knplabs/rad-prototype

This package is abandoned and no longer maintained. No replacement package was suggested.

Pierre PLAZANET <pierre@knplabs.com>

Maintainers

👁 KnpLabs

Package info

github.com/KnpLabs/rad-prototype

pkg:composer/knplabs/rad-prototype

Statistics

Installs: 4 235

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 1

v2.1.0 2017-09-21 08:23 UTC

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 14b79cfa7d9da71a84a072bd4de631c0da5fc818

  • Pierre PLAZANET <pierre.woop@knplabs.com>

This package is auto-updated.

Last update: 2022-09-23 13:36:32 UTC


README

Unfortunately we decided to not maintain this project anymore (see why). If you want to mark another package as a replacement for this one please send an email to hello@knplabs.com.

Rapid Application Development : Prototype

Automatically inject methods into objects

👁 Build Status
👁 Scrutinizer Code Quality
👁 Latest Stable Version
👁 Total Downloads
👁 Latest Unstable Version
👁 License

Installation

composer require knplabs/rad-prototype ~2.0
class AppKernel
{
 function registerBundles()
 {
 $bundles = array(
 //...
 new Knp\Rad\Prototype\Bundle\PrototypeBundle(),
 //...
 );

 //...

 return $bundles;
 }
}

Usages

1. Method side

You can create injectable methods via dependency injections. You can apply the tag knp_rad_prototype.prototype_method. For example, if I want to expose the method getRepository form the @doctrine service, I just have to declare a new method:

knp_rad_prototype.prototype.method.doctrine.get_repository:
 class: Knp\Rad\Prototype\Prototype\Method
 arguments:
 - @doctrine
 - getRepository
 tags:
 - { name: knp_rad_prototype.prototype_method, alias: getRepository, domain: doctrine }

The first argument should be a service or a classname (for static methods), the second argument should be a method name. In this case, the method will be @doctrine->getRepository().

The alias tag option represent the method name inside the prototype, so in this case, I can call the method with $this->getRepository(). Finaly, the domain tag option represent the domain of this method, a prototype can recieve method of some domains.

2. Prototype side

2.1. Attach methods to a controller

Access to methods from a controller

Your controller should implements the Knp\Rad\Prototype\Prototype. You can also use the basic implementation via the trait Knp\Rad\Prototype\Prototype\Controller

namespace AppBundle\Controller;

use Knp\Rad\Prototype\Prototype;

class ProductController implements Prototype
{
 use Prototype\Controller;

 public function testAction($id) 
 {
 $product = $this->getRepository('AppBundle:Product')->find($id);

 $this->persist($product);
 $this->flush();

 // ...
 }
}

3. Web Debug Toolbar

When your controller implements the Knp\Rad\Prototype\Prototype interface, the following icon will appear into the Symfony web debug toobar.

👁 wdt.png

And you can also access to every accessable methods from your prototypes from the Symfony profiler interface

👁 profiler.png