Improving App::import() to make importing from plugins work again

This commit is contained in:
Jose Lorenzo Rodriguez 2011-03-11 01:31:01 -04:30
parent 3f7a7cc5d1
commit 0bf51d92ca
2 changed files with 16 additions and 4 deletions

View file

@ -145,7 +145,8 @@ class App {
'components' => 'Controller/Component', 'components' => 'Controller/Component',
'views' => 'View', 'views' => 'View',
'helpers' => 'View/Helper', 'helpers' => 'View/Helper',
'shells' => 'Console/Command' 'shells' => 'Console/Command',
'libs' => 'Lib'
); );
/** /**
@ -228,7 +229,7 @@ class App {
'%s' . 'vendors' . DS . 'shells' . DS . 'tasks' . DS, '%s' . 'vendors' . DS . 'shells' . DS . 'tasks' . DS,
VENDORS . 'shells' . DS . 'tasks' . DS VENDORS . 'shells' . DS . 'tasks' . DS
), ),
'libs' => array('%s' . 'libs' . DS), 'Lib' => array('%s' . 'libs' . DS),
'locales' => array('%s' . 'locale' . DS), 'locales' => array('%s' . 'locale' . DS),
'vendors' => array('%s' . 'vendors' . DS, VENDORS), 'vendors' => array('%s' . 'vendors' . DS, VENDORS),
'plugins' => array(APP . 'plugins' . DS, CAKE_CORE_INCLUDE_PATH . DS . 'plugins' . DS) 'plugins' => array(APP . 'plugins' . DS, CAKE_CORE_INCLUDE_PATH . DS . 'plugins' . DS)
@ -262,8 +263,8 @@ class App {
} }
} }
$mergeExclude = array('libs', 'locales', 'vendors', 'plugins'); $mergeExclude = array('Lib', 'locales', 'vendors', 'plugins');
$appLibs = empty($paths['libs']) ? $defaults['libs'] : $paths['libs']; $appLibs = empty($paths['Lib']) ? $defaults['Lib'] : $paths['Lib'];
foreach ($defaults as $type => $default) { foreach ($defaults as $type => $default) {
if (empty(self::$__packages[$type]) || empty($paths)) { if (empty(self::$__packages[$type]) || empty($paths)) {
@ -553,6 +554,15 @@ class App {
$name .= ($suffix == $name) ? '' : $suffix; $name .= ($suffix == $name) ? '' : $suffix;
} }
if (isset(self::$types[$originalType]['extends'])) {
$extends = self::$types[$originalType]['extends'];
App::uses($extends, $type);
if ($plugin && in_array($originalType, array('controller', 'model'))) {
$pluginName = substr($plugin, 0 , -1);
App::uses($pluginName . $extends, $plugin . $type);
}
}
App::uses(Inflector::camelize($name), $plugin . $type); App::uses(Inflector::camelize($name), $plugin . $type);
return (bool) self::load($name); return (bool) self::load($name);
} }

View file

@ -1,4 +1,6 @@
<?php <?php
App::uses('DataSource', 'Model/Datasource');
class TestSource extends DataSource { class TestSource extends DataSource {
function describe($model) { function describe($model) {