Skip to content

Commit

Permalink
Improving App::import() to make importing from plugins work again
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 11, 2011
1 parent 3f7a7cc commit 0bf51d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/Cake/Core/App.php
Expand Up @@ -145,7 +145,8 @@ class App {
'components' => 'Controller/Component',
'views' => 'View',
'helpers' => 'View/Helper',
'shells' => 'Console/Command'
'shells' => 'Console/Command',
'libs' => 'Lib'
);

/**
Expand Down Expand Up @@ -228,7 +229,7 @@ public static function build($paths = array(), $reset = false) {
'%s' . 'vendors' . DS . 'shells' . DS . 'tasks' . DS,
VENDORS . 'shells' . DS . 'tasks' . DS
),
'libs' => array('%s' . 'libs' . DS),
'Lib' => array('%s' . 'libs' . DS),
'locales' => array('%s' . 'locale' . DS),
'vendors' => array('%s' . 'vendors' . DS, VENDORS),
'plugins' => array(APP . 'plugins' . DS, CAKE_CORE_INCLUDE_PATH . DS . 'plugins' . DS)
Expand Down Expand Up @@ -262,8 +263,8 @@ public static function build($paths = array(), $reset = false) {
}
}

$mergeExclude = array('libs', 'locales', 'vendors', 'plugins');
$appLibs = empty($paths['libs']) ? $defaults['libs'] : $paths['libs'];
$mergeExclude = array('Lib', 'locales', 'vendors', 'plugins');
$appLibs = empty($paths['Lib']) ? $defaults['Lib'] : $paths['Lib'];

foreach ($defaults as $type => $default) {
if (empty(self::$__packages[$type]) || empty($paths)) {
Expand Down Expand Up @@ -553,6 +554,15 @@ public static function import($type = null, $name = null, $parent = true, $searc
$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);
return (bool) self::load($name);
}
Expand Down
@@ -1,4 +1,6 @@
<?php
App::uses('DataSource', 'Model/Datasource');

class TestSource extends DataSource {

function describe($model) {
Expand Down

0 comments on commit 0bf51d9

Please sign in to comment.