2017 © Pedro PelĂĄez
 

cakephp-plugin cobaia-annotation

CakePHP Plugin with a collection of Annotations to use

image

cobaia/cobaia-annotation

CakePHP Plugin with a collection of Annotations to use

  • Monday, February 4, 2013
  • by krolow
  • Repository
  • 0 Watchers
  • 3 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 4 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

CobaiaAnnotation

Annotations in CakePHP., (*1)

Why?

  • Because Annotations are cool!
  • Because We like (or at least I like)
  • Because no make sense repeate over and over the same code in PHP
  • Use PHP array to configure is sux
  • Metadata and Metaprogramming are cool!

Installing

CobaiaAnnotations make usage of composer, so download composer and create your app/composer.json, (*2)

{
    "name": "testing",
    "require": {
        "php": ">=5.3.0",
        "cakephp/debug_kit" : "*",
        "cobaia/cobaia-annotation": "dev-master"
    },
    "minimum-stability": "dev"
}

It's time to running composer.phar install, (*3)

After install it's time to load the plugin, open app/Config/bootstrap.php, (*4)

CakePlugin::load('CobaiaAnnotation', array('bootstrap' => true));

//register filter
Configure::write('Dispatcher.filters', array(
    'AssetDispatcher',
    'CacheDispatcher',
    'CobaiaAnnotation.AnnotationDispatcher'
));

What annotations do we have in CobaiaAnnotation?

@ParamConverter

<?php
App::uses('AppController', 'Controller');

use CobaiaAnnotation\Configuration\Controller\ParamConverter;

class ContentsController extends AppController {


    /**
     * @ParamConverter("content", class="Content")
     */
    public function view($content = 1) {
        var_dump($content);
    }

}

ParamConverter will automatically converts the action paramter to data that is in the database., (*5)

So for example, using param coverter: call: /contents/view/20, (*6)

It would be the same as, (*7)

$content = $this->Content->read(null, $content);

@ViewHandler

<?php
App::uses('AppController', 'Controller');

use CobaiaAnnotation\Configuration\Controller\ViewHandler;

/**
 * @ViewHandler(layout="ajax")
 */
class ContentsController extends AppController {

    /**
     * @ViewHandler(view="show")
     */
    public function view() {
    }

    /**
     * @ViewHandler(layout="default")
     */
    public function index() {

    }

}

ViewHandler will take care of your view, forget about $this->layout, $this->render(), just define in the annotation what layout you want to use and also what view, and that's it., (*8)

It makes also inheritance so if you define one layout or view in the class DocBlock, the actions will inherit the value., (*9)

@ModelLoader, @ComponentLoader, @HelperLoader

<?php
App::uses('AppController', 'Controller');

use CobaiaAnnotation\Configuration\Controller\Loader\ModelLoader;
use CobaiaAnnotation\Configuration\Controller\Loader\ComponentLoader;
use CobaiaAnnotation\Configuration\Controller\Loader\HelperLoader;

/**
 * @ModelLoader({"Content", "Fake"})
 * @ComponentLoader({"Session", "RequestHandler"})
 * @HelperLoader({"Text", "Time", "Number"})
 */
class ContentsController extends AppController {


    public function view($content = 1) {
    }

}

@Model, @Component, @Helper will handle to you the load of models, components and helpers, not needed anymore put the attribute of class in your code., (*10)

What next?

  • @Route (adding custom routes in your controller)
  • @Auth (allow, deny)
  • @Route (adding custom routes in your controller)
  • @Auth (allow, deny)
  • @Table
  • @HasMany
  • @HasAndBelongsToMany
  • @BelongsTo
  • @Behaviors
  • Check performance with 2 autoloads
  • Cache annotations parsed
  • Add Unit Tests

License

Licensed under The MIT License Redistributions of files must retain the above copyright notice., (*11)

Author

VinĂ­cius Krolow - krolow[at]gmail.com, (*12)

The Versions

04/02 2013

dev-master

9999999-dev https://github.com/krolow/CobaiaAnnotation

CakePHP Plugin with a collection of Annotations to use

  Sources   Download

MIT

The Requires

 

cakephp meta annotation