Skip to content
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
6 changes: 3 additions & 3 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor')
->notName('classmap*.php')
;

return Symfony\CS\Config\Config::create()
->finder($finder)
return PhpCsFixer\Config::create()
->setFinder($finder)
;
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ php:
- '5.5'
- '5.6'
- '7.0'
- '7.1'
- nightly
- hhvm

before_script:
- composer self-update
- composer remove --dev friendsofphp/php-cs-fixer
- composer install --no-interaction

script: composer test
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"php": ">= 5.3.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "*",
"friendsofphp/php-cs-fixer": "^2.0",
"phpdocumentor/phpdocumentor": "*",
"phpunit/phpunit": "*",
"theseer/autoload": "^1.22"
Expand Down
25 changes: 11 additions & 14 deletions src/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
class Autoload
{
/**
* @var bool Whether self is registered as an autoloader.
* @var bool Whether self is registered as an autoloader
*/
protected static $registered = false;

/**
* @var array Class map. See addClassMap() for description of elements.
* @var array Class map. See addClassMap() for description of elements
*/
protected static $classMap = array();

/**
* @var array PSR-4 mapping stack. See addPsr4() for description of elements.
* @var array PSR-4 mapping stack. See addPsr4() for description of elements
*/
protected static $psr4 = array();

/**
* @var array PSR-0 mapping stack. See addPsr0() for description of elements.
* @var array PSR-0 mapping stack. See addPsr0() for description of elements
*/
protected static $psr0 = array();

Expand Down Expand Up @@ -81,9 +81,9 @@ public static function register()
* array($prefix, $path)
* ```
*
* @param string $prefix Class or Namespace prefix (no `\` added).
* @param string $path Base path/directory (automatically suffixed with `DIRECTORY_SEPARATOR`).
* @param bool $prepend Whether or not to prepend to PSR-0 mapping stack.
* @param string $prefix Class or Namespace prefix (no `\` added)
* @param string $path Base path/directory (automatically suffixed with `DIRECTORY_SEPARATOR`)
* @param bool $prepend Whether or not to prepend to PSR-0 mapping stack
*
* @see http://www.php-fig.org/psr/psr-0/
*/
Expand Down Expand Up @@ -138,9 +138,9 @@ public static function addIncludePath()
* array($prefix, $path)
* ```
*
* @param string $prefix Namespace prefix (automatically suffixed with `\`).
* @param string $path Base path/directory (automatically suffixed with `DIRECTORY_SEPARATOR`).
* @param bool $prepend Whether or not to prepend to PSR-4 mapping stack.
* @param string $prefix Namespace prefix (automatically suffixed with `\`)
* @param string $path Base path/directory (automatically suffixed with `DIRECTORY_SEPARATOR`)
* @param bool $prepend Whether or not to prepend to PSR-4 mapping stack
*
* @see http://www.php-fig.org/psr/psr-4/
*/
Expand Down Expand Up @@ -175,9 +175,6 @@ public static function getPsr4()
return static::$psr4;
}

/**
*
*/
public static function addClassMap(array $classMap, $path)
{
// If not registered, register.
Expand Down Expand Up @@ -232,7 +229,7 @@ public static function findFileForClass($class)
}

// PSR-4
//

// NOTE: Cannot use `foreach (static::$psr4 as list($prefix, $path))`
// for PHP < 5.5 compatibility.
foreach (static::$psr4 as $psr4) {
Expand Down
28 changes: 21 additions & 7 deletions src/Dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

class Dependencies
{
/* Already loaded dependencies */
public static $_loaded = array();

/**
* Static functions only.
*/
Expand All @@ -34,10 +37,10 @@ private function __construct()
* See README for examples.
*
* @param array $dependencies Dependencies
* @param bool $required Whether dependencies are required or not.
* @param bool $required Whether dependencies are required or not
*
* @throws \RuntimeException If required and no file is successfully loaded
* via {@link requireFile()}.
* via {@link requireFile()}
*/
protected static function process(array $dependencies, $required)
{
Expand All @@ -46,11 +49,21 @@ protected static function process(array $dependencies, $required)
$dependencyLoaded = false;

foreach ($dependency as $firstExistsDependency) {
try {
requireFile($firstExistsDependency);
if (in_array($firstExistsDependency, self::$_loaded)) {
$dependencyLoaded = true;
break;
} catch (\RuntimeException $e) {
}
}

if (!$dependencyLoaded) {
foreach ($dependency as $firstExistsDependency) {
try {
requireFile($firstExistsDependency);
$dependencyLoaded = true;
self::$_loaded[] = $firstExistsDependency;
break;
} catch (\RuntimeException $e) {
}
}
}

Expand All @@ -63,6 +76,7 @@ protected static function process(array $dependencies, $required)
} else {
try {
requireFile($dependency);
self::$_loaded[] = $dependency;
} catch (\RuntimeException $e) {
if ($required) {
throw $e;
Expand All @@ -77,7 +91,7 @@ protected static function process(array $dependencies, $required)
*
* Calls `process($requiredDependencies, true)`.
*
* @param array $requiredDependencies Required dependencies.
* @param array $requiredDependencies Required dependencies
*
* @see process()
*/
Expand All @@ -91,7 +105,7 @@ public static function required(array $requiredDependencies)
*
* Calls `process($optionalDependencies, false)`.
*
* @param array $optionalDependencies Optional dependencies.
* @param array $optionalDependencies Optional dependencies
*
* @see process()
*/
Expand Down
6 changes: 3 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* Originally taken from
* {@link https://github.com/composer/composer/blob/master/src/Composer/Autoload/ClassLoader.php Composer/Autoload/ClassLoader::includeFile()}.
*
* @param string $file File to `require_once`.
* @param string $file File to `require_once`
*
* @throws \RuntimeException If file does not exist or is not readable.
* @throws \RuntimeException If file does not exist or is not readable
*/
function requireFile($file)
{
Expand All @@ -38,7 +38,7 @@ function requireFile($file)
* Originally taken from
* {@link https://github.com/composer/composer/blob/master/src/Composer/Autoload/ClassLoader.php Composer/Autoload/ClassLoader::includeFile()}.
*
* @param string $file File to `include_once`.
* @param string $file File to `include_once`
*/
function includeFile($file)
{
Expand Down
21 changes: 21 additions & 0 deletions tests/DependenciesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ public function testRequiredFirstExists()
$this->assertFalse(class_exists('Foo\\Bar\\Baz'));
}

public function testRequiredAlreadyLoaded()
{
$this->assertFalse(class_exists('Foo\\Bar'));
$this->assertFalse(class_exists('Foo\\Bar\\Baz'));

Dependencies::required(array(
__DIR__.'/fixtures/Foo/Bar/Baz.php',
));

$this->assertTrue(class_exists('Foo\\Bar\\Baz'));

Dependencies::required(array(
array(
__DIR__.'/fixtures/Foo/Bar.php',
__DIR__.'/fixtures/Foo/Bar/Baz.php',
),
));

$this->assertFalse(class_exists('Foo\\Bar'));
}

public function testOptionalExists()
{
$this->assertFalse(class_exists('Foo\\Bar'));
Expand Down