kendoctor / knd-rad-bundle
The Kendoctor Rad Edition bundle
Requires
- php: >=5.4
- fzaninotto/faker: ~1.2
- knplabs/knp-paginator-bundle: ^2.4
- nelmio/alice: ~1.5
- symfony/symfony: ~2.4
Requires (Dev)
- behat/behat: ~3.0
- behat/mink-extension: ~2.0
- behat/mink-goutte-driver: ~1.0
- behat/mink-selenium2-driver: ~1.1
- doctrine/doctrine-fixtures-bundle: *
- doctrine/orm: ~2.4
- phpspec/phpspec: ~2.0
- symfony/swiftmailer-bundle: ~2.3
- twig/twig: ~1
Suggests
- doctrine/doctrine-fixtures-bundle: To Take advantage of the Rad Doctrine AbstractFixture
- doctrine/orm: To take advantage of the Rad password hash updater listener
- symfony/form: To take advantage of the Rad Form Manager
- symfony/security: To take advantage of the Rad User Interface
- symfony/swiftmailer-bundle: To take advantage of the Rad mailer logger in your tests
This package is not auto-updated.
Last update: 2025-03-05 19:51:56 UTC
README
#KndRadBundle#
Rapid Application Development bundle for Symfony2 inspired by KnpRadBundle
##Features###
- Auto Dependency Injection
- Entity Model Manager
- Model Security Voter
##Installation##
composer require knd/rad-bundle
After installation, add bundle into kernel.
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
...
new \Knd\Bundle\RadBundle\KndRadBundle(),
...
);
}
...
}
Extends you bundle with Knd\Bundle\RadBundle\Bundle\Bundle
:
namespace AppBundle;
use Knd\Bundle\RadBundle\Bundle\Bundle;
class AppBundle extends Bundle
{
}
##Auto Dependency Injection##
###Common class injected as service###
If you want to inject a normal class as a service, for example:
namespace AppBundle\Generator;
class SomeGenerator
{
}
Add KndRadBundle
config in app/config.yml
knd_rad:
auto_inject:
common:
#auto inject classes in the directories, default ``Form``
dirs: [ Form, Generator, SomeDirectory/SubDirectory, ...]
#auto inject specified classes, default None
classes:
- AppBundle\SomeDirectory\SomeClass
#exclude classes to prevent being injected if the classes exist in dirs, default None
exclude_classes:
- AppBundle\OtherDirectory\OtherClass
For class AppBundle\Generator\SomeGenerator
-
Full name of the class injected as container parameter
app.class.generator.some
-
The class inject into container as:
services: app.generator.some class: %app.class.generator.some% arguments: []
If class suffix is same as root(relative bundle directory) directory, it will be trimmed.
Other possibilities:
Acme\Bundle\SomeBundle\Builder\SubDir\SomeBuilder
=> acme_some.class.generator.sub_dir_some #class container parameter
=> acme_some.generator.sub_dir_some #service id
NOTE
If you want a newly added class to be automatically injected, you need clear cache
php app/console cache:clear
If the class constructor has parameters, for example:
namespace AppBundle\Builder;
use Knd\Bundle\RadBundle\DependencyInjection\AutoInjectInterface;
class SomeBuilder implements AutoInjectInterface
{
private $em;
private $class;
public function __construct($class, $em)
{
$this->class = $class;
$this->em = $em;
}
public static function getConstructorParameters()
{
return array(
'%app.class.entity.product%',
'@doctrine.orm.entity_manager'
);
}
}
As you can see:
- %app.class.entity.product% - will be a container parameter
- @service_id - will be a service
Other possibilities:
Form Type services, classes should implement Symfony\Component\Form\FormInterface
namespace AppBundle\Form\UserType
class UserType extends AbstractType
=> app.class.form.user_type
=> app.form.type.user
Entity Repository services, class should extend Doctrine\ORM\EntityRepository
AppBundle\Repository\UserRepository
=> app.class.repository.user #class container parameter
=> app.repository.user #service id
Default repository class directory is Repository
,
If you want repository classes stay in the same dir with entity:
//config.yml
knd_rad:
auto_inject:
entity:
repository:
dir: Entity
You also do not need specify entity class's repository in orm mapping:
AppBundle\Entity\User
type: entity
repositoryClass: xxx # you can ignore this setting
If entity has no repository class, it will auto use Knd\Bundle\RadBundle\Repository\EntityRepository
You can ignore auto feature by config:
//config.yml
knd_rad:
auto_inject:
entity:
repository:
auto: false
Manager services for entity classes, the manager classes should extend Knd\Bundle\RadBundle\Manager\Manager
Default manager class directory is Manager
:
AppBundle\Manager\UserManager
=> app.class.manager.user #class container parameter
=> app.manager.user #service id
If entity has no manager class, it will auto use Knd\Bundle\RadBundle\Manager\Manager
.
You can ignore auto feature by config:
//config.yml
knd_rad:
auto_inject:
entity:
manager:
auto: false
Model class voter services, default directory is Security/Voter
,
Voter classes should extend Knd\Bundl\RadBundle\Security\Voter\AbstractVoter
AppBundle\Security\Voter\UserVoter
=> app.class.security.voter_user_voter
=> app.security.voter.user # the service is private, you can not access it from container
##Configuation##
knd_rad:
auto_inject:
entity:
dirs: [Entity]
classes: []
exclude_classes: []
repository:
auto: true
dir: Repository
manager:
auto: true
dir: Manager
voter:
auto: true
dir: Security/Voter
common:
dirs: [Form]
classes: []
exclude_classes: []