Skip to content

Commit

Permalink
feat: resolvers and validators
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Klimchuk committed Jul 19, 2021
1 parent 83e3dcc commit 0f68858
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
38 changes: 38 additions & 0 deletions _build/resolvers/payments.php
@@ -0,0 +1,38 @@
<?php
/**
* Copyright (c) Ivan Klimchuk - All Rights Reserved
* Unauthorized copying, changing, distributing this file, via any medium, is strictly prohibited.
* Written by Ivan Klimchuk <ivan@klimchuk.com>, 2021
*/

/** @var xPDOTransport $transport */
/** @var array $options */

if (!$transport->xpdo && !$transport->xpdo instanceof modX) {
return true;
}

switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:

$transport->xpdo->newObject(
msPayment::class,
[
'name' => 'Klarna',
'description' => null,
'price' => 0,
'rank' => 0,
'active' => 1,
'class' => KlarnaHandler::class,
'properties' => null // todo: setup minimal default properties
]
)->save();

break;

case xPDOTransport::ACTION_UNINSTALL:

$transport->xpdo->removeObject(msPayment::class, ['class' => KlarnaHandler::class]);

break;
}
36 changes: 36 additions & 0 deletions _build/resolvers/services.php
@@ -0,0 +1,36 @@
<?php
/**
* Copyright (c) Ivan Klimchuk - All Rights Reserved
* Unauthorized copying, changing, distributing this file, via any medium, is strictly prohibited.
* Written by Ivan Klimchuk <ivan@klimchuk.com>, 2021
*/

declare(strict_types = 1);

/** @var xPDOTransport $transport */
/** @var array $options */

if (!$transport->xpdo && !$transport->xpdo instanceof modX) {
return true;
}

switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:

/** @var miniShop2 $shop */
if ($shop = $transport->xpdo->getService('miniShop2')) {
$shop->addService('payment', KlarnaHandler::class, '{core_path}components/mspklarna/KlarnaHandler.class.php');
}

break;

case xPDOTransport::ACTION_UNINSTALL:

/** @var miniShop2 $shop */
if ($shop = $transport->xpdo->getService('miniShop2')) {
$shop->removeService('payment', KlarnaHandler::class);
}

break;
}
43 changes: 43 additions & 0 deletions _build/validators/php-extensions.php
@@ -0,0 +1,43 @@
<?php
/**
* Copyright (c) Ivan Klimchuk - All Rights Reserved
* Unauthorized copying, changing, distributing this file, via any medium, is strictly prohibited.
* Written by Ivan Klimchuk <ivan@klimchuk.com>, 2019
*/

declare(strict_types = 1);

/** @var xPDOTransport $transport */
/** @var array $options */

if (!$transport->xpdo) {
return false;
}

$extensions = [
'pdo' => 'PHP Data Objects',
'curl' => 'Client URL Library',
'simplexml' => 'SimpleXML',
'json' => 'JavaScript Object Notation',
'xmlwriter' => 'XMLWriter',
'bcmath' => 'BCMath Arbitrary Precision Mathematics',
'openssl' => 'OpenSSL'
];

foreach ($extensions as $ext => $title) {
if (!extension_loaded($ext)) {
$msg = sprintf('
PHP extension `%s` (https://php.net/manual/en/book.%s.php) does not loaded.
This PHP extension is required for a proper work of this package.
Please, ask your sysadmin or hosting company to install and configure it before continue.',
$title, $ext === 'bcmath' ? 'bc' : $ext
);

$transport->xpdo->log(modX::LOG_LEVEL_ERROR, $msg);

return false;
}
}


return true;

0 comments on commit 0f68858

Please sign in to comment.