public function modelConstruct(CakeEvent $Event) { $Model = $Event->subject(); // Because, by default, the SQL is only logged and displayed if debug > 2; using the `DebugKit` // new 'autoRun' and/or 'forceEnable' still doesn't help in profiling SQL calls in production. // This will force the current model's datasource to log all SQL calls ONLY when in production // mode and DebugKit is used with either 'autoRun' or 'forceEnable'. if (Reveal::is('DebugKit.running') && !Reveal::is('Page.test')) { $Model->getDatasource()->fullDebug = true; } if (!isset($Model->belongsToForeignModels)) { return; } // Get all foreign models used if not defined by current model. if (empty($Model->belongsToForeignModels)) { $foreignModels = $Model->find('all', array('fields' => array('DISTINCT' => 'foreign_model'), 'recursive' => -1, 'callbacks' => false)); foreach ($foreignModels as $foreignModel) { // Rarely, some tokens are not associated with any other model. if (empty($foreignModel[$Model->alias]['foreign_model'])) { continue; } list($plugin, $name) = pluginSplit($foreignModel[$Model->alias]['foreign_model']); $Model->belongsToForeignModels[$name] = array('className' => $foreignModel[$Model->alias]['foreign_model'], 'foreignKey' => 'foreign_key', 'conditions' => null, 'fields' => null, 'order' => null, 'counterCache' => false); } } // Associate foreign `belongsTo` models. $Event->result = Hash::merge((array) $Event->result, array('belongsTo' => array_merge($Model->belongsTo, $Model->belongsToForeignModels))); }
/** * Add a menu item. * * @param string $path dot separated path in the array. * @param array $options menu options array * @return void */ public static function add($path, $options) { if (Reveal::is('Sapi.cli')) { return; } if (!empty($options['access'])) { foreach ((array) $options['access'] as $rule) { $check = strpos($rule, '!') === 0; if ($check) { $rule = substr($rule, 1); } if (Reveal::is($rule) == $check) { return; } } unset($options['access']); } $pathE = explode('.', $path); $pathE = array_splice($pathE, 0, count($pathE) - 2); $parent = join('.', $pathE); if (!empty($parent) && !Hash::check(self::$_items, $parent)) { $title = Inflector::humanize(end($pathE)); $o = array('title' => $title); self::_setupOptions($o); self::add($parent, $o); } self::_setupOptions($options); $current = Hash::extract(self::$_items, $path); if (!empty($current)) { self::_replace(self::$_items, $path, $options); } else { self::$_items = Hash::insert(self::$_items, $path, $options); } }
/** * {@inheritdoc} */ public function setup(Model $Model, $config = array()) { if (isset($config[0])) { $config['fields'] = $config[0]; unset($config[0]); } $config = array_merge($this->_defaults, $config); $config['default'] = reset($config['values']); if (is_string($config['fields'])) { $config['fields'] = (array) $config['fields']; } foreach ($config['fields'] as $field => $options) { if (is_numeric($field)) { unset($config['fields'][$field]); $field = $options; $options = $config['fields'][$options] = array(); } if (!array_key_exists('values', $options)) { $options = array('values' => empty($options) ? $config['values'] : $options); } $config['fields'][$field] = array_merge(array('default' => reset($options['values'])), $options); if (!$Model->hasField($field) && (!Reveal::is('Sapi.cli') || !in_array('Migrations.migration', env('argv')))) { $msg = __d('affiliates', "Missing state field '%s' in table '%s'", $field, $Model->useTable); throw new FatalErrorException($msg); } } $this->settings[$Model->alias] = $config; }
/** * Auto-load plugin event listeners. * * @param CommonEventManager $manager Optional. Instance to use. Defaults to the global instance. * @param string $scope Optional. The scope of events to load. * @return CakeEventManager */ public static function loadListeners($manager = null, $scope = null) { if (!$manager instanceof CakeEventManager) { $manager = CakeEventManager::instance(); } empty($manager::$loadedListeners['Common']) && ($manager::$loadedListeners['Common'] = new CommonEventListener()); (empty($manager::$loadedScopes['Common']) || !in_array($scope, (array) $manager::$loadedScopes['Common'])) && ($manager::$loadedScopes['Common'][] = $scope && CommonEventManager::attachByScope($manager::$loadedListeners['Common'], $manager, $scope)); $manager::$implementedEvents['Common'] = array_keys($manager::$loadedListeners['Common']->implementedEvents()); foreach (CakePlugin::loaded() as $plugin) { if (isset($manager::$loadedListeners[$plugin])) { if ($manager::$loadedListeners[$plugin] && !empty($scope) && !in_array($scope, (array) $manager::$loadedScopes[$plugin])) { self::$loadedScopes[$plugin][] = $scope; CommonEventManager::attachByScope($manager::$loadedListeners[$plugin], $manager, $scope); } continue; } $class = $plugin . 'EventListener'; if (ClassRegistry::isKeySet($class)) { $manager::$loadedListeners[$plugin] = ClassRegistry::getObject($class); } else { if (file_exists(CakePlugin::path($plugin) . 'Event' . DS . $class . '.php')) { App::uses($class, $plugin . '.Event'); $manager::$loadedListeners[$plugin] = new $class(); } else { $manager::$loadedListeners[$plugin] = false; continue; } } $manager::$loadedScopes[$plugin] = array(); $manager::$implementedEvents[$plugin] = array_keys($manager::$loadedListeners[$plugin]->implementedEvents()); if (empty($scope)) { $manager->attach($manager::$loadedListeners[$plugin]); } else { if (!in_array($scope, $manager::$loadedScopes[$plugin])) { $manager::$loadedScopes[$plugin][] = $scope; CommonEventManager::attachByScope($manager::$loadedListeners[$plugin], $manager, $scope); } } } if (!Reveal::is('Page.test') && !isset($manager::$loadedListeners['App'])) { if (file_exists(APP . 'Event' . DS . 'AppEventListener.php')) { App::uses('AppEventListener', 'Event'); $manager::$loadedListeners['App'] = new AppEventListener(); $manager::$loadedScopes['App'] = array(); $manager::$implementedEvents['App'] = array_keys($manager::$loadedListeners['App']->implementedEvents()); if (empty($scope)) { $manager->attach($manager::$loadedListeners['App']); } else { if (!in_array($scope, $manager::$loadedScopes['App'])) { self::$loadedScopes['App'][] = $scope; CommonEventManager::attachByScope($manager::$loadedListeners['App'], $manager, $scope); } } } } else { if (isset($manager::$loadedListeners['App']) && $manager::$loadedListeners['App'] && !empty($scope) && !in_array($scope, $manager::$loadedScopes['App'])) { $manager::$loadedScopes['App'][] = $scope; CommonEventManager::attachByScope($manager::$loadedListeners['App'], $manager, $scope); } } return $manager; }
/** * Breadcrumb constructor. * * @return void */ protected function _constructCrumbs() { if ($this instanceof CakeErrorController || $this instanceof PagesController || false === Common::read('Layout.showCrumbs', true) || false === $this->breadCrumbs || !empty($this->breadCrumbs)) { return; } // Home. $this->breadCrumbs = array(__d('common', "Home") => '/'); // Dashboard. if (CakePlugin::loaded('Users') && Reveal::is('User.loggedin')) { $this->breadCrumbs = array(__d('common', "Dashboard") => $this->Auth->loginRedirect); if ($this->request->controller == $this->Auth->loginRedirect['controller'] && preg_match('/' . $this->Auth->loginRedirect['action'] . '$/', $this->action) && (empty($this->Auth->loginRedirect['plugin']) || $this->plugin == Inflector::camelize($this->Auth->loginRedirect['plugin']))) { $this->breadCrumbs[__d('common', "Dashboard")] = array(); return; } } // Plugin. if (!empty($this->plugin)) { $title = empty($this->crumbTitles[$this->plugin]) ? $this->plugin : $this->crumbTitles[$this->plugin]; $this->breadCrumbs[$title] = array('plugin' => Inflector::underscore($this->plugin), 'controller' => Inflector::underscore($this->plugin), 'action' => 'index'); if (Router::normalize(Router::url($this->breadCrumbs[$title])) == $this->request->here) { $this->breadCrumbs[$title] = array(); } if (($this->plugin == $this->name || !empty($this->crumbTitles[$this->name]) && $this->plugin == $this->crumbTitles[$this->name]) && in_array('index', explode('_', $this->action))) { return; } } // Controller. if (!empty($this->crumbTitles[$this->name])) { $this->breadCrumbs[$this->crumbTitles[$this->name]] = array('action' => 'index'); } else { if (!array_key_exists($this->name, $this->crumbTitles)) { $this->breadCrumbs[!empty($this->modelName) ? Inflector::pluralize($this->modelName) : Inflector::humanize(Inflector::underscore($this->name))] = array('action' => 'index'); } } if (array_pop(explode('_', $this->action)) == 'index') { $this->breadCrumbs[end(array_keys($this->breadCrumbs))] = array(); return; } // Action if (!empty($this->crumbTitles[$this->action])) { $this->breadCrumbs[$this->crumbTitles[$this->action]] = array(); } else { if (!array_key_exists($this->action, $this->crumbTitles)) { $action = str_replace($this->request->prefix, '', $this->action); if ($action == $this->action) { $action = str_replace(Configure::read($this->plugin . '.routingPrefixes.' . $this->request->prefix), '', $this->action); } $this->breadCrumbs[Inflector::humanize(Inflector::underscore($action))] = array(); } } }
/** * Stops a benchmarking timer. * * $name should be the same as the $name used in startTimer(). * * @param string $name The name of the timer to end. * @return boolean true if timer was ended, false if timer was not started. */ public static function stopTimer($name) { if (!Reveal::is('DebugKit.running')) { return; } DebugTimer::stop($name); }
/** * [_render description] * @param [type] $path [description] * @param [type] $attrs [description] * @return [type] */ protected function _render($nav) { extract($nav); $items = Navigation::order(Navigation::items($path)); if (empty($items)) { return false; } $defaults = array($this->_tag => array(), $this->_tags[$this->_tag] => array(), 'a' => array()); $list = array(); foreach ($items as $key => $options) { $title = Inflector::humanize($key); extract($options); $htmlAttributes = Hash::merge($defaults, $htmlAttributes); Reveal::addRule('Page.current', array('self', '__isPageCurrent'), Router::normalize($url)); if (Reveal::is('Page.current')) { $class = 'active'; if (!empty($htmlAttributes[$this->_tags[$this->_tag]]['class'])) { $class = $htmlAttributes[$this->_tags[$this->_tag]]['class'] . ' ' . $class; } $htmlAttributes = Hash::merge($htmlAttributes, array($this->_tags[$this->_tag] => compact('class'))); } if (method_exists($this->Html, 'icon') && !empty($icon) && count(explode(' ', $icon)) == 1) { $icon = $this->Html->icon($icon); } $title = $icon . $title; // Link-ify item's title when it does not match the current page. if (!empty($url)) { // Allow for link tag customization using `HtmlHelper::loadConfig()`. $configPath = dirname(__FILE__) . DS . 'Navigation' . DS; $reset = false; if (!empty($htmlAttributes['a']['tag'])) { $this->Html->loadConfig($htmlAttributes['a']['tag'], $configPath); $reset = true; unset($htmlAttributes['a']['tag']); } if (isset($url['prefix']) && false === $url['prefix'] && !empty($this->_View->request->prefix)) { $url[$this->_View->request->prefix] = false; } if (is_array($url) && !isset($url['plugin'])) { $url['plugin'] = null; } $title = $this->Html->link($title, $url, $htmlAttributes['a'], $confirmMessage); $reset && $this->Html->loadConfig('reset', $configPath); } if (!empty($children)) { // if (!)$title = $this->Html->tag('span', $title, array('class' => 'title')); $title .= $this->_render(array('path' => "{$path}.{$key}.children", 'attrs' => $htmlAttributes[$this->_tag])); } $list[] = $this->Html->tag($this->_tags[$this->_tag], $title, $htmlAttributes[$this->_tags[$this->_tag]]); } return $this->Html->tag($this->_tag, implode('', $list), $attrs); }
/** * {@inheritdoc} */ public function startTest($method) { // Skip if method requires connection and currently not connected. if (!empty($this->_testsRequireConnection) && in_array($method, $this->_testsRequireConnection)) { $this->skipIf(!Reveal::is('App.online'), "Requires internet connection."); } // Skip if method is listed in `self::$_testsToRun`. $message = "Running selected tests only."; if (false !== self::$testsStopped) { $this->_testsToRun = array(''); $message = "Disabled during test run."; if (true !== self::$testsStopped) { $message = self::$testsStopped; } } $this->skipIf(!empty($this->_testsToRun) && !in_array($method, $this->_testsToRun), $message); }
public function testIsUndefinedRule() { $this->expectException('CommonRevealException', "Rule 'Foo.bar' is not defined."); Reveal::is('Foo.bar'); }