CakePHP 框架的工具

euromark 10c8d959f2 Adjust namespace 11 years ago
src 10c8d959f2 Adjust namespace 11 years ago
tests 10c8d959f2 Adjust namespace 11 years ago
.coveralls.yml 7a03eaee62 another test 11 years ago
.scrutinizer.yml 987acd04dd update bootstrap 11 years ago
.travis.yml 7ef65eb97c spaces 11 years ago
README.md 10c8d959f2 Adjust namespace 11 years ago
composer.json 10c8d959f2 Adjust namespace 11 years ago
phpunit.xml.dist 1557bda74c phpunit.xml.dist 11 years ago

README.md

CakePHP Tools Plugin

A CakePHP 3.x Plugin containing several useful tools that can be used in many projects.

Version notice

This cake3 branch only works for cake3 - please use the master branch for CakePHP 2.x!

How to include

Installing the Plugin is pretty much as with every other CakePHP Plugin.

Put the files in APP/Plugin/Tools, using packagist/composer:

"require": {
	"dereuromark/tools-cakephp": "dev-cake3"
}

and

composer update

Details @ https://packagist.org/packages/dereuromark/tools-cakephp

That's it. It should be up and running.

The basics

In case you want the Tools bootstrap file included (recommended), you can do that in your APP/Config/bootstrap.php with

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

For CakePlugin::loadAll() it's

CakePlugin::loadAll(array(
		'Tools' => array('bootstrap' => true
));

Namespacing

Using Cake3 and namespaces, don't forget to add "Dereuromark\Tools" as namespace to new files. Also don't forget the use statements.

So for a new behavior "MySlugged" that extends "Slugged" it is:

namespace App\Model\Behavior;

use Dereuromark\Tools\Model\Behavior\SluggedBehavior;

class MySluggedBehavior extends SluggedBehavior {
}

Note that use statements should be in alphabetical order. See CakePHP coding standards for details.

Shortened namespacing

As long as you don't have a "Tools" namespace already in use and if you want to save yourself some namespace typing, you can configure it the way that it does not need the the vendor name:

CakePlugin::load('Tools', array('namespace' => 'Dereuromark\\Tools'));

For CakePlugin::loadAll() it's

CakePlugin::loadAll(array(
		'Tools' => array('namespace' => 'Dereuromark\\Tools'
));

Personally, this is my default configuration for all plugins.

So for a new behavior "MySlugged" that extends "Slugged" it is now:

namespace App\Model\Behavior;

use Tools\Model\Behavior\SluggedBehavior;

class MySluggedBehavior extends SluggedBehavior {
}

Testing

You can test using a local installation of phpunit or the phar version of it:

cd Plugin/Tools
phpunit --stderr

To test a specific file:

phpunit --stderr /path/to/class.php

License

Licensed under The MIT License unless specified otherwise (in the classes).

TODOs

  • Move more 2.x stuff to 3.x