定制 cobaia/cobaia-annotation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cobaia/cobaia-annotation

Composer 安装命令:

composer require cobaia/cobaia-annotation

包简介

CakePHP Plugin with a collection of Annotations to use

README 文档

README

Annotations in CakePHP.

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

{
    "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

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

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.

So for example, using param coverter: call: /contents/view/20

It would be the same as

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

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

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

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.

Author

Vinícius Krolow - krolow[at]gmail.com

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-21