danadesrosiers / silex-annotation-provider Goto Github PK
View Code? Open in Web Editor NEWA Silex ServiceProvider that defines annotations that can be used to define routes in a ServiceController.
License: MIT License
A Silex ServiceProvider that defines annotations that can be used to define routes in a ServiceController.
License: MIT License
This seems overkill and leaves users no choice.
My application does not need it but it still gets registered - why is it required (as per the comment)?
Is there a way to ignore a route for a given URL?
For example, I don't want the annotation for the path:
http://localhost/foo
But at the same time I would like to have the annotations working in the root, like:
http://localhost
here is my proposal
public function registerController($controllerName)
{
/**
* instead fetching reflection class, it build all class metadata
*/
if ($this->cache->contains("annot.{$controllerName}.metadara") && $this->useCache) {
$controllerMetadata = $this->cache->fetch("annot.{$controllerName}.metadara");
} else {
$controllerMetadata = $this->buildMetadata($controllerName);
}
if ($controllerMetadata["controller"]["annotation"] instanceof Controller) {
$this->app['annot.registerServiceController'](trim($controllerName, "\\"));
$this->process($this->app, $controllerMetadata);
}
}
Instead creating controller reflection class on registerController
method it would be great performance improvement if it build all class metadata (methods & annotation) in simple array or object so it can be cached for future use.
I am injecting into controller some factories and library is overriding PHP-DI and injecting into controller Silex\Application. Is there any workaround about this?
Is there a way to remove a given route being automatically used by the annotations?
Today I've got a bunch of controllers registered in the service provider, but let's say, for whatever reason I'd like to use the route /foo/bar
freely. How can I accomplish that?
obs: When I say freely, I mean without any annotation. Right know silex throws an exception saying 'Route not registered'.
Hi there,
This is not so much an issue but shameless self promotion....
I've created a library that allows to use silex annotations together with swagger-php to generate swagger JSON from the annotations: https://packagist.org/packages/radebatz/silex2swagger.
If it turns out to be useful (I use it a lot...) it would be great if perhaps there could be a reference to it somewhere in your docs.
Cheers, mano
Is there any specific reason you remove these feature?
Hello,
I have just updated to version 2.1.0 and all my routes are now ignored because of a combination of AnnotationService::getFiles()
and AnnotationService::registerControllers()
/ AnnotationService::prefixMatchesUri()
.
AnnotationService::getFiles()
builds an array which is indexed with both prefixes and indexes, then it is used by AnnotationService::registerControllers()
in a foreach($controllers as $prefix => $controllerNames)
.
When my controller doesn't have a prefix, the position in the array is used as a prefix /0
, /1
and so on, for example:
string(48) "Controller\CommonController"
string(7) "$prefix"
int(1)
string(2) "/1"
When my controller does have a prefix, it is re-prefixed by "/" which make the strpos
function fail, for example:
string(57) "Modules\Administration\ApiController" (I am using multiple controller directories)
string(7) "$prefix"
string(19) "/administration/api"
string(20) "//administration/api"
Here's how I register the service provider
<?php
$this->register(
new AnnotationServiceProvider(),
[
'annot.base_uri' => '/',
'annot.cache' => new ArrayCache(),
'annot.controllerDir' => [
__DIR__.'/Controller/',
__DIR__.'/Modules/',
],
]
);
I have, for now, regressed to version 2.0.1 so as to keep developing but I thought I would mention it here, be it an error on my part because I simply run composer update
or a code error. I am running PHP 7.2 on Apache 2.4 on Windows 10 x64.
Thank you,
Bruno Buiret
It would be great if support silex v2
I have my minimum-stability set to dev, but composer update barfs on your composer install instructions
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package ddesrosiers/silex-annotation-provider ~2.0@dev exists as ddesrosiers/silex-annotation-provider[1.1.x-dev, dev-master, v0.1.0, v0.1.1, v0.1.2, v0.2.0, v0.2.1, v1.0.0, v1.1.0] but these are rejected by your constraint.
I was wondering if it would be possible to add a way to pass some sort of context (array/map/object) into the generated annotations? This would be very useful for me :)
The point is that it could allow to make the annotations behave differently depending on the environment, etc.
For example, I'd like to add an environment requirement, so some annotations are only active/used if the environment matches.
if this sounds like something useful I'd be happy to create a pull request...
I work with
Silex: v2.1.0
ddesrosiers/silex-annotation-provider: v2.0
doctrine/cache: v1.7.1
PHP: 7.1.5
Docker, FPM, Alpine
In my src/app.php configure AnnotationServiceProvider
php $app->register(new AnnotationServiceProvider(), [ "annot.cache" => new ApcuCache(), "annot.controllerDir" => [ ROOT_PATH . "/src/App/Controllers", ROOT_PATH . "/src/Core/Controllers" ] ]);
And only work routes in /src/App/Controllers, other routes show error "Route not found".
But i remove annot.cache and work fine
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.