Add support libs folder into app and plugins that will allow to split users and vendors code. Libs files should follow cake naming conventions for files names and classes.

This commit is contained in:
SkieDr 2009-10-21 14:59:12 +04:00
parent fa6b1b1a20
commit fb64d14442
4 changed files with 55 additions and 3 deletions

View file

@ -71,6 +71,11 @@ if (!defined('APP')) {
*/
define('COMPONENTS', CONTROLLERS.'components'.DS);
/**
* Path to the application's views directory.
*/
define('APPLIBS', APP.'libs'.DS);
/**
* Path to the application's views directory.
*/

View file

@ -364,7 +364,7 @@ class Configure extends Object {
* @access private
*/
function __loadBootstrap($boot) {
$modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = $localePaths = $shellPaths = null;
$libPaths = $modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = $localePaths = $shellPaths = null;
if ($boot) {
Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR));
@ -418,7 +418,7 @@ class Configure extends Object {
'models' => $modelPaths, 'views' => $viewPaths, 'controllers' => $controllerPaths,
'helpers' => $helperPaths, 'components' => $componentPaths, 'behaviors' => $behaviorPaths,
'plugins' => $pluginPaths, 'vendors' => $vendorPaths, 'locales' => $localePaths,
'shells' => $shellPaths
'shells' => $shellPaths, 'libs' => $libPaths
));
}
}
@ -448,6 +448,7 @@ class App extends Object {
'behavior' => array('suffix' => '.php', 'extends' => 'ModelBehavior', 'core' => true),
'controller' => array('suffix' => '_controller.php', 'extends' => 'AppController', 'core' => true),
'component' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'lib' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'view' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'helper' => array('suffix' => '.php', 'extends' => 'AppHelper', 'core' => true),
'vendor' => array('suffix' => '', 'extends' => null, 'core' => true),
@ -487,6 +488,13 @@ class App extends Object {
*/
var $components = array();
/**
* List of additional path(s) where libs files reside.
*
* @var array
* @access public
*/
var $libs = array();
/**
* List of additional path(s) where view files reside.
*
@ -626,6 +634,7 @@ class App extends Object {
'datasources' => array(MODELS . 'datasources'),
'controllers' => array(CONTROLLERS),
'components' => array(COMPONENTS),
'libs' => array(APPLIBS),
'views' => array(VIEWS),
'helpers' => array(HELPERS),
'locales' => array(APP . 'locale' . DS),
@ -879,7 +888,6 @@ class App extends Object {
$file = Inflector::underscore($name) . ".{$ext}";
}
$ext = $_this->__settings($type, $plugin, $parent);
if ($name != null && !class_exists($name . $ext['class'])) {
if ($load = $_this->__mapped($name . $ext['class'], $type, $plugin)) {
if ($_this->__load($load)) {
@ -1138,6 +1146,12 @@ class App extends Object {
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'lib':
if ($plugin) {
$path = $pluginPath . DS . 'libs' . DS;
}
return array('class' => null, 'suffix' => null, 'path' => $path);
break;
case 'view':
if ($plugin) {
$path = $pluginPath . DS . 'views' . DS;

View file

@ -502,6 +502,10 @@ class AppImportTest extends UnitTestCase {
$this->assertTrue(class_exists('TestPluginAppController'));
$this->assertTrue(class_exists('TestsController'));
$result = App::import('Lib', 'TestPlugin.TestPluginLibrary');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestPluginLibrary'));
$result = App::import('Helper', 'TestPlugin.OtherHelper');
$this->assertTrue($result);
$this->assertTrue(class_exists('OtherHelperHelper'));

View file

@ -0,0 +1,29 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test Suite TestPlugin Library
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.5432
* @version $Rev$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
class TestPluginLibrary {}
?>