Code Monkey home page Code Monkey logo

knpradbundle's Introduction

knpradbundle's People

Contributors

aitboudad avatar akovalyov avatar artemdigi avatar baachi avatar brucewouaigne avatar cordoval avatar cursedcoder avatar defrag avatar djeg avatar docteurklein avatar everzet avatar f1nder avatar gquemener avatar herzult avatar inoryy avatar lsmith77 avatar ludovicstulmuller avatar nek- avatar pborreli avatar pedrotroller avatar rfkm avatar shivoham avatar umpirsky avatar wouterj avatar wysow 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  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

knpradbundle's Issues

[Bug] rad:generate:controller cause error if multilevel sub namespace was passed

example
console rad:generate:controller Level1/Level2/Level3:index

expected controller namespace
${AppBundleNS}\Level1\Level2\Level3;

generated controller namespace
${AppBundleNS}\Level1\Level2/Level3;

causes: "Parse error: syntax error, unexpected '/', expecting T_NS_SEPARATOR or ';' or '{' in...."

Solution
Replacement for GenerateControllerCommand:execute in L44

$subns     = str_replace('/', '\\', dirname(str_replace('\\', '/', $class)));

How to register bundles that require constructor arguments?

For example, to register the JMS Serializer Bundle is required to do something like this:

bundles = array(
    // ...
    new JMS\SerializerBundle\JMSSerializerBundle($this),
    // ...
);

In these cases, how to register bundles in kernel.yml ?

Thanks.

Unable to use subdirectories with routing

I am trying to break my controllers up into two folders, "frontend" and "admin". So I added the following routes to my routing.yml

App:Frontend:Home:index: /
App:Admin:Post:index: /admin/posts/

When I visit the home page of the site I get the following error:

Unable to find controller "App:Frontend" - class "App\Controller\FrontendController" does not exist.

Is this something that should or will be supported by the KnpRadBundle?

Translatable fields are not persisted when updating entity with RadController shortcuts

I'm using knp translatable behavior and when object is created, translatable fields are persisted normally, but when object is updated changes on translatable fields are ignored. Ex I have this code in updateAction:

...
  /*This controller extends RadController*/

   if ($form->isValid()) {

    $entity->translate('fr')->setName('Chaussures');
    $entity->translate('en')->setName('Shoes');

        $this->persist($entity, true);

        return $this->redirectToRoute('somewhere');

    }
...

If instead call RadController shortcuts methods I persist entity like this, works perfect.

$this->getDoctrine()->getManager()->persist($entity);
$this->getDoctrine()->getManager()->flush();

Licensing?

There doesn't seem to be any mention of licensing in the repository or anywhere I could find. Having something would be reassuring since public domain can sometimes be a bit... sticky.

Documentation

It's a fact: it's quite hard to get started with the rad edition cause the documention is not good enough.

Let's discuss a plan for a brand new documentation that compiles in RST so we can generate some website/pdf using a shinny theme.

So bellow is a starting draft:

  • Quick overview
  • Getting started
    • Installation
    • Hello World
  • Controllers
    • Convention
    • Automatic view rendering
    • Available shortcuts
  • Forms
    • Convention
    • Form creator
    • Controller shortcuts
    • Registration of types
  • Routes
    • Convention
    • Resource routing
  • Flash messages
    • Convention
    • Message anatomy
    • Controller shortcut
    • Twig extension
  • Security
    • Convention
    • Built-in voters
    • Registering custom voters
  • Specifications
    • StoryBDD
    • SpecBDD

Security voter service registration failing

I have a Voter located at App->Security->JobVoter.php that looks something like this

namespace App\Security;

use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\Entity\Job;

class JobVoter implements VoterInterface, ContainerAwareInterface
{
    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function supportsAttribute($attribute)
    {
        return in_array($attribute, [
            'OWNER'
        ]);
    }

    public function supportsClass($object)
    {
        return $object instanceof Job;
    }

    public function vote(TokenInterface $token, $object, array $attributes)
    {
        if (null === $object || !$this->supportsClass($object)) {
            return VoterInterface::ACCESS_ABSTAIN;
        }

        foreach ($attributes as $attribute) {
            if ($this->supportsAttribute($attribute)) {
                switch ($attribute) {
                    case 'OWNER':
                    if ($token->getUser() !== $object->getCreatedBy()) {
                        return self::ACCESS_DENIED;
                    }
                    break;
                }
            }
        }

        return self::ACCESS_GRANTED;
    }
}

This is giving me the following error:

FatalErrorException: Error: Cannot use object of type Symfony\Component\DependencyInjection\Reference as array in ../vendor/knplabs/rad-bundle/Knp/RadBundle/DependencyInjection/DefinitionManipulator.php line 12

[RFC][Routing] Controllers in sub folders

I like to keep my Controllers namespaced depending on their purpose. For example:

  • App/Controllers/Api/ProjectsController
  • App/Controllers/Admin/ProjectsController
  • App/Controllers/App/ProjectsController

Is this currently possible in KnpRadBundle if not would a pull request be in scope of the project.

Security/sessions error in Max OS X Installation

Installing this great new bundle on Mac Lion with MAMP, getting this error when trying to view a page:

"ErrorException: Catchable Fatal Error: Object of class __PHP_Incomplete_Class could not be converted to string in /Applications/MAMP/htdocs/{PROJECT}/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php line 70"

I can probably solve it with a php.ini setting change, but since I'm using a very common dev environment I wanted to post the issue. Thanks!

Providing a javascript for unsupported method call

What about providing a javascript loaded in the rad base template that will handle DELETE, PUT, PATCH, ... method that can't be handled in html5 directly?
Something like :

    jQuery('body').on('click', 'a.delete', function (event) {
        event.preventDefault();

        if (confirm(jQuery(event.target).data('confirm') || 'Are you sure?')) {
            var form    = document.createElement('form');
            var input   = document.createElement('input');

            form.method = 'POST';
            form.action = event.currentTarget.href;

            input.type  = 'hidden';
            input.name  = '_method';
            input.value = 'DELETE';

            form.appendChild(input);
            document.body.appendChild(form);

            form.submit();
        }
    });

I'm getting tired of copy/pasting it to every project I work on ๐Ÿ‘…

wrong imagine bundle used

Your skeleton for the Imagine config uses an old bundle (a fork of the first bundle created by @avalanche123 and deleted long ago). This bundle is incompatible with both Symfony (it is written for PR10 or something like that) and Imagine

you should use https://github.com/avalanche123/AvalancheImagineBundle (official basic integration) or https://github.com/liip/LiipImagineBundle (most advanced features as @avalanche123 wanted to keep his own bundle very simple). And the best solution would be to provide the skeleton for both of course :)

Command generate:bundle does not exist

Hi guys,
when trying to generate a bundle
"php app/console generate:bundle --namespace=MyNS\MyBundle --format=xml"
I get the following error:
Command "generate:bundle" is not defined.

Is that command supported in KnpRadBundle?

Doctrine and ORM ?

I can't manage to get Doctrine/ORM works.

First of all, seems that I have no doctrine.yml. I don't know if I should install more bundles, but I've got the SolverProblemsException with composer that a lot of people get.

So, is Doctrine currently implemented in RadBundle or should I install it ? If so, what's the way to do it, because I found nothing on it.

incorrect handling of missing "extends" templates

If an extends template is missing, it will trigger the missing view handling, which then suggests to create the action template again instead of realizing that its not the action template that is missing, but one of the extends, ie. parent, templates that is missing.

Installation is not so rad

After

composer.phar create-project -s dev --prefer-dist --dev knplabs/rad-edition my_project

Then

error

Me

:(

The function "link_attr" does not exist in App:Member:index.html.twig

Following example on "csrf protected links", the function link_attr is not found.

<a {{ link_attr('delete', 'Are you really sure ?') }} href="{{ path('app_member_delete', { 'id': member.id }) }}">Supprimer</a>

I'm using Symfony v2.2.1 and the "develop" branch of this bundle.

    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.2.*",
        "symfony/swiftmailer-bundle": "2.2.*",
        "symfony/monolog-bundle": "2.2.*",
        "doctrine/orm": "~2.3",
        "doctrine/doctrine-bundle": "1.2.*@alpha",
        "sensio/distribution-bundle": "2.2.*",
        "knplabs/rad-bundle": "2.3",
        "knplabs/knp-menu-bundle":"~1.1.0@dev",

        "twig/extensions": "1.0.*@dev",

        "symfony/assetic-bundle": "2.1.*",
        "kriswallsmith/assetic": "1.1.*@dev",

        "doctrine/doctrine-fixtures-bundle": "2.1.*@dev",
        "doctrine/data-fixtures": "1.0.*@dev",

        "mopa/bootstrap-bundle": "2.1.*@dev",
        "mopa/composer-bridge": "*@dev",
        "stof/doctrine-extensions-bundle": "~1.1@dev",

        "friendsofsymfony/user-bundle": "*",
        "sonata-project/admin-bundle": "2.2.*@dev",
        "sonata-project/doctrine-orm-admin-bundle": "2.2.*@dev",
        "sonata-project/user-bundle": "2.2.*@dev",
        "sonata-project/block-bundle": "2.2.*@dev"
    },

wrong path in phpunit.xml

I set custom project name (not KnpRad) and path in phpunit.xml is wrong
https://github.com/KnpLabs/KnpRadBundle/blob/master/Resources/skeleton/project/phpunit.xml.dist#L18

$ phpunit
PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "Knp Rad intro suite.php" nor "Knp Rad intro suite.php" could be opened.' in /usr/share/php/PHPUnit/Util/Skeleton/Test.php:100
Stack trace:
#0 /usr/share/php/PHPUnit/TextUI/Command.php(152): PHPUnit_Util_Skeleton_Test->__construct('Knp Rad intro s...', '')
#1 /usr/share/php/PHPUnit/TextUI/Command.php(125): PHPUnit_TextUI_Command->run(Array, true)
#2 /usr/bin/phpunit(46): PHPUnit_TextUI_Command::main()
#3 {main}
  thrown in /usr/share/php/PHPUnit/Util/Skeleton/Test.php on line 100

Translations not loaded in src/KnpRad/Resources/translations

I wasted my time and crashed my head against the wall today.
I was trying to translate my app by putting translations into src/MyApplication/Resources/translations/messages.fr.yml.
But I still had Shakespeare's language instead of Moliere until I moved translation files into /app/Resources/translations.

What's wrong ? Have you got the same issue ? Looks like a bug for me or maybe we should update the documentation.

Using composition instead of inheritance for the template name parser

Using composition instead of inheritance would be less intrusive by allowing to nest as many composed parser as needed.

the way to overwrite it can be seen here: https://github.com/BeSimple/BeSimpleI18nRoutingBundle/pull/6/files#diff-1 My refactoring is under MIT so you can use the compiler pass to adapt it to your need without any issue.
This will work at best if other bundles wanting to overwrite it also uses composition this way (and not a crappy way forcing to compose the FrameworkBundle service only) but it can work too with bundles using a dumb composition or using inheritance if you take care to apply KnpRadBundle after them (as KnpRad would then take care to do things cleanly)

fatal error during install

I wanted to test this promising bundle, bunt during composer install, I get... ;(


[ErrorException]
  symlink(): Operation not supported

It could be able to auto detect the type of a form field using naming conventions.

using TypeGuesser.

We already have a DataTypeGuesser, that knows to add a collection type when the property is type array or Collection.
Same for DateTime.

What could be cool is to add a typeGuesser that knows which type class to use when available (for collection f.e).

Example:

  • there a BlogPost object.
  • BlogPost has many Comments.
  • there is a 'comments' field in the BlogPostType
  • comments field is guessed to be a collection type with options [ type: new CommentsType]

Better documentation

Hi all,

First of all, thanks for this great work. ๐Ÿ‘
I've tested routing, forms and datatables and it's really easy to use.

With symfony 2.2 I've been obliged to use this :

class App extends Bundle
{
    public function boot()
    {
        Request::enableHttpMethodParameterOverride();
    }
}

Concerning the globale documentation, it is really poor.
For example, reading the code, I found how to add button in the table building this var :

public function indexAction()
{
    $items = $this->getRepository('App:User')->findAll();

    $routes = array(
        'show' => array(
            'path' => 'app_user_show',
            'label' => 'Show',
            'parameters' => array('id' => 'id')
        ),
        'edit' => array(
            'path' => 'app_user_edit',
            'label' => 'Edit',
            'parameters' => array('id' => 'id')
        ),
        'delete' => array(
            'path' => 'app_user_delete',
            'label' => 'Delete',
            'parameters' => array('id' => 'id')
        ),
    );

    return array('items' => $items, 'routes' => $routes);
}

and setting it in the twig template like that :

<table class="table table-hover table-bordered table-condensed">
    {{ bootstrap_datatable(items, {bootstrap: 'Twitter_Bootstrap', routes: routes}) }}
</table>

But I haven't been able to find such documentation about it.

Thanks for your feedback.

can't remove all resources from routing

Is there a way to remove all resource routes? I thought something like this might work.

App:Test:
    collections: 
        index: ~
        custom:
            pattern: /custom/
    resources: ~

But I am still getting the following routes when running router:debug

I also tried resources: [] and resources: {}, which produced the same results

app_test_show GET /test/{id}
app_test_edit GET /test/{id}/edit
app_test_update PUT /test/{id}
app_test_delete DELETE /test/{id}

Single bundle application wide -??

Even application specific code can become too varied to comfortably sit together in a single bundle.

Please consider allowing multiple bundles according to application needs.

Otherwise you may be limiting this great bundle's applicability to small projects only.

Create a (dev-)branch for SF2.1

RadBundle seems to basically work with SF2.1.
Therefore it would be nice to have a modified branch and maybe even packagist package for it.

TODOs:

  • modifiy composer symfony dependencies for 2.1 (e.g. 2.1.*)
  • remove (apparently no longer necessary and even causing errors) swiftmailer autoloader from "Knp\Bundle\RadBundle\HttpKernel\RadKernel ::createAppKernel" since this is now done correctly by composer

Create Validator in Controller.

Hi,

I have problem with validation.

In my controller:

$User = new User();
$User->setFirstName('Martin');
$User->setLastName('Grochulski');

$validator = $this->container->get('validator');
$errors = $validator->validate($User);
var_dump($errors);

I have create the validation with annotation in my User Entity,

When I do that, symfony return:

FatalErrorException: Error: Cannot instantiate abstract class Knp\RadBundle\Doctrine\EntityRepository in /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 689

[Assetic Pipeline] Allow to define custom dirs for types

I'm using Bootstrap with my project, and decided to clone it and use the LESS version.

So, I added the dependency to my composer.json (I had to define a new repository since Bootstrap isn't available natively through Composer), and modified my knp_rad.yml as follows:

all:
    # ...

    assetic_pipeline:
        enabled:  true
        paths:
            - %kernel.project_dir%/Resources/public
            - %kernel.project_root%/assets
            - %kernel.project_root%/vendor/twitter/bootstrap

    # ...

Then, I created a new style.css that contained the following:

/*
 *= require libs/boilerplate
 *= require bootstrap
 */

But I get an error because Assetic Pipeline looks for the dependency in vendor/twitter/bootstrap/css/, while it should look under vendor/twitter/bootstrap/less.

It'd be nice if I could define additional sub-directories to look in when resolving dependency, e.g..:

all:
    # ...

    assetic_pipeline:
        # ...
        types:
            css: ["css", "less", "sass", "scss"]
            js: ["js", "coffee"]

    # ...

What do you think?

[Semantic Configuration] A config TreeBuilder

I have noticed that actually the RadBundle does not permit to define a correct config TreeBuilder. It would be interesting to give this kind of functionality. Maybe simplify it a little bit.

I am thinking about how to improve the actual AppBundle and add two methods like :

public function buildTree(NodeParentInterface $rootNode);

public function buildContainer(array $config, ContainerBuilder $container)

The buildContainer method corespond to the standard load method of an bundle Extension object. Except that the given $config in this new method is already parsed.

What did you think about this idea ?

Add documentation on flashes tag

Dear @Herzult,

I hope everything is going well for you in the country of Andouillette.
Would it be possible that you add some usage documentation on the flashes tag?
At least, so we can update the base tb layout that still uses app.session.flashes (which is baaaad).

Sincerly yours,

GildasQ.

Custom QueryBuilder

Hi guys.

In one of my projects I used a quite different division of the repository to which I used to do. The idea was to define the various states of my entity and then chaining these states in the repository to have a code clearer and extensible. I give you a exemble.

This is a simple entity.

<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Entity\ProductRepository")
 */
class Product
{

    const STATUS_APPROVED = 1;
    const STATUS_REJECTED = 0;

    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $name;

    /**
     * @ORM\Column(type="string")
     */
    protected $createdBy;

    /**
     * @ORM\Column(type="datetime")
     */
    protected $createdAt;

    /**
     * @ORM\Column(type="datetime")
     */
    protected $removedAt;

    /**
     * @ORM\Column(type="integer")
     */
    protected $status;

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    public function getCreatedBy()
    {
        return $this->createdBy;
    }

    public function setCreatedBy($createdBy)
    {
        $this->createdBy = $createdBy;

        return $this;
    }

    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    public function getRemovedAt()
    {
        return $this->removedAt;
    }

    public function setRemovedAt($removedAt)
    {
        $this->removedAt = $removedAt;

        return $this;
    }

    public function getStatus()
    {
        return $this->removedAt;
    }

    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

}

Now, I want to add a method to her repository to recieved all displayable entites.

My customer told me that a displayable product should be active (should be created and shouldn't be removed) and must have an approved status. So I create this method :

<?php

namespace App\Entity;

use Knp\RadBundle\Doctrine\EntityRepository;

class ProductRepository extends EntityRepository
{

    public function findDisplayable()
    {
        return $this
            ->build()
            ->andWhere('p.createdAt <= :today')
            ->andWhere('p.removedAt > :today')
            ->andWhere('p.status = :status_approved')
            ->setParameter('status_approved', Product::STATUS_APPROVED)
            ->setParameter('today', new \DateTime)
            ->getQuery()
            ->getResult()
        ;
    }

}

But, I think is not clear anougth. If the entity grows and the application becomes more and more complex, this repository classe will has a lot of lines and will be unreadable.

My approche is to say : "One method, one state". For exemple, if I extract all states of my customer needs, I've got those states :

  • created (or not)
  • removed (or not)
  • approved (or rejected)
  • displayable

If you look at the GeekWeek12 repo, I've splitted my query building in separated methods but it's not clear anougth.

I propose to include custom query builder linked to the customs repository which containes states methods. For our example, it should be a class like this :

<?php

namespace App\Entity;

use Knp\RadBundle\Doctrine\QueryBuilder as BaseQueryBuilder;

use App\Entity\Product;

class ProductQueryBuilder extends BaseQueryBuilder
{

    public function whichAreCreated()
    {
        return $this
            ->andWhere(sprintf('%s.createdAt <= :today', $this->getAlias()))
            ->setParameter('today', new \DateTime)
        ;
    }

    public function whichAreNotCreated()
    {
        return $this
            ->andWhere(sprintf('%s.createdAt > :today', $this->getAlias()))
            ->setParameter('today', new \DateTime)
        ;
    }

    public function whichAreRemoved()
    {
        return $this
            ->andWhere(sprintf('%s.removedAt <= :today', $this->getAlias()))
            ->setParameter('today', new \DateTime)
        ;
    }

    public function whichAreNotRemoved()
    {
        return $this
            ->andWhere(sprintf('%s.removedAt > :today', $this->getAlias()))
            ->setParameter('today', new \DateTime)
        ;
    }

    public function whichAreApproved()
    {
        return $this
            ->andWhere(sprintf('%s.status = :status_approved', $this->getAlias()))
            ->setParameter('status_approved', Product::STATUS_APPROVED)
        ;
    }

    public function whichAreRejected()
    {
        return $this
            ->andWhere(sprintf('%s.status = :status_approved', $this->getAlias()))
            ->setParameter('status_approved', Product::STATUS_REJECTED)
        ;
    }

    public function whichAreDisplayable()
    {
        return $this
            ->whichAreCreated()
            ->whichAreNotRemoved()
            ->whichAreApproved()
        ;
    }

}

It's longer but it's clear and if the customer wants to redifined one of those states, you dont have to read all the repository to apply the modification.

What do you think?

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.