mmoreram / controllerextrabundle Goto Github PK
View Code? Open in Web Editor NEWController extra Bundle for Symfony2
License: MIT License
Controller extra Bundle for Symfony2
License: MIT License
I'm working on what will be new version 2 of the bundle.
This work will be appended in branch feature/version-2 and will not be BC break unless you've overridden some parts of the bundle, so if you just use the bundle as shown in the documentation, you'll be able to upgrade without any kind of problem. Otherwise, you'll find an upgrade file.
Here some points
@Service
and @Parameter
, a way of remove usage of containerWhat do you think?
Is there support for ODM/MongoDB?
Why is the paginator annotation named "PaginatorAnnotation" and not "Paginator"?
It will be a good idea to direcly access to the query and post parameters from the annotations.
GET /page?foo=bar
And you could get this parameters from:
<?php
//...
/**
* ...
* @Get(
* path = "foo",
* name = "varName"
* default = false,
* deep = false
* )
* ...
*/
public function anyAction(
$varName
) {
echo $varName;
// This would print 'bar'
}
Same would work for post requests:
POST /page
Body:
foo=bar
And you could get this parameters from:
<?php
//...
/**
* ...
* @Post(
* path = "foo",
* name = "varName"
* default = false,
* deep = false
* )
* ...
*/
public function anyAction(
$varName
) {
echo $varName;
// This would print 'bar'
}
Both would call the parameterBag get method.
Optional parameters:
Hi Marc,
I would like to be able to use a service container object (@elcodi.store) in your wheres clause
@PaginatorAnnotation(
* attributes = "paginatorAttributes",
* class = "elcodi.entity.product.class"
* page = "~page~",
* limit = 6
* wheres = {
* {"x", "enabled", "=", true},
* {"x", "showInHome", "=", true},
* {"x", "store", "=", "@elcodi.store"},
* },
..unfortunately I could not manage to get this running. Any ideas?
Thx
Roland
Hi,
I think I found an issue when adding multiple where params to the paginator. It seems something like:
* wheres = {
* {"x", "code", "=", "GER"},
* {"x", "dial", "=", "49"},
* }
doesn't work, it only loads the value of the last param and the query executed is like this:
`WHERE c0_.code = '49' AND c0_.dial = '49' ORDER BY c0_.code ASC) dctrn_result) dctrn_table
I've looking into the code and I think I found the problem: in the evaluate method of the PaginatorWheresEvaluator you initialize interation:
$iteration = 0;
but I think the $iterations++; is missing in the foreach loop.
I tried by adding it and it works perfectly now, here's the method:
public function evaluate(
QueryBuilder $queryBuilder,
AnnotationPaginator $annotation
)
{
$iteration = 0;
if (is_array($annotation->getWheres())) {
foreach ($annotation->getWheres() as $where) {
$whereValue = $this
->requestParameterProvider
->getParameterValue($where[3]);
$optionalFilter = (boolean) isset($where[4])
? $where[4]
: false;
if ($optionalFilter && ($where[3] === $whereValue)) {
continue;
}
$queryBuilder
->andWhere(trim($where[0]) . '.' . trim($where[1]) . " " . $where[2] . " ?0" . $iteration)
->setParameter("0" . $iteration, $whereValue);
# The missing iteration
$iteration++;
}
}
return $this;
}
Hello!
Thank you for the bundle, it looks great and we will use it in the future.
We use this code several times:
public function special...Action(Project $project)
{
$response = $this->render(
'@AppBundle/special....html.twig',
array(
'project' => $project,
)
);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
It would be great if we can introduce a header-annotation like
@Header('Access-Control-Allow-Origin', '*')
or
@AddHeader('Access-Control-Allow-Origin', '*')
Logger should be selected using logger name. For this, we need to create a LoggerFactory, returning desired logger, given a name.
When i use the annotation Secure of the JMSSecurityExtraBundle the annotation JsonResponse get ignored and i get LogicException "The controller must return a response".
Log component should accept expression language
Hi!
If I think well, here you wanna put back the % sign:
private function addWildcards($annotationWhereParameter, $whereValue)
{
$hasInitialPercentage = (strpos($annotationWhereParameter, '%') === 0);
$hasEndPercentage = (strpos($annotationWhereParameter, '%') === 0);
if ($hasInitialPercentage) {
$whereValue = '%' . $whereValue;
}
if ($hasEndPercentage) {
$whereValue = $whereValue . '%';
}
return $whereValue;
}
But, the second strpos
line is same with the first one, so you put % back and forth in any case, if it was the first char.
In my opinion, it's need to be stripos
for the correct work.
Hi,
I think I found a small bug in the Where section of the pagination.
When I try to add a parameter like this:
wheres = {
* {"x", "code", "LIKE", "code%", true},
* }
it seems like it doesn't work.
Looking into the code I think I fund the problem, in the addWildCards method of the PaginatorWheresEvaluator:
$hasInitialPercentage = (strpos($annotationWhereParameter, '%') === 0);
$hasEndPercentage = (strpos($annotationWhereParameter, '%') === 0);
if ($hasInitialPercentage) {
$whereValue = '%' . $whereValue;
}
if ($hasEndPercentage) {
$whereValue = $whereValue . '%';
}
return $whereValue;
The $hasEndPercentage uses the same condition as the hasIniticialPercentage. Could that be the problem? Thanks!
Hi,
Would it make sense to add an annotation to automatically create the knp breadcrumbs? Something like:
Now:
public function listAction(
$page,
$limit,
$orderByField,
$orderByDirection
) {
$breadcrumbs = $this->get("white_october_breadcrumbs");
$breadcrumbs
->addItem("backend.ui.home.label.title", $this->get("router")->generate("backend_home"))
->addItem("backend.accessory.list.label.title", $this->get("router")->generate("backend_accessories_list"));
With annotation:
/**
* Accessories list
* @Security("has_role('ROLE_ADMIN')")
*
* ...
* @Breadcrumbs({
* "backend.ui.home.label.title" = "backend_home",
* "backend.accesory.list.label.title" = "backend_accesories_list",
* })
*/
public function listAction(
$page,
$limit,
$orderByField,
$orderByDirection
) {
....
I don't know if it makes sense to add this kind of annotation and "interfer" with other bundles.
Howto create an Api REST using only annotations.
When I add more than one where value is ever the same.
Sometimes we don't need the Form
nor the FormView
but still want the magic behind FormAnnotation
. It would be nice to have no $form
parameter in the Controller
, if we're not going to use it anyway.
Now it checks for the class of the parameter and crashes if it does not exist (or if the type-hint is not a class)
Using expressionlanguage
I have 2 problems.
The "Paginator Wheres" are linked to "andwhere". I need "orwhere". What can I do?
I give a searchstring, which can also contain blank characters. The string should be split into the blank and each individual substring should then be passed to "Paginator Wheres". Is that possible?
I thank you for your help ...
i use symfony 2.3 and for composer the version 1.1.5 is listed as 2.3 compatible, however, wen ive just finished implementing some custom annotation i had this surprise exception.
request_stack is a symfony 2.4 feature, maybe you should fix the composer.json for this version.
It would be great if we can configure @Pagination annotation to return a PagerFanta Instance instead of Doctrine/Paginator.
Here is the bundle https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle.
Take a look at https://github.com/whiteoctober/Pagerfanta/blob/master/README.md#doctrineormadapter
example of conversion :
$paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($queryBuilder, true);
...
$pagerFanta = new \Pagerfanta\Pagerfanta(new \Pagerfanta\Adapter\DoctrineORMAdapter($paginator->getQuery()));
$request->attributes->set(
$parameterName,
$pagerFanta
);
Thank you !
Just copy and paste default config
controller_extra:
resolver_priority: -8
request: current
factory:
default_method: create
default_static: true
pagination:
active: true
default_name: paginator
default_page: 1
default_limit_per_page: 10
entity:
active: true
default_name: entity
default_persist: true
default_mapping_fallback: false
form:
active: true
default_name: form
object_manager:
active: true
default_name: form
flush:
active: true
default_manager: default
json_response:
active: true
default_status: 200
default_headers: []
log:
active: true
default_level: info
default_execute: pre
from documentation.
In @entity annotation, entityManager used to persist any specific entity should be really the manager of given entity, using Manager getManagerForClass() method.
see https://github.com/elcodi/elcodi/blob/master/src/Elcodi/CoreBundle/Services/ManagerProvider.php
When I try to filter a query with a like including wildcards and this value comes from get/post request, resulting query is not correct.
For example:
wheres = {
{ "x", "field" , "LIKE", "%?search?%" }
}
I'm searching the fix.
This parameter can have an entity or an array of entities.
If defined, each specified entity will be lonely flushed.
Otherwise, all EntityManager will be flushed.
default
managerInsetad of passing full Container, we should use some factory pattern :)
in Resolver/EntityAnnotationResolver.php, line 88
A Symfony dependency injection container has been found as an argument.
* @param string $defaultName Default name
* @param string $defaultManager Default manager
* @param boolean $defaultPersist Default persist
*/
public function __construct(
ContainerInterface $container,
AbstractManagerRegistry $doctrine,
array $kernelBundles,
$defaultName,
$defaultManager,
$defaultPersist
Posted from SensioLabsInsight
Also documentation of options and examples
Related to #10
Create and fill a class with these fields.
Hi,
I'm having a problem trying to filter date fields using the where params. I.e. if I do the following (expiration_date is a DateTime in the entity)
/*
*
* wheres = {
* {"x", "expiration_date", ">=", "?expiration_date?", true},
* }
* )
The problem is that by doing this I get a transformation error: Can not transform string to DateTime.
Is there any workaround? Is it possible to implement something to be able to search by datetime?
Thanks!
This annotation should contain an entity or a group of entities existing on Request ParameterBar
There are three optional values.
By default this value must be set as EXEC_PRE in config and must be overwriittable.
Hi,
I fund out that when trying to use boolean values in the filters.
Turns out that, i.e., I set a filter like
/*
* wheres = {
* {"x", "code", "LIKE", "?code?", true},
* {"x", "active, "=", "?active?", true},
* }
and I request the follwing url /page?active=0 the filter is not applied. Although if I request /page?active=1 then it works fine.
Seems to me like the 0 value is discard in the pre processing of the filter vars. Could be so?
Thanks!
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.