Skip to content

Commit

Permalink
Version 1.0.4
Browse files Browse the repository at this point in the history
 - Small refactoring
 - Update nikic/FastRoute to version 1.3.0
 - Small fixes
  • Loading branch information
vanchelo committed Sep 18, 2018
1 parent 0ea8bee commit 1a297b2
Show file tree
Hide file tree
Showing 44 changed files with 858 additions and 878 deletions.
12 changes: 6 additions & 6 deletions _build/build.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
define('PKG_NAME', 'FastRouter');
define('PKG_NAME_LOWER', strtolower(PKG_NAME));

define('PKG_VERSION', '1.0.2');
define('PKG_VERSION', '1.0.4');
define('PKG_RELEASE', 'pl');
define('PKG_AUTO_INSTALL', true);
define('PKG_NAMESPACE_PATH', '{core_path}components/' . PKG_NAME_LOWER . '/');

/* define paths */
if (isset($_SERVER['MODX_BASE_PATH'])) {
define('MODX_BASE_PATH', $_SERVER['MODX_BASE_PATH']);
} elseif (file_exists(realpath(dirname(dirname(__FILE__))) . DS . 'core')) {
define('MODX_BASE_PATH', realpath(dirname(dirname(__FILE__))) . DS);
} elseif (file_exists(realpath(dirname(__DIR__)) . DS . 'core')) {
define('MODX_BASE_PATH', realpath(dirname(__DIR__)) . DS);
} else {
define('MODX_BASE_PATH', dirname(dirname(dirname(dirname(__FILE__)))) . '/');
define('MODX_BASE_PATH', dirname(dirname(dirname(__DIR__))) . '/');
}

define('MODX_CORE_PATH', MODX_BASE_PATH . 'core/');
Expand All @@ -42,6 +42,6 @@
define('BUILD_SNIPPET_STATIC', false);
define('BUILD_PLUGIN_STATIC', false);

$BUILD_RESOLVERS = array(
$BUILD_RESOLVERS = [
'chunks',
);
];
132 changes: 87 additions & 45 deletions _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;

set_time_limit(0);

header('Content-Type:text/html;charset=utf-8');
header('Content-Type: text/html;charset=utf-8');

require_once 'build.config.php';

/* define sources */
$root = dirname(dirname(__FILE__)) . '/';
$sources = array(
/**
* Define sources
*/
$root = dirname(__DIR__) . '/';
$sources = [
'root' => $root,
'build' => $root . '_build/',
'data' => $root . '_build/data/',
Expand All @@ -23,7 +26,7 @@
'lexicon' => $root . 'core/components/' . PKG_NAME_LOWER . '/lexicon/',
'docs' => $root . 'core/components/' . PKG_NAME_LOWER . '/docs/',
'source_core' => $root . 'core/components/' . PKG_NAME_LOWER,
);
];
unset($root);

require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
Expand All @@ -35,6 +38,7 @@
$modx->setLogTarget('ECHO');
$modx->getService('error', 'error.modError');
$modx->loadClass('transport.modPackageBuilder', '', false, true);

if (!XPDO_CLI_MODE) {
echo '<pre>';
}
Expand All @@ -45,66 +49,86 @@

$modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package and Namespace.');

/* load system settings */
/**
* Load system settings
*/
if (defined('BUILD_SETTING_UPDATE')) {
$settings = include $sources['data'] . 'transport.settings.php';

if (!is_array($settings)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in settings.');
} else {
$attributes = array(
$attributes = [
xPDOTransport::UNIQUE_KEY => 'key',
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => BUILD_SETTING_UPDATE,
);
];

foreach ($settings as $setting) {
$vehicle = $builder->createVehicle($setting, $attributes);
$builder->putVehicle($vehicle);
}

$modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($settings) . ' System Settings.');
}

unset($settings, $setting, $attributes);
}

/* load plugins events */
/**
* Load plugins events
*/
if (defined('BUILD_EVENT_UPDATE')) {
$events = include $sources['data'] . 'transport.events.php';

if (!is_array($events)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in events.');
} else {
$attributes = array(
$attributes = [
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => BUILD_EVENT_UPDATE,
);
];

foreach ($events as $event) {
$vehicle = $builder->createVehicle($event, $attributes);
$builder->putVehicle($vehicle);
}

$modx->log(xPDO::LOG_LEVEL_INFO, 'Packaged in ' . count($events) . ' Plugins events.');
}

unset ($events, $event, $attributes);
}

/* create category */
/**
* Create category
*/
$modx->log(xPDO::LOG_LEVEL_INFO, 'Created category.');
/* @var modCategory $category */
$category = $modx->newObject('modCategory');
$category->set('category', PKG_NAME);
/* create category vehicle */
$attr = array(

/**
* Create category vehicle
*/
$attr = [
xPDOTransport::UNIQUE_KEY => 'category',
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::RELATED_OBJECTS => true,
);
];

/* add snippets */
/**
* Add snippets
*/
if (defined('BUILD_SNIPPET_UPDATE')) {
$attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Snippets'] = array(
$attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Snippets'] = [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => BUILD_SNIPPET_UPDATE,
xPDOTransport::UNIQUE_KEY => 'name',
);
];
$snippets = include $sources['data'] . 'transport.snippets.php';

if (!is_array($snippets)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in snippets.');
} else {
Expand All @@ -113,14 +137,17 @@
}
}

/* add chunks */
/**
* Add chunks
*/
if (defined('BUILD_CHUNK_UPDATE')) {
$attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Chunks'] = array(
$attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Chunks'] = [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => BUILD_CHUNK_UPDATE,
xPDOTransport::UNIQUE_KEY => 'name',
);
];
$chunks = include $sources['data'] . 'transport.chunks.php';

if (!is_array($chunks)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in chunks.');
} else {
Expand All @@ -129,19 +156,22 @@
}
}

/* add plugins */
/**
* Add plugins
*/
if (defined('BUILD_PLUGIN_UPDATE')) {
$attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Plugins'] = array(
$attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Plugins'] = [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => BUILD_PLUGIN_UPDATE,
xPDOTransport::UNIQUE_KEY => 'name',
);
$attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['PluginEvents'] = array(
];
$attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['PluginEvents'] = [
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => BUILD_PLUGIN_UPDATE,
xPDOTransport::UNIQUE_KEY => array('pluginid', 'event'),
);
xPDOTransport::UNIQUE_KEY => ['pluginid', 'event'],
];
$plugins = include $sources['data'] . 'transport.plugins.php';

if (!is_array($plugins)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in plugins.');
} else {
Expand All @@ -152,56 +182,63 @@

$vehicle = $builder->createVehicle($category, $attr);

/* now pack in resolvers */
$vehicle->resolve('file', array(
/**
* Now pack in resolvers
*/
$vehicle->resolve('file', [
'source' => $sources['source_core'],
'target' => "return MODX_CORE_PATH . 'components/';",
));
]);

foreach ($BUILD_RESOLVERS as $resolver) {
if ($vehicle->resolve('php', array('source' => $sources['resolvers'] . 'resolve.' . $resolver . '.php'))) {
if ($vehicle->resolve('php', ['source' => $sources['resolvers'] . 'resolve.' . $resolver . '.php'])) {
$modx->log(modX::LOG_LEVEL_INFO, 'Added resolver "' . $resolver . '" to category.');
} else {
$modx->log(modX::LOG_LEVEL_INFO, 'Could not add resolver "' . $resolver . '" to category.');
}
}

flush();

$builder->putVehicle($vehicle);

/* now pack in the license file, readme and setup options */
$builder->setPackageAttributes(array(
/**
* Now pack in the license file, readme and setup options
*/
$builder->setPackageAttributes([
'changelog' => file_get_contents($sources['docs'] . 'changelog.txt'),
'license' => file_get_contents($sources['docs'] . 'license.txt'),
'readme' => file_get_contents($sources['docs'] . 'readme.txt'),
'chunks' => $BUILD_CHUNKS,
'setup-options' => array(
'setup-options' => [
'source' => $sources['build'] . 'setup.options.php',
),
));
],
]);
$modx->log(modX::LOG_LEVEL_INFO, 'Added package attributes and setup options.');

/* zip up package */
/**
* Zip up package
*/
$modx->log(modX::LOG_LEVEL_INFO, 'Packing up transport package zip...');
$builder->pack();

$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = ($tend - $tstart);
$totalTime = sprintf("%2.4f s", $totalTime);
$totalTime = sprintf('%2.4f s', $totalTime);

$signature = $builder->getSignature();
if (defined('PKG_AUTO_INSTALL') && PKG_AUTO_INSTALL) {
$sig = explode('-', $signature);
$versionSignature = explode('.', $sig[1]);

/* @var modTransportPackage $package */
if (!$package = $modx->getObject('transport.modTransportPackage', array('signature' => $signature))) {
/** @var modTransportPackage $package */
if (!$package = $modx->getObject('transport.modTransportPackage', ['signature' => $signature])) {
$package = $modx->newObject('transport.modTransportPackage');
$package->set('signature', $signature);
$package->fromArray(array(
$package->fromArray([
'created' => date('Y-m-d h:i:s'),
'updated' => null,
'state' => 1,
Expand All @@ -212,28 +249,33 @@
'version_major' => $versionSignature[0],
'version_minor' => !empty($versionSignature[1]) ? $versionSignature[1] : 0,
'version_patch' => !empty($versionSignature[2]) ? $versionSignature[2] : 0,
));
]);

if (!empty($sig[2])) {
$r = preg_split('/([0-9]+)/', $sig[2], -1, PREG_SPLIT_DELIM_CAPTURE);
$r = preg_split('/(\d+)/', $sig[2], -1, PREG_SPLIT_DELIM_CAPTURE);

if (is_array($r) && !empty($r)) {
$package->set('release', $r[0]);
$package->set('release_index', (isset($r[1]) ? $r[1] : '0'));
} else {
$package->set('release', $sig[2]);
}
}

$package->save();
}

if ($package->install()) {
$modx->runProcessor('system/clearcache');
}
}

if (!empty($_GET['download'])) {
echo '<script>document.location.href = "/core/packages/' . $signature . '.transport.zip' . '";</script>';
}

$modx->log(modX::LOG_LEVEL_INFO, "\n<br />Execution time: {$totalTime}\n");
$modx->log(modX::LOG_LEVEL_INFO, "Execution time: {$totalTime}");

if (!XPDO_CLI_MODE) {
echo '</pre>';
}
17 changes: 9 additions & 8 deletions _build/data/transport.chunks.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
<?php

$chunks = array();
$chunks = [];

$tmp = array(
'fastrouter' => array(
$tmp = [
'fastrouter' => [
'file' => 'fastrouter',
'source' => false,
'description' => '',
),
);
],
];

// Save chunks for setup options
$BUILD_CHUNKS = array();
$BUILD_CHUNKS = [];

foreach ($tmp as $k => $v) {
/* @avr modChunk $chunk */
$chunk = $modx->newObject('modChunk');
$chunk->fromArray(array(
$chunk->fromArray([
'id' => 0,
'name' => $k,
'description' => $v['description'],
'snippet' => file_get_contents($sources['source_core'] . '/elements/chunks/chunk.' . $v['file'] . '.tpl'),
'static' => BUILD_CHUNK_STATIC,
'source' => $v['source'],
'static_file' => 'core/components/' . PKG_NAME_LOWER . '/elements/chunks/chunk.' . $v['file'] . '.tpl',
), '', true, true);
], '', true, true);

$chunks[] = $chunk;

$BUILD_CHUNKS[$k] = file_get_contents($sources['source_core'] . '/elements/chunks/chunk.' . $v['file'] . '.tpl');
}

unset($tmp);

return $chunks;
Loading

0 comments on commit 1a297b2

Please sign in to comment.