Skip to content

Commit

Permalink
PSR-4 conversion. Required a custom auto loader for the Doctrine Anno…
Browse files Browse the repository at this point in the history
…tations since the default behavior cannot handle a PSR-4 directory structure. A convenient side effect of which is that it is no longer a need to specify annot.srcDir.
  • Loading branch information
danadesrosiers committed Jun 15, 2014
1 parent 4651f53 commit 2f1d9f4
Show file tree
Hide file tree
Showing 33 changed files with 20 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
.idea
composer.lock
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
"symfony/security": "You will need this package to use the `Secure` annotation"
},
"autoload": {
"psr-0": {
"DDesrosiers\\SilexAnnotations\\": "src/",
"psr-4": {
"DDesrosiers\\SilexAnnotations\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DDesrosiers\\Test\\SilexAnnotations\\": "test/"
}
},
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ class AnnotationServiceProvider implements ServiceProviderInterface
*/
public function boot(Application $app)
{
AnnotationRegistry::registerAutoloadNamespace(
"DDesrosiers\\SilexAnnotations\\Annotations",
$app['annot.srcDir']
);

// Process annotations for any given controllers
if ($app->offsetExists('annot.controllers') && is_array($app['annot.controllers'])) {
foreach ($app['annot.controllers'] as $groupName => $controllerGroup) {
Expand Down Expand Up @@ -64,13 +59,19 @@ function (Application $app) use ($controllerName) {
*/
public function register(Application $app)
{
// Need the ability to register annotation namespace early for ControllerProviders
if ($app->offsetExists('annot.srcDir')) {
AnnotationRegistry::registerAutoloadNamespace(
"DDesrosiers\\SilexAnnotations\\Annotations",
$app['annot.srcDir']
);
}
// A custom auto loader for Doctrine Annotations since it can't handle PSR-4 directory structure
AnnotationRegistry::registerLoader(function ($class) {
$annotationDir = __DIR__ . "/Annotations";
$fqcn_array = explode("\\", $class);
$class_name = array_pop($fqcn_array);
if (is_file("$annotationDir/$class_name.php"))
{
/** @noinspection PhpIncludeInspection */
require_once "$annotationDir/$class_name.php";
return true;
}
return false;
});

// ServiceControllerServiceProvider is required, so register it here so the user doesn't have to.
$app->register(new ServiceControllerServiceProvider());
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function testRegisterControllers()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\TestControllerOne")
)
);
Expand All @@ -52,7 +51,6 @@ public function testRegisterControllersWithGroups()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../src",
"annot.controllers" => array(
'group1' => array("DDesrosiers\\Test\\SilexAnnotations\\TestControllerOne"),
'group2' => array("DDesrosiers\\Test\\SilexAnnotations\\TestControllerTwo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function testServiceController()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\TestController")
)
);
Expand All @@ -53,7 +52,6 @@ public function testControllerProvider()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\TestControllerProvider")
)
);
Expand All @@ -71,7 +69,6 @@ public function testCacheUsingStringIdentifier()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../src",
"annot.cache" => 'Array',
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\TestController")
)
Expand All @@ -87,7 +84,6 @@ public function testCacheUsingImplementationOfCache()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../src",
"annot.cache" => new ApcCache(),
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\TestController")
)
Expand All @@ -106,7 +102,6 @@ public function testInvalidCacheString()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../src",
"annot.cache" => 'Fake',
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\TestController")
)
Expand All @@ -122,7 +117,6 @@ public function testInvalidCacheClass()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../src",
"annot.cache" => new InvalidCache(),
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\TestController")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\AfterTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\AssertTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\BeforeTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\BindTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\ConvertTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\HostTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\ModifierTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\RequestTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\RequireHttpTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\RequireHttpsTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\RouteTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\SecureTestController")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function setUp()
$this->app->register(
new AnnotationServiceProvider(),
array(
"annot.srcDir" => __DIR__ . "/../../../../../src",
"annot.controllers" => array("DDesrosiers\\Test\\SilexAnnotations\\Annotations\\ValueTestController")
)
);
Expand Down

0 comments on commit 2f1d9f4

Please sign in to comment.