-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5c9b412
Showing
21 changed files
with
868 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: PHPCS | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run: | ||
name: phpcs | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php-version: ['7.4', '8.0', '8.1', '8.2'] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
extensions: pdo, pdo_mysql, zip, mysqli, gd | ||
|
||
- name: Install dependencies | ||
run: cd core/components/commerce_dynamictaxmode && composer install --no-progress --prefer-dist --optimize-autoloader | ||
|
||
- name: Install phpcs | ||
run: composer install --no-progress --prefer-dist --optimize-autoloader | ||
|
||
- name: Run phpcs | ||
run: composer run phpcs -- --runtime-set testVersion ${{ matrix.php-version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.idea | ||
config.core.php | ||
.DS_store | ||
_packages/ | ||
core/components/commerce_dynamictaxmode/vendor/ | ||
composer.lock | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<?php | ||
|
||
/* Get the core config */ | ||
$componentPath = dirname(__DIR__); | ||
if (!file_exists($componentPath . '/config.core.php')) { | ||
die('ERROR: missing ' . $componentPath . '/config.core.php file defining the MODX core path.'); | ||
} | ||
|
||
echo "<pre>"; | ||
/* Boot up MODX */ | ||
echo "Loading modX...\n"; | ||
require_once $componentPath . '/config.core.php'; | ||
require_once MODX_CORE_PATH . 'model/modx/modx.class.php'; | ||
$modx = new modX(); | ||
echo "Initializing manager...\n"; | ||
$modx->initialize('mgr'); | ||
$modx->getService('error', 'error.modError', '', ''); | ||
$modx->setLogTarget('HTML'); | ||
|
||
|
||
/* Namespace */ | ||
if ( | ||
!createObject('modNamespace', [ | ||
'name' => 'commerce_dynamictaxmode', | ||
'path' => $componentPath . '/core/components/commerce_dynamictaxmode/', | ||
'assets_path' => $componentPath . '/assets/components/commerce_dynamictaxmode/', | ||
], 'name', false) | ||
) { | ||
echo "Error creating namespace commerce_dynamictaxmode.\n"; | ||
} | ||
|
||
/* Path settings */ | ||
if ( | ||
!createObject('modSystemSetting', [ | ||
'key' => 'commerce_dynamictaxmode.core_path', | ||
'value' => $componentPath . '/core/components/commerce_dynamictaxmode/', | ||
'xtype' => 'textfield', | ||
'namespace' => 'commerce_dynamictaxmode', | ||
'area' => 'Paths', | ||
'editedon' => time(), | ||
], 'key', false) | ||
) { | ||
echo "Error creating commerce_dynamictaxmode.core_path setting.\n"; | ||
} | ||
|
||
if ( | ||
!createObject('modSystemSetting', [ | ||
'key' => 'commerce_dynamictaxmode.assets_path', | ||
'value' => $componentPath . '/assets/components/commerce_dynamictaxmode/', | ||
'xtype' => 'textfield', | ||
'namespace' => 'commerce_dynamictaxmode', | ||
'area' => 'Paths', | ||
'editedon' => time(), | ||
], 'key', false) | ||
) { | ||
echo "Error creating commerce_dynamictaxmode.assets_path setting.\n"; | ||
} | ||
|
||
/* Fetch assets url */ | ||
$requestUri = $_SERVER['REQUEST_URI'] ?: __DIR__ . '/_bootstrap/index.php'; | ||
$bootstrapPos = strpos($requestUri, '_bootstrap/'); | ||
$requestUri = rtrim(substr($requestUri, 0, $bootstrapPos), '/') . '/'; | ||
$assetsUrl = "{$requestUri}assets/components/commerce_dynamictaxmode/"; | ||
|
||
if ( | ||
!createObject('modSystemSetting', [ | ||
'key' => 'commerce_dynamictaxmode.assets_url', | ||
'value' => $assetsUrl, | ||
'xtype' => 'textfield', | ||
'namespace' => 'commerce_dynamictaxmode', | ||
'area' => 'Paths', | ||
'editedon' => time(), | ||
], 'key', false) | ||
) { | ||
echo "Error creating commerce_dynamictaxmode.assets_url setting.\n"; | ||
} | ||
|
||
|
||
$settings = include dirname(__DIR__) . '/_build/data/settings.php'; | ||
foreach ($settings as $key => $opts) { | ||
$val = $opts['value']; | ||
|
||
if (isset($opts['xtype'])) { | ||
$xtype = $opts['xtype']; | ||
} elseif (is_int($val)) { | ||
$xtype = 'numberfield'; | ||
} elseif (is_bool($val)) { | ||
$xtype = 'modx-combo-boolean'; | ||
} else { | ||
$xtype = 'textfield'; | ||
} | ||
|
||
if ( | ||
!createObject('modSystemSetting', [ | ||
'key' => 'commerce_dynamictaxmode.' . $key, | ||
'value' => $opts['value'], | ||
'xtype' => $xtype, | ||
'namespace' => 'commerce_dynamictaxmode', | ||
'area' => $opts['area'], | ||
'editedon' => time(), | ||
], 'key', false) | ||
) { | ||
echo "Error creating commerce_dynamictaxmode." . $key . " setting.\n"; | ||
} | ||
} | ||
|
||
|
||
$path = $modx->getOption('commerce.core_path', null, MODX_CORE_PATH . 'components/commerce/') . 'model/commerce/'; | ||
$params = ['mode' => $modx->getOption('commerce.mode')]; | ||
/** @var Commerce|null $commerce */ | ||
$commerce = $modx->getService('commerce', 'Commerce', $path, $params); | ||
if (!($commerce instanceof Commerce)) { | ||
die("Couldn't load Commerce class"); | ||
} | ||
|
||
// Make sure our module can be loaded. In this case we're using a composer-provided PSR4 autoloader. | ||
include $componentPath . '/core/components/commerce_dynamictaxmode/vendor/autoload.php'; | ||
|
||
// Grab the path to our namespaced files | ||
$modulePath = $componentPath . '/core/components/commerce_dynamictaxmode/src/'; | ||
|
||
// Instruct Commerce to load modules from our directory, providing the base namespace and module path twice | ||
$logLevel = $modx->setLogLevel(xPDO::LOG_LEVEL_INFO); | ||
$commerce->loadModulesFromDirectory($modulePath, 'modmore\\Commerce_DynamicTaxMode\\', $modulePath); | ||
$modx->setLogLevel($logLevel); | ||
|
||
// Clear the cache | ||
$modx->cacheManager->refresh(); | ||
|
||
echo "Done."; | ||
|
||
|
||
/** | ||
* Creates an object. | ||
* | ||
* @param string $className | ||
* @param array $data | ||
* @param string $primaryField | ||
* @param bool $update | ||
* @return bool | ||
* @throws \xPDO\xPDOException | ||
*/ | ||
function createObject(string $className = '', array $data = [], string $primaryField = '', bool $update = true): bool | ||
{ | ||
global $modx; | ||
/* @var xPDOObject $object */ | ||
$object = null; | ||
|
||
/* Attempt to get the existing object */ | ||
if (!empty($primaryField)) { | ||
if (is_array($primaryField)) { | ||
$condition = []; | ||
foreach ($primaryField as $key) { | ||
$condition[$key] = $data[$key]; | ||
} | ||
} else { | ||
$condition = [$primaryField => $data[$primaryField]]; | ||
} | ||
$object = $modx->getObject($className, $condition); | ||
if ($object instanceof $className) { | ||
if ($update) { | ||
$object->fromArray($data); | ||
return $object->save(); | ||
} else { | ||
$condition = $modx->toJSON($condition); | ||
echo "Skipping {$className} {$condition}: already exists.\n"; | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
/* Create new object if it doesn't exist */ | ||
if (!$object) { | ||
$object = $modx->newObject($className); | ||
$object->fromArray($data, '', true); | ||
return $object->save(); | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
$mtime = microtime(); | ||
$mtime = explode(" ", $mtime); | ||
$mtime = $mtime[1] + $mtime[0]; | ||
$tstart = $mtime; | ||
set_time_limit(0); | ||
|
||
/* define package name */ | ||
define('PKG_NAME', 'Commerce_Dynamictaxmode'); | ||
define('PKG_NAME_LOWER', strtolower(PKG_NAME)); | ||
|
||
require_once dirname(__DIR__) . '/config.core.php'; | ||
include_once MODX_CORE_PATH . 'model/modx/modx.class.php'; | ||
$modx= new modX(); | ||
$modx->initialize('mgr'); | ||
$modx->loadClass('transport.modPackageBuilder','',false, true); | ||
$modx->setLogLevel(modX::LOG_LEVEL_INFO); | ||
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); | ||
|
||
$root = dirname(__DIR__) . '/'; | ||
$sources = array( | ||
'root' => $root, | ||
'core' => $root.'core/components/commerce_dynamictaxmode/', | ||
'model' => $root.'core/components/commerce_dynamictaxmode/model/', | ||
'assets' => $root.'assets/components/commerce_dynamictaxmode/', | ||
'schema' => $root.'core/components/commerce_dynamictaxmode/model/schema/', | ||
); | ||
$manager= $modx->getManager(); | ||
$generator= $manager->getGenerator(); | ||
$generator->classTemplate= <<<EOD | ||
<?php | ||
/** | ||
* Dynamictaxmode for Commerce. | ||
* | ||
* Copyright 2020 by Your Name <[email protected]> | ||
* | ||
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required. | ||
* | ||
* @package commerce_dynamictaxmode | ||
* @license See core/components/commerce_dynamictaxmode/docs/license.txt | ||
*/ | ||
class [+class+] extends [+extends+] | ||
{ | ||
} | ||
EOD; | ||
$generator->platformTemplate= <<<EOD | ||
<?php | ||
require_once strtr(realpath(dirname(dirname(__FILE__))), '\\\\', '/') . '/[+class-lowercase+].class.php'; | ||
/** | ||
* Dynamictaxmode for Commerce. | ||
* | ||
* Copyright 2020 by Your Name <[email protected]> | ||
* | ||
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required. | ||
* | ||
* @package commerce_dynamictaxmode | ||
* @license See core/components/commerce_dynamictaxmode/docs/license.txt | ||
*/ | ||
class [+class+]_[+platform+] extends [+class+] | ||
{ | ||
} | ||
EOD; | ||
$generator->mapHeader= <<<EOD | ||
<?php | ||
/** | ||
* Dynamictaxmode for Commerce. | ||
* | ||
* Copyright 2020 by Your Name <[email protected]> | ||
* | ||
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required. | ||
* | ||
* @package commerce_dynamictaxmode | ||
* @license See core/components/commerce_dynamictaxmode/docs/license.txt | ||
*/ | ||
EOD; | ||
|
||
$generator->parseSchema($sources['schema'] . 'commerce_dynamictaxmode.mysql.schema.xml', $sources['model']); | ||
|
||
|
||
$mtime= microtime(); | ||
$mtime= explode(" ", $mtime); | ||
$mtime= $mtime[1] + $mtime[0]; | ||
$tend= $mtime; | ||
$totalTime= ($tend - $tstart); | ||
$totalTime= sprintf("%2.4f s", $totalTime); | ||
|
||
echo "\nExecution time: {$totalTime}\n"; | ||
|
||
exit (); |
Oops, something went wrong.