Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

множество мелких улучшений синтаксиса и читаемости #777

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _build/build.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
const BUILD_SNIPPET_STATIC = false;
const BUILD_PLUGIN_STATIC = false;

$BUILD_RESOLVERS = array(
$BUILD_RESOLVERS = [
'extension',
'tables',
'policy',
Expand All @@ -55,4 +55,4 @@
'chunks',
'statuses',
'setup',
);
];
4 changes: 2 additions & 2 deletions _build/build.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

// Define sources
$root = dirname(__FILE__, 2) . '/';
$sources = array(
$sources = [
'root' => $root,
'build' => $root . '_build/',
'source_core' => $root . 'core/components/' . PKG_NAME_LOWER,
'model' => $root . 'core/components/' . PKG_NAME_LOWER . '/model/',
'schema' => $root . 'core/components/' . PKG_NAME_LOWER . '/model/schema/',
'xml' => $root . 'core/components/' . PKG_NAME_LOWER . '/model/schema/' . PKG_NAME_LOWER . '.mysql.schema.xml',
);
];
unset($root);

require MODX_CORE_PATH . 'model/modx/modx.class.php';
Expand Down
91 changes: 45 additions & 46 deletions _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

// Define sources
$root = dirname(__FILE__, 2) . '/';
$sources = array(
$sources = [
'root' => $root,
'build' => $root . '_build/',
'data' => $root . '_build/data/',
Expand All @@ -29,7 +29,7 @@
'pages' => $root . 'core/components/' . PKG_NAME_LOWER . '/elements/pages/',
'source_assets' => $root . 'assets/components/' . PKG_NAME_LOWER,
'source_core' => $root . 'core/components/' . PKG_NAME_LOWER,
);
];
unset($root);

require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
Expand All @@ -53,11 +53,11 @@
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);
Expand All @@ -71,10 +71,10 @@
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);
Expand All @@ -84,11 +84,11 @@
unset($events, $event, $attributes);

// Package in default access policy
$attributes = array(
$attributes = [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UNIQUE_KEY => array('name'),
xPDOTransport::UNIQUE_KEY => ['name'],
xPDOTransport::UPDATE_OBJECT => BUILD_POLICY_UPDATE,
);
];
$policies = include $sources['data'] . 'transport.policies.php';
if (!is_array($policies)) {
$modx->log(modX::LOG_LEVEL_FATAL, 'Adding policies failed.');
Expand All @@ -103,19 +103,19 @@

// Package in default access policy templates
$templates = include dirname(__FILE__) . '/data/transport.policytemplates.php';
$attributes = array(
$attributes = [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UNIQUE_KEY => array('name'),
xPDOTransport::UNIQUE_KEY => ['name'],
xPDOTransport::UPDATE_OBJECT => BUILD_POLICY_TEMPLATE_UPDATE,
xPDOTransport::RELATED_OBJECTS => true,
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array(
'Permissions' => array(
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => [
'Permissions' => [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => BUILD_PERMISSION_UPDATE,
xPDOTransport::UNIQUE_KEY => array('template', 'name'),
),
),
);
xPDOTransport::UNIQUE_KEY => ['template', 'name'],
],
],
];
if (is_array($templates)) {
foreach ($templates as $template) {
$vehicle = $builder->createVehicle($template, $attributes);
Expand All @@ -130,11 +130,11 @@

// Load menus
$menus = include $sources['data'] . 'transport.menu.php';
$attributes = array(
$attributes = [
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => BUILD_MENU_UPDATE,
xPDOTransport::UNIQUE_KEY => 'text',
);
];
if (is_array($menus)) {
foreach ($menus as $menu) {
$vehicle = $builder->createVehicle($menu, $attributes);
Expand All @@ -147,7 +147,6 @@
}
unset($vehicle, $menus, $menu, $attributes);


// Create category
$modx->log(xPDO::LOG_LEVEL_INFO, 'Created category.');
/** @var modCategory $category */
Expand All @@ -165,7 +164,7 @@
}

// Add chunks
$package_chunks = array();
$package_chunks = [];
$chunks = include $sources['data'] . 'transport.chunks.php';
if (!is_array($chunks)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in chunks.');
Expand All @@ -187,48 +186,48 @@
}

// Create category vehicle
$attr = array(
$attr = [
xPDOTransport::UNIQUE_KEY => 'category',
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::RELATED_OBJECTS => true,
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array(
'Snippets' => array(
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => [
'Snippets' => [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => BUILD_SNIPPET_UPDATE,
xPDOTransport::UNIQUE_KEY => 'name',
),
'Chunks' => array(
],
'Chunks' => [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => BUILD_CHUNK_UPDATE,
xPDOTransport::UNIQUE_KEY => 'name',
),
'Plugins' => array(
],
'Plugins' => [
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => BUILD_PLUGIN_UPDATE,
xPDOTransport::UNIQUE_KEY => 'name',
),
'PluginEvents' => array(
],
'PluginEvents' => [
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => BUILD_EVENT_UPDATE,
xPDOTransport::UNIQUE_KEY => array('pluginid', 'event'),
),
),
);
xPDOTransport::UNIQUE_KEY => ['pluginid', 'event'],
],
],
];
$vehicle = $builder->createVehicle($category, $attr);

// Now pack in resolvers
$vehicle->resolve('file', array(
$vehicle->resolve('file', [
'source' => $sources['source_assets'],
'target' => "return MODX_ASSETS_PATH . 'components/';",
));
$vehicle->resolve('file', array(
]);
$vehicle->resolve('file', [
'source' => $sources['source_core'],
'target' => "return MODX_CORE_PATH . 'components/';",
));
]);
/** @var array $BUILD_RESOLVERS */
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.');
Expand All @@ -239,19 +238,19 @@
$builder->putVehicle($vehicle);

// Now pack in the license file, readme and setup options
$builder->setPackageAttributes(array(
$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' => $package_chunks,
'setup-options' => array(
'setup-options' => [
'source' => $sources['build'] . 'setup.options.php',
),
],
'requires' => [
'php' => '>=7.0.0',
'modx' => '<3.0.0',
],
));
]);
$modx->log(modX::LOG_LEVEL_INFO, 'Added package attributes and setup options.');

// Zip up package
Expand All @@ -272,10 +271,10 @@
$versionSignature = explode('.', $sig[1]);

/** @var modTransportPackage $package */
if (!$package = $modx->getObject('transport.modTransportPackage', array('signature' => $signature))) {
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 @@ -286,7 +285,7 @@
'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);
if (is_array($r) && !empty($r)) {
Expand Down
10 changes: 5 additions & 5 deletions _build/data/transport.chunks.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/** @var modX $modx */
$chunks = array();
$chunks = [];

$tmp = array(
$tmp = [
'msProduct.content' => 'ms_product_content',
'msProduct.content.fenom' => 'ms_product_content_fenom',
'tpl.msProducts.row' => 'ms_products_row',
Expand All @@ -25,21 +25,21 @@
'tpl.msEmail.paid.manager' => 'ms_email_paid_manager',
'tpl.msEmail.sent.user' => 'ms_email_sent_user',
'tpl.msEmail.cancelled.user' => 'ms_email_cancelled_user',
);
];

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

Expand Down
10 changes: 5 additions & 5 deletions _build/data/transport.events.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/** @var modX $modx */
$events = array();
$events = [];

$tmp = array(
$tmp = [
'msOnBeforeAddToCart',
'msOnAddToCart',
'msOnBeforeChangeInCart',
Expand Down Expand Up @@ -54,16 +54,16 @@

'msOnManagerCustomCssJs',

);
];

foreach ($tmp as $k => $v) {
/** @var modEvent $event */
$event = $modx->newObject('modEvent');
$event->fromArray(array(
$event->fromArray([
'name' => $v,
'service' => 6,
'groupname' => PKG_NAME,
), '', true, true);
], '', true, true);
$events[] = $event;
}

Expand Down
Loading