function buildAcl() { $log = array(); $aco = $this->MyAcl->Myaco; $aco->recursive = 0; $root = $aco->find(array('alias' => '/everything')); if (!$root) { $aco->create(array('parent_id' => null, 'model' => null, 'alias' => '/everything')); $root = $aco->save(); $root['id'] = $aco->id; $log[] = 'Created Aco node for /everything'; } else { $root = $root['Myaco']; } App::import('Core', 'File'); $Controllers = Configure::listObjects('controller'); $appIndex = array_search('App', $Controllers); if ($appIndex !== false) { unset($Controllers[$appIndex]); } $baseMethods = get_class_methods('Controller'); $baseMethods[] = 'buildAcl'; // look at each controller in app/controllers foreach ($Controllers as $ctrlName) { App::import('Controller', $ctrlName); $ctrlclass = $ctrlName . 'Controller'; $methods = get_class_methods($ctrlclass); // find / make controller node $controllerNode = $aco->find(array('alias' => '/everything/' . $ctrlName)); if (!$controllerNode) { $aco->create(array('parent_id' => $root['id'], 'alias' => "/everything/{$ctrlName}")); $controllerNode = $aco->save(); $controllerNode['id'] = $aco->id; $log[] = "Created Aco node for /everything/{$ctrlName}"; } else { $controllerNode = $controllerNode['Myaco']; } //clean the methods. to remove those in Controller and private actions. foreach ($methods as $k => $method) { if (strpos($method, '_', 0) === 0) { unset($methods[$k]); continue; } if (in_array($method, $baseMethods)) { unset($methods[$k]); continue; } } foreach ($methods as $method) { $methodNode = $aco->find(array('alias' => '/everything/' . $ctrlName . '/' . $method)); if (!$methodNode) { $aco->create(array('parent_id' => $controllerNode['id'], 'alias' => "/everything/{$ctrlName}/{$method}")); $methodNode = $aco->save(); $log[] = "Created Aco node for /everything/{$ctrlName}/{$method}"; } } } $this->set('log', $log); }
public function shouldNotMatchController($field) { $controllers = Configure::listObjects('controller'); if (in_array(current($field), $controllers)) { return current($field) . ' is an illegal username'; } return true; }
function startup() { $appPaths = array_diff(Configure::read('modelPaths'), Configure::corePaths('model')); $this->models = Configure::listObjects('model', $appPaths, false); if (empty($this->params['src'])) { $this->params['src'] = ROOT . DS . 'src'; } }
function buildAcl() { $log = array(); $aco =& $this->Acl->Aco; $root = $aco->node('controllers'); if (!$root) { $aco->create(array('parent_id' => null, 'model' => null, 'alias' => 'controllers')); $root = $aco->save(); $root['Aco']['id'] = $aco->id; $log[] = 'Created Aco node for controllers'; } else { $root = $root[0]; } App::import('Core', 'File'); $Controllers = Configure::listObjects('controller'); $appIndex = array_search('App', $Controllers); if ($appIndex !== false) { unset($Controllers[$appIndex]); } $baseMethods = get_class_methods('Controller'); $baseMethods[] = 'buildAcl'; // look at each controller in app/controllers foreach ($Controllers as $ctrlName) { App::import('Controller', $ctrlName); $ctrlclass = $ctrlName . 'Controller'; $methods = get_class_methods($ctrlclass); // find / make controller node $controllerNode = $aco->node('controllers/' . $ctrlName); if (!$controllerNode) { $aco->create(array('parent_id' => $root['Aco']['id'], 'model' => null, 'alias' => $ctrlName)); $controllerNode = $aco->save(); $controllerNode['Aco']['id'] = $aco->id; $log[] = 'Created Aco node for ' . $ctrlName; } else { $controllerNode = $controllerNode[0]; } // clean the methods. to remove those in Controller and private actions. foreach ($methods as $k => $method) { if (strpos($method, '_', 0) === 0) { unset($methods[$k]); continue; } if (in_array($method, $baseMethods)) { unset($methods[$k]); continue; } $methodNode = $aco->node('controllers/' . $ctrlName . '/' . $method); if (!$methodNode) { $aco->create(array('parent_id' => $controllerNode['Aco']['id'], 'model' => null, 'alias' => $method)); $methodNode = $aco->save(); $log[] = 'Created Aco node for ' . $method; } } } debug($log); $this->Session->setFlash('Database succesfully initialised'); $this->redirect(array('controller' => '/')); }
function testGetPlugins() { $_allPlugins = Configure::listObjects('plugin'); $allPlugins = array() + array('' => 'None'); foreach ($_allPlugins as $k => $v) { $allPlugins[Inflector::underscore($v)] = $v; } // need to see how to do this //$this->assertEqual(count($this->Infinitas->getPlugins($this->AppModel, true)), count($allPlugins)); }
function getDBDrivers() { $drivers = array(); $dbo_path = APP . LIBS . "model" . DS . "datasources" . DS . "dbo"; $files = Configure::listObjects('file', $dbo_path, false); foreach ($files as $fname) { $name = substr(substr($fname, strpos($fname, "_") + 1), 0, -4); $drivers[$name] = $name; } return $drivers; }
function _getControllers() { $controllerList = Configure::listObjects('controller'); $controllers = array(); foreach ($controllerList as $controller) { if ($controller == 'App') { continue; } $controllers[$controller] = $this->_getControllerMethods($controller); } return $controllers; }
function __getClass($className) { $this->type = null; $classType = false; $className = $this->__fixClassName($className); if ($this->type) { $types = array($this->type); } else { $types = array('model', 'helper'); } $class = $className; if (strpos($className, '.') !== false) { list($plugin, $className) = explode('.', $className); $this->objectPath = App::pluginPath($plugin); } foreach ($types as $type) { $objects = Configure::listObjects($type, $this->objectPath ? $this->objectPath . Inflector::pluralize($type) . DS : null, $this->objectCache); if (in_array($className, $objects)) { $classType = $type; break; } } switch ($classType) { case 'model': return ClassRegistry::init($class); case 'controller': App::import('Controller', $class); $className = $className . 'Controller'; return new $className(); case 'component': App::import('Controller', 'Controller'); $Controller = new Controller(); $Controller->params['action'] = ''; App::import('Component', $class); $className = $className . 'Component'; $Class = new $className(); $Class->initialize($Controller); $Class->startup($Controller); return $Class; case 'helper': $this->raw = true; App::import('Controller', 'Controller'); $Controller = new Controller(); $Controller->helpers[] = $class; App::import('View', 'View'); $View =& new View($Controller); $loaded = array(); $helpers = $View->_loadHelpers($loaded, $Controller->helpers); return $helpers[$className]; } return false; }
/** * beforeRender * * Application hook which runs after each action but, before the view file is * rendered * * @access public */ function beforeRender() { //If we have an authorised user logged then pass over an array of controllers //to which they have index action permission if ($this->Auth->user()) { $controllerList = Configure::listObjects('controller'); $permittedControllers = array(); foreach ($controllerList as $controllerItem) { if ($controllerItem != 'App') { if ($this->__permitted($controllerItem, 'index')) { $permittedControllers[] = $controllerItem; } } } } $this->set(compact('permittedControllers')); }
/** * Override intialize of the Shell * * @access public */ function initialize() { require_once CAKE . 'dispatcher.php'; $this->Dispatcher = new Dispatcher(); $this->models = Configure::listObjects('model'); App::import('Model', $this->models); foreach ($this->models as $model) { $class = Inflector::camelize(r('.php', '', $model)); $this->models[$model] = $class; $this->{$class} =& new $class(); } $this->out('Model classes:'); $this->out('--------------'); foreach ($this->models as $model) { $this->out(" - {$model}"); } }
/** * afterFind method * * @param mixed $Model * @param mixed $results * @param bool $primary * @access public * @return void */ function afterFind(&$Model, $results, $primary = false) { extract($this->settings[$Model->alias]); if (App::import('Vendor', 'Mi.MiCache')) { $models = MiCache::mi('models'); } else { $models = Configure::listObjects('model'); } if ($primary && isset($results[0][$Model->alias][$modelField]) && isset($results[0][$Model->alias][$foreignKey]) && $Model->recursive > 0) { foreach ($results as $key => $result) { $associated = array(); $model = Inflector::classify($result[$Model->alias][$modelField]); $foreignId = $result[$Model->alias][$foreignKey]; if ($model && $foreignId && in_array($model, $models)) { $result = $result[$Model->alias]; if (!isset($Model->{$model})) { $Model->bindModel(array('belongsTo' => array($model => array('conditions' => array($Model->alias . '.' . $modelField => $model), 'foreignKey' => $foreignKey)))); } $conditions = array($model . '.' . $Model->{$model}->primaryKey => $result[$foreignKey]); $recursive = -1; $associated = $Model->{$model}->find('first', compact('conditions', 'recursive')); $name = $Model->{$model}->display($result[$foreignKey]); $associated[$model]['display_field'] = $name ? $name : '*missing*'; $results[$key][$model] = $associated[$model]; } } } elseif (isset($results[$Model->alias][$modelField])) { $associated = array(); $model = Inflector::classify($result[$Model->alias][$modelField]); $foreignId = $results[$Model->alias][$foreignKey]; if ($model && $foreignId) { $result = $results[$Model->alias]; if (!isset($Model->{$model})) { $Model->bindModel(array('belongsTo' => array($model => array('conditions' => array($Model->alias . '.' . $modelField => $model), 'foreignKey' => $foreignKey)))); } $conditions = array($model . '.' . $Model->{$model}->primaryKey => $result[$foreignKey]); $recursive = -1; $associated = $Model->{$model}->find('first', compact('conditions', 'recursive')); $name = $Model->{$model}->display($result[$foreignKey]); $associated[$model]['display_field'] = $name ? $name : '*missing*'; $results[$model] = $associated[$model]; } } return $results; }
function setPrivileges() { // get controllers $controllers = Configure::listObjects('controller'); $this->filter['methods'] = get_class_methods('Controller'); $this->filter['controller'] = array('App', 'Pages'); $list = array(); foreach ($controllers as $c) { if (in_array($c, $this->filter['controller'])) { continue; } if (!App::import('Controller', $c)) { foreach ($plugins as $p) { if (strpos($p, $c) === 0 && App::import('Controller', $p . '.' . $c)) { break; } } } // get controller methods $list[$c] = $this->_getMethods($c . 'Controller', 'methods'); } $i = ''; foreach ($list as $key => $value) { foreach ($value as $k => $v) { $methods[$i] = array('controller' => $key, 'action' => $v); $i++; } } $groups = ClassRegistry::init('Group')->find('list', array('fields' => array('Group.id', 'Group.name'), 'recursive' => -1)); $i = 0; foreach ($groups as $k => $v) { foreach ($methods as $key => $value) { $method[$i] = array('id' => $i, 'group_id' => $k, 'controller' => $value['controller'], 'action' => $value['action']); $i++; } } $this->Privilege = ClassRegistry::init('Privilege'); foreach ($method as $key => $value) { $this->Privilege->create(); $this->Privilege->save($value); } }
/** * Start up And load Acl Component / Aco model * * @return void **/ function startup() { $this->Acl =& new AclComponent(); $controller = null; $this->Acl->startup($controller); $this->Aro =& $this->Acl->Aro; $plugins = Configure::listObjects('plugin'); $plugins[] = 'App'; // include the non-plugin task if it exists foreach ($plugins as $plugin) { foreach ($this->Dispatch->shellPaths as $path) { $taskPath = $path . 'tasks' . DS . Inflector::underscore($plugin) . '_permissions.php'; if (file_exists($taskPath)) { $this->tasks[] = $plugin . 'Permissions'; break; } } } $this->loadTasks(); }
function admin_index() { $this->UserGroup->recursive = 0; $data = $this->UserGroup->findAll(); $Controllers = Configure::listObjects('controller'); $controllerList = $this->ControllerList->get(); // we loop on all action for all roles foreach ($controllerList as $controller => $actions) { foreach ($actions as $key => $action) { $controllerList[$controller][$action] = array(); unset($controllerList[$controller][$key]); foreach ($data as $p) { $controllerList[$controller][$action][$p['UserGroup']['id']] = $this->Acl->check($p, $controller . '/' . $action, '*'); } } } //debug($controllerList); $this->set('ctlist', $controllerList); $this->set('data', $data); }
function get() { $controllerClasses = Configure::listObjects('controller'); foreach ($controllerClasses as $controller) { if ($controller != 'App') { $filenName = strtolower($controller) . '_controller.php'; $file = CONTROLLERS . $fileName; require_once $file; $className = $controller . 'Controller'; $action = get_class_methods($className); foreach ($actions as $k => $v) { if ($v[0] == '_') { unset($actions[$k]); } } $parentActions = get_class_methods('AppController'); $controllers[$controller] = array_diff($actions, $parentActions); } } return $controllers; }
/** * gets all available actions in controller. * * @param array $reserved reserved action (for example, that already inserted to databse) * @return array An array of action in key=>value format (suitable for listbox, checkbox, etc) * @access public * @static */ function listActions($reserved = array()) { $menu = array(); $reservedPath = array(); foreach ($reserved as $res) { $reservedPath[] = $res['Link']['controller'] . '/' . $res['Link']['action']; } $controllers = Configure::listObjects('controller'); $controllers = array_diff($controllers, array('App', 'Pages')); $baseMethods = get_class_methods('Controller'); // look at each controller in app/controllers foreach ($controllers as $ctrlName) { App::import('Controller', $ctrlName); $ctrlclass = $ctrlName . 'Controller'; $methods = get_class_methods($ctrlclass); //clean the methods. to remove those in Controller and private actions. foreach ($methods as $k => $method) { $path = Inflector::underscore($ctrlName) . '/' . $method; if (strpos($method, '_', 0) === 0) { unset($methods[$k]); continue; } if (in_array($method, $baseMethods)) { unset($methods[$k]); continue; } if (in_array($path, $reservedPath)) { unset($methods[$k]); continue; } $menu[$path] = $path; } } ksort($menu); return $menu; }
/** * Returns all common paths where media files are stored * * @access protected * @return array */ function _paths() { $plugins = array_map('Inflector::underscore', Configure::listObjects('plugin')); foreach ($plugins as $plugin) { foreach (App::path('plugins') as $pluginPath) { if (is_dir($pluginPath . $plugin)) { $pluginVendorPaths[] = $pluginPath . $plugin . DS . 'vendors' . DS; } } } $paths = array_merge(App::path('vendors'), array(WWW_ROOT), $pluginVendorPaths); foreach ($paths as $key => $path) { $message = sprintf('Would you like to collect files from %s?', $this->shortPath($path)); if ($this->in($message, 'y,n', 'y') == 'n') { unset($paths[$key]); } } $answer = 'y'; while ($answer == 'y') { if ($answer = $this->in('Would you like to add another path?', 'y,n', 'n') == 'y') { $path = $this->in('Path:'); if (!is_dir($path)) { $this->out('Directory does not exist!'); } else { $paths[] = $path; } } } return $paths; }
/** * Provides the left hand navigation for the testsuite * * @return void * @access public */ function CakePHPTestSuiteHeader() { switch (CAKE_TEST_OUTPUT) { case CAKE_TEST_OUTPUT_HTML: ob_start(); $groups = $_SERVER['PHP_SELF'] . '?show=groups'; $cases = $_SERVER['PHP_SELF'] . '?show=cases'; $plugins = Configure::listObjects('plugin'); include CAKE_TESTS_LIB . 'content.php'; break; } }
/** * Binds the given domain to a file in the specified directory. * * @param string $domain Domain to bind * @return string Domain binded * @access private */ function __bindTextDomain($domain) { $_this =& I18n::getInstance(); $_this->__noLocale = true; $core = true; $merge = array(); $searchPath[] = APP . 'locale'; $plugins = Configure::listObjects('plugin'); if (!empty($plugins)) { } foreach ($searchPath as $directory) { foreach ($_this->l10n->languagePath as $lang) { $file = $directory . DS . $lang . DS . $_this->category . DS . $domain; if ($core) { $app = $directory . DS . $lang . DS . $_this->category . DS . 'core'; if (file_exists($fn = "{$app}.mo")) { $_this->__loadMo($fn, $domain); $_this->__noLocale = false; $merge = $_this->__domains; $core = null; } elseif (file_exists($fn = "{$app}.po") && ($f = fopen($fn, "r"))) { $_this->__loadPo($f, $domain); $_this->__noLocale = false; $merge = $_this->__domains; $core = null; } } if (file_exists($fn = "{$file}.mo")) { $_this->__loadMo($fn, $domain); $_this->__noLocale = false; break 2; } elseif (file_exists($fn = "{$file}.po") && ($f = fopen($fn, "r"))) { $_this->__loadPo($f, $domain); $_this->__noLocale = false; break 2; } } } if (empty($_this->__domains[$_this->category][$domain])) { $_this->__domains[$_this->category][$domain] = array(); return $domain; } if ($head = $_this->__domains[$_this->category][$domain][""]) { foreach (explode("\n", $head) as $line) { $header = strtok($line, ":"); $line = trim(strtok("\n")); $_this->__domains[$_this->category][$domain]["%po-header"][strtolower($header)] = $line; } if (isset($_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"])) { $switch = preg_replace("/[() {}\\[\\]^\\s*\\]]+/", "", $_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"]); $_this->__domains[$_this->category][$domain]["%plural-c"] = $switch; } $_this->__domains = Set::pushDiff($_this->__domains, $merge); if (isset($_this->__domains[$_this->category][$domain][null])) { unset($_this->__domains[$_this->category][$domain][null]); } } return $domain; }
/** * Connects the default, built-in routes, including admin routes, and (deprecated) web services * routes. * * @return void * @access private */ function __connectDefaultRoutes() { if ($this->__defaultsMapped) { return; } if ($this->__admin) { $params = array('prefix' => $this->__admin, $this->__admin => true); } if ($plugins = Configure::listObjects('plugin')) { foreach ($plugins as $key => $value) { $plugins[$key] = Inflector::underscore($value); } $match = array('plugin' => implode('|', $plugins)); $this->connect('/:plugin/:controller/:action/*', array(), $match); if ($this->__admin) { $this->connect("/{$this->__admin}/:plugin/:controller", $params, $match); $this->connect("/{$this->__admin}/:plugin/:controller/:action/*", $params, $match); } } if ($this->__admin) { $this->connect("/{$this->__admin}/:controller", $params); $this->connect("/{$this->__admin}/:controller/:action/*", $params); } $this->connect('/:controller', array('action' => 'index')); $this->connect('/:controller/:action/*'); if ($this->named['rules'] === false) { $this->connectNamed(true); } $this->__defaultsMapped = true; }
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @package cake * @subpackage cake.app.config * @since CakePHP(tm) v 0.2.9 * @version $Revision: 7945 $ * @modifiedby $LastChangedBy: gwoo $ * @lastmodified $Date: 2008-12-19 13:16:01 +1100 (Fri, 19 Dec 2008) $ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ Router::parseExtensions('rss', 'json'); /** * Here, we are connecting '/' (base path) to controller called 'Pages', * its action called 'display', and we pass a param to select the view file * to use (in this case, /app/views/pages/home.ctp)... */ Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); /** * ...and connect the rest of 'Pages' controller's urls. */ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); Router::connect('/p/:slug-:id', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id'), 'id' => $UUID)); $controllers = array_map(array('Inflector', 'underscore'), Configure::listObjects('controller')); Router::connect('/:controller', array(), array('controller' => join('|', $controllers))); Router::connect('/:username', array('controller' => 'users', 'action' => 'view'), array('pass', array('username')));
/** * Reads database and creates schema tables * * Options * * - 'connection' - the db connection to use * - 'name' - name of the schema * - 'models' - a list of models to use, or false to ignore models * @param array $options schema object properties * @return array Array indexed by name and tables * @access public */ function read($options = array()) { extract(array_merge(array('connection' => $this->connection, 'name' => $this->name, 'models' => true), $options)); $db =& ConnectionManager::getDataSource($connection); App::import('Model', 'AppModel'); $tables = array(); $currentTables = $db->listSources(); $prefix = null; if (isset($db->config['prefix'])) { $prefix = $db->config['prefix']; } if (!is_array($models) && $models !== false) { $models = Configure::listObjects('model'); } if (is_array($models)) { foreach ($models as $model) { if (PHP5) { $Object = ClassRegistry::init(array('class' => $model, 'ds' => $connection)); } else { $Object =& ClassRegistry::init(array('class' => $model, 'ds' => $connection)); } if (is_object($Object) && $Object->useTable !== false) { $Object->setDataSource($connection); $table = $db->fullTableName($Object, false); if (in_array($table, $currentTables)) { $key = array_search($table, $currentTables); if (empty($tables[$Object->table])) { $tables[$Object->table] = $this->__columns($Object); $tables[$Object->table]['indexes'] = $db->index($Object); unset($currentTables[$key]); } if (!empty($Object->hasAndBelongsToMany)) { foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) { if (isset($assocData['with'])) { $class = $assocData['with']; } elseif ($assocData['_with']) { $class = $assocData['_with']; } if (is_object($Object->{$class})) { $table = $db->fullTableName($Object->{$class}, false); if (in_array($table, $currentTables)) { $key = array_search($table, $currentTables); $tables[$Object->{$class}->table] = $this->__columns($Object->{$class}); $tables[$Object->{$class}->table]['indexes'] = $db->index($Object->{$class}); unset($currentTables[$key]); } } } } } } } } if (!empty($currentTables)) { foreach ($currentTables as $table) { if ($prefix) { if (strpos($table, $prefix) !== 0) { continue; } $table = str_replace($prefix, '', $table); } $Object = new AppModel(array('name' => Inflector::classify($table), 'table' => $table, 'ds' => $connection)); $systemTables = array('aros', 'acos', 'aros_acos', Configure::read('Session.table'), 'i18n'); if (in_array($table, $systemTables)) { $tables[$Object->table] = $this->__columns($Object); $tables[$Object->table]['indexes'] = $db->index($Object); } elseif ($models === false) { $tables[$table] = $this->__columns($Object); $tables[$table]['indexes'] = $db->index($Object); } else { $tables['missing'][$table] = $this->__columns($Object); $tables['missing'][$table]['indexes'] = $db->index($Object); } } } ksort($tables); return compact('name', 'tables'); }
/** * Shows console help * * @access public */ function help() { $this->stdout("\nWelcome to CakePHP v" . Configure::version() . " Console"); $this->stdout("---------------------------------------------------------------"); $this->stdout("Current Paths:"); $this->stdout(" -app: " . $this->params['app']); $this->stdout(" -working: " . rtrim($this->params['working'], DS)); $this->stdout(" -root: " . rtrim($this->params['root'], DS)); $this->stdout(" -core: " . rtrim(CORE_PATH, DS)); $this->stdout(""); $this->stdout("Changing Paths:"); $this->stdout("your working path should be the same as your application path"); $this->stdout("to change your path use the '-app' param."); $this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp"); $this->stdout("\nAvailable Shells:"); $_shells = array(); foreach ($this->shellPaths as $path) { if (is_dir($path)) { $shells = Configure::listObjects('file', $path); $path = str_replace(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS, 'CORE' . DS, $path); $path = str_replace(APP, 'APP' . DS, $path); $path = str_replace(ROOT, 'ROOT', $path); $path = rtrim($path, DS); $this->stdout("\n " . $path . ":"); if (empty($shells)) { $this->stdout("\t - none"); } else { sort($shells); foreach ($shells as $shell) { if ($shell !== 'shell.php') { $this->stdout("\t " . str_replace('.php', '', $shell)); } } } } } $this->stdout("\nTo run a command, type 'cake shell_name [args]'"); $this->stdout("To get help on a specific command, type 'cake shell_name help'"); $this->_stop(); }
function admin_index() { $this->pageTitle = __('Hooks', true); $hooks = array(); $plugins = Configure::listObjects('plugin'); $folder =& new Folder(); // Components $appComponents = Configure::listObjects('component', APP . 'controllers' . DS . 'components'); $pluginComponents = array(); foreach ($plugins as $plugin) { $folder->path = APP . 'plugins' . DS . Inflector::underscore($plugin) . DS . 'controllers' . DS . 'components'; $content = $folder->read(); foreach ($content['1'] as $componentFile) { $pluginComponents[] = $plugin . '.' . Inflector::camelize(str_replace('.php', '', $componentFile)); } } $components = array_merge($appComponents, $pluginComponents); $i = 0; foreach ($components as $component) { $components[$i] = $component . 'Component'; $i++; } // Helpers $appHelpers = Configure::listObjects('helper', APP . 'views' . DS . 'helpers'); $pluginHelpers = array(); foreach ($plugins as $plugin) { $folder->path = APP . 'plugins' . DS . Inflector::underscore($plugin) . DS . 'views' . DS . 'helpers'; $content = $folder->read(); foreach ($content['1'] as $helperFile) { $pluginHelpers[] = $plugin . '.' . Inflector::camelize(str_replace('.php', '', $helperFile)); } } $helpers = array_merge($appHelpers, $pluginHelpers); $i = 0; foreach ($helpers as $helper) { $helpers[$i] = $helper . 'Helper'; $i++; } // Get only hook helpers/components $items = array_merge($components, $helpers); foreach ($items as $item) { if (strstr(Inflector::underscore($item), '_hook_component') || strstr(Inflector::underscore($item), '_hook_helper')) { $hooks[] = $item; } } sort($hooks); // Configuration $siteHookComponents = explode(',', Configure::read('Hook.components')); $siteHookHelpers = explode(',', Configure::read('Hook.helpers')); //$siteHooks = array_merge($hookComponents, $hookHelpers); $siteHooks = array(); foreach ($siteHookComponents as $siteHookComponent) { if (!$siteHookComponent) { continue; } $siteHooks[] = $siteHookComponent . 'Component'; } foreach ($siteHookHelpers as $siteHookHelper) { if (!$siteHookHelper) { continue; } $siteHooks[] = $siteHookHelper . 'Helper'; } $this->set(compact('hooks', 'siteHookComponents', 'siteHookHelpers', 'siteHooks')); }
/** * Shows console help * * @access public */ function help() { $this->stdout("Current Paths:"); $this->stdout(" -working: " . $this->params['working']); $this->stdout(" -root: " . ROOT); $this->stdout(" -app: " . APP); $this->stdout(" -core: " . CORE_PATH); $this->stdout(""); $this->stdout("Changing Paths:"); $this->stdout("your working path should be the same as your application path"); $this->stdout("to change your path use the '-app' param."); $this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp"); $this->stdout("\nAvailable Shells:"); foreach ($this->shellPaths as $path) { if (is_dir($path)) { $shells = Configure::listObjects('file', $path); $path = r(CORE_PATH, '', $path); $this->stdout("\n " . $path . ":"); if (empty($shells)) { $this->stdout("\t - none"); } else { foreach ($shells as $shell) { if ($shell != 'shell.php') { $this->stdout("\t " . r('.php', '', $shell)); } } } } } $this->stdout("\nTo run a command, type 'cake shell_name [args]'"); $this->stdout("To get help on a specific command, type 'cake shell_name help'"); exit; }
/** * Override main() to handle action * * @access public */ function main() { if (empty($this->args)) { return $this->help(); } $type = strtolower($this->args[0]); if (isset($this->paths[$type])) { $path = $this->paths[$type]; } else { $path = $this->paths['core']; } if (count($this->args) == 1) { $file = $type; $class = Inflector::camelize($type); } elseif (count($this->args) > 1) { $file = Inflector::underscore($this->args[1]); $class = Inflector::camelize($file); } $objects = Configure::listObjects('class', $path); if (in_array($class, $objects)) { if (in_array($type, array('behavior', 'component', 'helper')) && $type !== $file) { if (!preg_match('/' . Inflector::camelize($type) . '$/', $class)) { $class .= Inflector::camelize($type); } } } else { $this->err(sprintf(__("%s not found", true), $class)); $this->_stop(); } $parsed = $this->__parseClass($path . $file . '.php'); if (!empty($parsed)) { if (isset($this->params['m'])) { if (!isset($parsed[$this->params['m']])) { $this->err(sprintf(__("%s::%s() could not be found", true), $class, $this->params['m'])); $this->_stop(); } $method = $parsed[$this->params['m']]; $this->out($class . '::' . $method['method'] . $method['parameters']); $this->hr(); $this->out($method['comment'], true); } else { $this->out(ucwords($class)); $this->hr(); $i = 0; foreach ($parsed as $method) { $list[] = ++$i . ". " . $method['method'] . $method['parameters']; } $this->out($list); $methods = array_keys($parsed); while ($number = strtolower($this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.', true), null, 'q'))) { if ($number === 'q') { $this->out(__('Done', true)); $this->_stop(); } if ($number === 'l') { $this->out($list); } if (isset($methods[--$number])) { $method = $parsed[$methods[$number]]; $this->hr(); $this->out($class . '::' . $method['method'] . $method['parameters']); $this->hr(); $this->out($method['comment'], true); } } } } }
/** * undocumented function * * @return void **/ function aco_update() { $root = $this->_checkNode($this->rootNode, $this->rootNode, null); App::import('Core', array('Controller')); $Controllers = Configure::listObjects('controller'); $appIndex = array_search('App', $Controllers); if ($appIndex !== false) { unset($Controllers[$appIndex]); } // look at each controller in app/controllers foreach ($Controllers as $ctrlName) { App::import('Controller', $ctrlName); // find / make controller node $controllerNode = $this->_checkNode($this->rootNode . '/' . $ctrlName, $ctrlName, $root['Aco']['id']); $this->_checkMethods($ctrlName, $controllerNode, $this->_clean); } if ($this->_clean) { $this->Aco->id = $root['Aco']['id']; $controllerNodes = $this->Aco->children(null, true); $ctrlFlip = array_flip($Controllers); foreach ($controllerNodes as $ctrlNode) { if (!isset($ctrlFlip[$ctrlNode['Aco']['alias']])) { $this->Aco->id = $ctrlNode['Aco']['id']; if ($this->Aco->delete()) { $this->out(sprintf(__('Deleted %s and all children', true), $this->rootNode . '/' . $ctrlNode['Aco']['alias'])); } } } } $this->out(__('Aco Update Complete', true)); return true; }
/** * testListObjects method * * @access public * @return void */ function testListObjects() { $result = Configure::listObjects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs'); $this->assertTrue(in_array('Xml', $result)); $this->assertTrue(in_array('Cache', $result)); $this->assertTrue(in_array('HttpSocket', $result)); $result = Configure::listObjects('behavior'); $this->assertTrue(in_array('Tree', $result)); $result = Configure::listObjects('controller'); $this->assertTrue(in_array('Pages', $result)); $result = Configure::listObjects('component'); $this->assertTrue(in_array('Auth', $result)); $result = Configure::listObjects('view'); $this->assertTrue(in_array('Media', $result)); $result = Configure::listObjects('helper'); $this->assertTrue(in_array('Html', $result)); $result = Configure::listObjects('model'); $notExpected = array('AppModel', 'Behavior', 'ConnectionManager', 'DbAcl', 'Model', 'Schema'); foreach ($notExpected as $class) { $this->assertFalse(in_array($class, $result)); } $result = Configure::listObjects('file'); $this->assertFalse($result); $result = Configure::listObjects('file', 'non_existing_configure'); $expected = array(); $this->assertEqual($result, $expected); $result = Configure::listObjects('NonExistingType'); $this->assertFalse($result); }
function _getControllers($lowercase = false) { $controllerList = array(); $controllers = Configure::listObjects('controller'); App::import('Controller', $controllers); /* To improve... $controllers[]='User'; $controllers[]='Users'; $controllers[]='Groups'; $controllers[]='Rules'; $controllers[]='Denied'; App::import('Controller', array('Authake.User', 'Authake.Users', 'Authake.Groups', 'Authake.Rules', 'Authake.Denied')); */ foreach ($controllers as $controller) { if ($controller != "App") { $className = $controller . 'Controller'; $actions = get_class_methods($className); foreach ($actions as $k => $v) { if ($v[0] == '_') { unset($actions[$k]); } } $parentActions = get_class_methods('AppController'); if ($lowercase) { $controller = strtolower($controller); } $controllersList[$controller] = array_diff($actions, $parentActions); } } return $controllersList; }
/** * Binds the given domain to a file in the specified directory. * * @param string $domain Domain to bind * @return string Domain binded * @access private */ function __bindTextDomain($domain) { $this->__noLocale = true; $core = true; $merge = array(); $searchPaths = Configure::read('localePaths'); $plugins = Configure::listObjects('plugin'); if (!empty($plugins)) { $pluginPaths = Configure::read('pluginPaths'); foreach ($plugins as $plugin) { $plugin = Inflector::underscore($plugin); if ($plugin === $domain) { foreach ($pluginPaths as $pluginPath) { $searchPaths[] = $pluginPath . DS . $plugin . DS . 'locale'; } $searchPaths = array_reverse($searchPaths); break; } } } foreach ($searchPaths as $directory) { foreach ($this->l10n->languagePath as $lang) { $file = $directory . DS . $lang . DS . $this->category . DS . $domain; if ($core) { $app = $directory . DS . $lang . DS . $this->category . DS . 'core'; if (file_exists($fn = "{$app}.mo")) { $this->__loadMo($fn, $domain); $this->__noLocale = false; $merge[$this->category][$this->__lang][$domain] = $this->__domains[$this->category][$this->__lang][$domain]; $core = null; } elseif (file_exists($fn = "{$app}.po") && ($f = fopen($fn, "r"))) { $this->__loadPo($f, $domain); $this->__noLocale = false; $merge[$this->category][$this->__lang][$domain] = $this->__domains[$this->category][$this->__lang][$domain]; $core = null; } } if (file_exists($fn = "{$file}.mo")) { $this->__loadMo($fn, $domain); $this->__noLocale = false; break 2; } elseif (file_exists($fn = "{$file}.po") && ($f = fopen($fn, "r"))) { $this->__loadPo($f, $domain); $this->__noLocale = false; break 2; } } } if (empty($this->__domains[$this->category][$this->__lang][$domain])) { $this->__domains[$this->category][$this->__lang][$domain] = array(); return $domain; } if ($head = $this->__domains[$this->category][$this->__lang][$domain][""]) { foreach (explode("\n", $head) as $line) { $header = strtok($line, ":"); $line = trim(strtok("\n")); $this->__domains[$this->category][$this->__lang][$domain]["%po-header"][strtolower($header)] = $line; } if (isset($this->__domains[$this->category][$this->__lang][$domain]["%po-header"]["plural-forms"])) { $switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->__domains[$this->category][$this->__lang][$domain]["%po-header"]["plural-forms"]); $this->__domains[$this->category][$this->__lang][$domain]["%plural-c"] = $switch; unset($this->__domains[$this->category][$this->__lang][$domain]["%po-header"]); } $this->__domains = Set::pushDiff($this->__domains, $merge); if (isset($this->__domains[$this->category][$this->__lang][$domain][null])) { unset($this->__domains[$this->category][$this->__lang][$domain][null]); } } return $domain; }