Giter Site home page Giter Site logo

controllerextrabundle's People

Contributors

alch avatar bitdeli-chef avatar c33s avatar davidschmidt avatar eriktrapman avatar gerfigna avatar ickbinhier avatar javiereguiluz avatar jjmonagas avatar mmoreram avatar nilportugues avatar octante avatar oskarstark avatar rogergros avatar sidux avatar xphere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

controllerextrabundle's Issues

KNP Breadcrumb annotation

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.

persist annotation

This annotation should contain an entity or a group of entities existing on Request ParameterBar

Get Query or Post params on annotation

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:

  • name (The name should be the same than the original path"
  • default (Default parameterBag value)
  • deep (Default parameterBag value)

PaginatorWheresEvaluator bug

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.

Support FormAnnotation with no form parameter

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)

Problem when using boolean params in the where filters

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!

JsonResponse annotation

Related to #10

  • Create JsonResponse annotation
  • Response status and headers should be configurable by parameters ( defaults ) and inline ( in Annotation )
  • Tests
  • Documentation

Add entity parameter in flush annotation

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.

Unrecognized option "pagination" under "controller_extra"

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.

[Insight] The Symfony Dependency Injection Container should not be passed as an argument

Insetad 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

Entity can be persisted

  • In @entity annotation, you can persist it.
  • Manager should be defined, by default, default manager
  • persist option also should have a default value

Set log option "execute"

There are three optional values.

  • EXEC_PRE - Executes the log before action
  • EXEC_POST - Executes the log after action
  • EXEC_BOTH - Execute the log both

By default this value must be set as EXEC_PRE in config and must be overwriittable.

Adding PagerFanta Support

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 !

Version 2

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

  • Close the classes visibility by turning everything private and all classes final. This will help composition over inheritance
  • Use BaseBundle to reduce some parts complexity. Tests complexity will be reduced as well
  • These unit testing scenarios are useless, so will be removed. Instead of that, some extra functional tests will be added to cover more rare cases
  • Updated minimum PHP version to 7.1 in order to be able to use BaseBundle. Lets make this step all of us. Old users will continue being able to use old versions of this bundle.
  • New extension point for providers will be introduced. New DIC services and parameters providers will be added
  • New annotation @Service and @Parameter, a way of remove usage of container Has no sense at all...

What do you think?

PaginatorAnnotation Factory Pattern

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

orwhere and substring search

I have 2 problems.

  1. The "Paginator Wheres" are linked to "andwhere". I need "orwhere". What can I do?

  2. 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 ...

Header annotation

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', '*')

v1.1.5 has a dependency on a non-existent service "request_stack"

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.

Problems using dates in the paginator where params

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!

Multiple paginator params don't work

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;
    }

Wildcard % not working properly

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!

Use factory to get Logger

Logger should be selected using logger name. For this, we need to create a LoggerFactory, returning desired logger, given a name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.