├── .gitignore ├── .travis.yml ├── phpunit.xml.dist ├── LICENSE ├── composer.json ├── src └── Dflydev │ └── Psr0ResourceLocator │ └── Composer │ └── ComposerResourceLocator.php ├── README.md └── tests └── Dflydev └── Psr0ResourceLocator └── Composer └── ComposerResourceLocatorTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | composer.lock 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3.3 5 | - 5.3 6 | - 5.4 7 | 8 | before_script: 9 | - wget -nc http://getcomposer.org/composer.phar 10 | - php composer.phar install --dev 11 | 12 | script: phpunit --coverage-text --verbose 13 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./tests/Dflydev/Psr0ResourceLocator/Composer 6 | 7 | 8 | 9 | 10 | 11 | ./src/Dflydev/Psr0ResourceLocator/Composer/ 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Dragonfly Development Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dflydev/psr0-resource-locator-composer", 3 | "description": "Composer PSR-0 Resource Locator", 4 | "keywords": ["composer", "psr0", "classpath", "namespace", "namespaceish"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Dragonfly Development Inc.", 9 | "email": "info@dflydev.com", 10 | "homepage": "http://dflydev.com" 11 | }, 12 | { 13 | "name": "Beau Simensen", 14 | "email": "beau@dflydev.com", 15 | "homepage": "http://beausimensen.com" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.3.3", 20 | "dflydev/composer-autoload": "1.0.*@dev", 21 | "dflydev/psr0-resource-locator": "1.0.*@dev" 22 | }, 23 | "provide": { 24 | "dflydev/psr0-resource-locator-implementation": "1.0.0-alpha" 25 | }, 26 | "autoload": { 27 | "psr-0": { 28 | "Dflydev\\Psr0ResourceLocator\\Composer": "src" 29 | } 30 | }, 31 | "extra": { 32 | "branch-alias": { 33 | "dev-master": "1.0-dev" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Dflydev/Psr0ResourceLocator/Composer/ComposerResourceLocator.php: -------------------------------------------------------------------------------- 1 | 21 | */ 22 | class ComposerResourceLocator extends AbstractPsr0ResourceLocator 23 | { 24 | private $classLoaderLocator; 25 | 26 | /** 27 | * Constructor 28 | * 29 | * @param ClassLoaderLocator $classLoaderLocator 30 | */ 31 | public function __construct(ClassLoaderLocator $classLoaderLocator = null) 32 | { 33 | $this->classLoaderLocator = $classLoaderLocator ?: new ClassLoaderLocator; 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | protected function loadMap() 40 | { 41 | $reader = $this->classLoaderLocator->getReader(); 42 | 43 | $prefixes = $reader->getPrefixes(); 44 | $prefixes[""] = $reader->getFallbackDirs(); 45 | 46 | return $prefixes; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Composer PSR-0 Resource Locator 2 | =============================== 3 | 4 | The Composer [PSR-0][1] Resource Locator implementation leverages 5 | [dflydev/composer-autoload][2] to locate the effective Composer autoloader 6 | in use at runtime and accesses its namespace map. 7 | 8 | See [dflydev/psr0-resource-locator][3] for more information on 9 | the [PSR-0][1] Resource Locator interface. 10 | 11 | 12 | Requirements 13 | ------------ 14 | 15 | * PHP 5.3+ 16 | * [dflydev/psr0-resource-locator][3] 17 | * [dflydev/composer-autoload][2] 18 | 19 | 20 | Installation 21 | ------------ 22 | 23 | This library can installed by [Composer][4]. 24 | 25 | 26 | Usage 27 | ----- 28 | 29 | ```php 30 | findFirstDirectory( 40 | 'Vendor\Project\Resources\mappings' 41 | ); 42 | 43 | // Search all PSR-0 namespaces registered by Composer 44 | // to find all templates directories looking like: 45 | // "/Vendor/Project/Resources/templates" 46 | $templateDirs = $resourceLocator->findDirectories( 47 | 'Vendor\Project\Resources\templates', 48 | ); 49 | 50 | ``` 51 | 52 | 53 | License 54 | ------- 55 | 56 | MIT, see LICENSE. 57 | 58 | 59 | Community 60 | --------- 61 | 62 | If you have questions or want to help out, join us in the [#dflydev][5] 63 | channel on irc.freenode.net. 64 | 65 | 66 | [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md 67 | [2]: https://github.com/dflydev/dflydev-composer-autoload 68 | [3]: https://github.com/dflydev/dflydev-psr0-resource-locator 69 | [4]: http://getcomposer.org/ 70 | [5]: irc://irc.freenode.net/#dflydev 71 | 72 | 73 | -------------------------------------------------------------------------------- /tests/Dflydev/Psr0ResourceLocator/Composer/ComposerResourceLocatorTest.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class ComposerResourceLocatorTest extends \PHPUnit_Framework_TestCase 11 | { 12 | /** 13 | * Functionality 14 | */ 15 | public function testFunctionality() 16 | { 17 | $resourceLocator = new ComposerResourceLocator; 18 | 19 | $projectRoot = dirname(dirname(dirname(dirname(__DIR__)))); 20 | 21 | $directories = $resourceLocator->findDirectories('Dflydev\Psr0ResourceLocator\Composer'); 22 | $this->assertCount(1, $directories); 23 | $this->assertEquals($projectRoot.'/src/Dflydev/Psr0ResourceLocator/Composer', $directories[0]); 24 | 25 | $directory = $resourceLocator->findOneDirectory('Dflydev\Composer\Autoload'); 26 | $this->assertEquals($projectRoot.'/vendor/dflydev/composer-autoload/src/Dflydev/Composer/Autoload', $directory); 27 | } 28 | 29 | /** 30 | * Test swapping out implementation 31 | */ 32 | public function testImplementation() 33 | { 34 | $reader = $this->getMock('Dflydev\Composer\Autoload\ClassLoaderReaderInterface'); 35 | 36 | $reader 37 | ->expects($this->once()) 38 | ->method('getPrefixes') 39 | ->will($this->returnValue(array( 40 | 'Dflydev\Psr0ResourceLocator\Composer' => array(realpath(__DIR__.'/../../..')), 41 | ))); 42 | 43 | $reader 44 | ->expects($this->once()) 45 | ->method('getFallbackDirs') 46 | ->will($this->returnValue(array())); 47 | 48 | $classLoaderLocator = $this->getMock('Dflydev\Composer\Autoload\ClassLoaderLocator'); 49 | 50 | $classLoaderLocator 51 | ->expects($this->once()) 52 | ->method('getReader') 53 | ->will($this->returnValue($reader)); 54 | 55 | $resourceLocator = new ComposerResourceLocator($classLoaderLocator); 56 | 57 | $projectRoot = dirname(dirname(dirname(dirname(__DIR__)))); 58 | 59 | $directories = $resourceLocator->findDirectories('Dflydev\Psr0ResourceLocator\Composer'); 60 | $this->assertCount(1, $directories); 61 | $this->assertEquals($projectRoot.'/tests/Dflydev/Psr0ResourceLocator/Composer', $directories[0]); 62 | 63 | $directory = $resourceLocator->findOneDirectory('Dflydev\Psr0ResourceLocator\Composer'); 64 | $this->assertEquals($projectRoot.'/tests/Dflydev/Psr0ResourceLocator/Composer', $directory); 65 | } 66 | } 67 | --------------------------------------------------------------------------------