Skip to content

Commit

Permalink
Merge f544c90 into 0e7275a
Browse files Browse the repository at this point in the history
  • Loading branch information
DeyV committed Feb 3, 2020
2 parents 0e7275a + f544c90 commit 368cd4e
Show file tree
Hide file tree
Showing 31 changed files with 540 additions and 525 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ env:
matrix:
fast_finish: true
include:
- php: 5.3
dist: precise
env: COMPOSER_MEMORY_LIMIT=3G
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 5.6
- php: 7.0
- php: 7.1
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"forum": "https://discourse.laminas.dev/"
},
"require": {
"php": "^5.6 || ^7.0"
"php": "^5.3 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.1",
"squizlabs/php_codesniffer": "^3.5"
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5 || ^8.1",
"squizlabs/php_codesniffer": "^2.9 || ^3.5"
},
"autoload": {
"files": [
Expand Down
4 changes: 2 additions & 2 deletions config/replacements.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return [
return array(
// NEVER REWRITE
'zendframework/zendframework' => 'zendframework/zendframework',
'zend-developer-tools/toolbar/doctrine' => 'zend-developer-tools/toolbar/doctrine',
Expand Down Expand Up @@ -512,4 +512,4 @@
'ZfApigilityDoctrineQueryCreateFilterManager' => 'LaminasApiToolsDoctrineQueryCreateFilterManager',
'zf-apigility-doctrine' => 'api-tools-doctrine',
'zf-development-mode' => 'laminas-development-mode',
];
);
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
<rule ref="PSR12"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<arg value="p"/>
<arg name="colors"/>
Expand Down
14 changes: 7 additions & 7 deletions src/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Autoloader
*/
public static function load()
{
$loaded = new ArrayObject([]);
$loaded = new ArrayObject();

spl_autoload_register(self::createPrependAutoloader(
RewriteRules::namespaceReverse(),
Expand Down Expand Up @@ -74,7 +74,7 @@ private static function createPrependAutoloader(array $namespaces, ClassLoader $
* @param string $class Class name to autoload
* @return void
*/
return static function ($class) use ($namespaces, $classLoader, $loaded) {
return function ($class) use ($namespaces, $classLoader, $loaded) {
if (isset($loaded[$class])) {
return;
}
Expand All @@ -95,11 +95,11 @@ private static function createPrependAutoloader(array $namespaces, ClassLoader $

if ($classLoader->loadClass($class)) {
$legacy = $namespaces[$check]
. strtr(substr($class, strlen($check)), [
. strtr(substr($class, strlen($check)), array(
'ApiTools' => 'Apigility',
'Mezzio' => 'Expressive',
'Laminas' => 'Zend',
]);
));
class_alias($class, $legacy);
}
};
Expand All @@ -114,7 +114,7 @@ private static function createAppendAutoloader(array $namespaces, ArrayObject $l
* @param string $class Class name to autoload
* @return void
*/
return static function ($class) use ($namespaces, $loaded) {
return function ($class) use ($namespaces, $loaded) {
$segments = explode('\\', $class);

if ($segments[0] === 'ZendService' && isset($segments[1])) {
Expand All @@ -137,15 +137,15 @@ private static function createAppendAutoloader(array $namespaces, ArrayObject $l
}

$alias = $namespaces[$check]
. strtr(substr($class, strlen($check)), [
. strtr(substr($class, strlen($check)), array(
'Apigility' => 'ApiTools',
'Expressive' => 'Mezzio',
'Zend' => 'Laminas',
'AbstractZendServer' => 'AbstractZendServer',
'ZendServerDisk' => 'ZendServerDisk',
'ZendServerShm' => 'ZendServerShm',
'ZendMonitor' => 'ZendMonitor',
]);
));

$loaded[$alias] = true;
if (class_exists($alias) || interface_exists($alias) || trait_exists($alias)) {
Expand Down
67 changes: 39 additions & 28 deletions src/ConfigPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

class ConfigPostProcessor
{
/** @var array String keys => string values */
private $exactReplacements = [
/**
* @var array String keys => string values
* public because php 5.3
*/
public $exactReplacements = array(
'zend-expressive' => 'mezzio',
'zf-apigility' => 'api-tools',
];
);

/** @var Replacements */
private $replacements;
Expand Down Expand Up @@ -44,53 +47,55 @@ public function __construct()
* @param string[] $keys
* @return mixed The transformed value
*/
$this->rulesets = [

$th =& $this; // fix compatibility problems with php 5.3
$this->rulesets = array(
// Exact values
function ($value) {
return is_string($value) && isset($this->exactReplacements[$value])
? [$this, 'replaceExactValue']
function ($value) use ($th) {
return is_string($value) && isset($th->exactReplacements[$value])
? array($th, 'replaceExactValue')
: null;
},

// Router (MVC applications)
// We do not want to rewrite these.
function ($value, array $keys) {
function ($value, array $keys) use ($th) {
$key = array_pop($keys);
// Only worried about a top-level "router" key.
return $key === 'router' && count($keys) === 0 && is_array($value)
? [$this, 'noopReplacement']
? array($th, 'noopReplacement')
: null;
},

// Aliases and invokables
function ($value, array $keys) {
function ($value, array $keys) use ($th) {
static $keysOfInterest;

$keysOfInterest = $keysOfInterest ?: ['aliases', 'invokables'];
$key = array_pop($keys);
$keysOfInterest = $keysOfInterest ?: array('aliases', 'invokables');
$key = array_pop($keys);

return in_array($key, $keysOfInterest, true) && is_array($value)
? [$this, 'replaceDependencyAliases']
? array($th, 'replaceDependencyAliases')
: null;
},

// Array values
function ($value, array $keys) {
function ($value, array $keys) use ($th) {
return 0 !== count($keys) && is_array($value)
? [$this, '__invoke']
? array($th, '__invoke')
: null;
},
];
);
}

/**
* @param string[] $keys Hierarchy of keys, for determining location in
* nested configuration.
* @return array
*/
public function __invoke(array $config, array $keys = [])
public function __invoke(array $config, array $keys = array())
{
$rewritten = [];
$rewritten = array();

foreach ($config as $key => $value) {
// Determine new key from replacements
Expand All @@ -105,7 +110,7 @@ public function __invoke(array $config, array $keys = [])
$newValue = $this->replace($value, $keys, $newKey);

// Key does not already exist and/or is not an array value
if (! array_key_exists($newKey, $rewritten) || ! is_array($rewritten[$newKey])) {
if (!array_key_exists($newKey, $rewritten) || !is_array($rewritten[$newKey])) {
// Do not overwrite existing values with null values
$rewritten[$newKey] = array_key_exists($newKey, $rewritten) && null === $newValue
? $rewritten[$newKey]
Expand All @@ -119,7 +124,7 @@ public function __invoke(array $config, array $keys = [])
}

// Key already exists as an array value, but $value is not an array
if (! is_array($newValue)) {
if (!is_array($newValue)) {
$rewritten[$newKey][] = $newValue;
continue;
}
Expand All @@ -136,8 +141,8 @@ public function __invoke(array $config, array $keys = [])
*
* The $key is provided to allow fine-grained selection of rewrite rules.
*
* @param mixed $value
* @param string[] $keys Key hierarchy
* @param mixed $value
* @param string[] $keys Key hierarchy
* @param null|int|string $key
* @return mixed
*/
Expand All @@ -149,7 +154,7 @@ private function replace($value, array $keys, $key = null)

// Identify rewrite strategy and perform replacements
$rewriteRule = $this->replacementRuleMatch($value, $keys);
return $rewriteRule($value, $keys);
return call_user_func($rewriteRule, $value, $keys);
}

/**
Expand All @@ -168,7 +173,7 @@ private function replace($value, array $keys, $key = null)
public static function merge(array $a, array $b)
{
foreach ($b as $key => $value) {
if (! isset($a[$key]) && ! array_key_exists($key, $a)) {
if (!isset($a[$key]) && !array_key_exists($key, $a)) {
$a[$key] = $value;
continue;
}
Expand All @@ -182,7 +187,7 @@ public static function merge(array $a, array $b)
$a[] = $value;
continue;
}

if (is_array($value) && is_array($a[$key])) {
$a[$key] = static::merge($a[$key], $value);
continue;
Expand All @@ -195,7 +200,7 @@ public static function merge(array $a, array $b)
}

/**
* @param mixed $value
* @param mixed $value
* @param null|int|string $key
* @return callable Callable to invoke with value
*/
Expand All @@ -207,7 +212,7 @@ private function replacementRuleMatch($value, $key = null)
return $result;
}
}
return [$this, 'fallbackReplacement'];
return array($this, 'fallbackReplacement');
}

/**
Expand All @@ -228,8 +233,10 @@ private function fallbackReplacement($value)
*
* @param mixed $value
* @return mixed
*
* public because php 5.3
*/
private function replaceExactValue($value)
public function replaceExactValue($value)
{
return $this->exactReplacements[$value];
}
Expand All @@ -243,6 +250,8 @@ private function replaceExactValue($value)
* an alias map.
*
* @return array
*
* public because php 5.3
*/
private function replaceDependencyAliases(array $aliases)
{
Expand All @@ -255,6 +264,8 @@ private function replaceDependencyAliases(array $aliases)
/**
* @param mixed $value
* @return mixed Returns $value verbatim.
*
* public because php 5.3
*/
private function noopReplacement($value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function init($moduleManager)
{
$moduleManager
->getEventManager()
->attach('mergeConfig', [$this, 'onMergeConfig']);
->attach('mergeConfig', array($this, 'onMergeConfig'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Replacements.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Replacements
/** @var string[] */
private $replacements;

public function __construct(array $additionalReplacements = [])
public function __construct(array $additionalReplacements = array())
{
$this->replacements = array_merge(
require __DIR__ . '/../config/replacements.php',
Expand Down
8 changes: 4 additions & 4 deletions src/RewriteRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RewriteRules
*/
public static function namespaceRewrite()
{
return [
return array(
// Expressive
'Zend\\ProblemDetails\\' => 'Mezzio\\ProblemDetails\\',
'Zend\\Expressive\\' => 'Mezzio\\',
Expand All @@ -36,15 +36,15 @@ public static function namespaceRewrite()
'ZendService\\ReCaptcha\\' => 'Laminas\\ReCaptcha\\',
'ZendService\\Twitter\\' => 'Laminas\\Twitter\\',
'ZendDeveloperTools\\' => 'Laminas\\DeveloperTools\\',
];
);
}

/**
* @return array
*/
public static function namespaceReverse()
{
return [
return array(
// ZendXml, ZendOAuth, ZendDiagnostics, ZendDeveloperTools
'Laminas\\Xml\\' => 'ZendXml\\',
'Laminas\\OAuth\\' => 'ZendOAuth\\',
Expand Down Expand Up @@ -74,6 +74,6 @@ public static function namespaceReverse()
'Laminas\\ApiTools\\Provider\\' => 'ZF\\Apigility\\Provider\\',
'Laminas\\ApiTools\\Welcome\\' => 'ZF\\Apiglity\\Welcome\\',
'Laminas\\ApiTools\\' => 'ZF\\',
];
);
}
}

0 comments on commit 368cd4e

Please sign in to comment.