예제 #1
0
 /**
  * Find the paths to all the installed shell themes in the app.
  *
  * Bake themes are directories not named `skel` inside a `Console/Templates` path.
  * They are listed in this order: app -> plugin -> default
  *
  * @return array Array of bake themes that are installed.
  */
 protected function _findThemes()
 {
     $paths = App::path('Console');
     $plugins = App::objects('plugin');
     foreach ($plugins as $plugin) {
         $paths[] = $this->_pluginPath($plugin) . 'Console/';
     }
     $core = current(App::core('Console'));
     $Folder = new Folder($core . 'Templates/default');
     $contents = $Folder->read();
     $themeFolders = $contents[0];
     $paths[] = $core;
     foreach ($paths as $i => $path) {
         $paths[$i] = rtrim($path, DS) . DS;
     }
     $this->_io->verbose('Found the following bake themes:');
     $themes = [];
     foreach ($paths as $path) {
         $Folder = new Folder($path . 'Templates', false);
         $contents = $Folder->read();
         $subDirs = $contents[0];
         foreach ($subDirs as $dir) {
             $Folder = new Folder($path . 'Templates/' . $dir);
             $contents = $Folder->read();
             $subDirs = $contents[0];
             if (array_intersect($contents[0], $themeFolders)) {
                 $templateDir = $path . 'Templates/' . $dir . DS;
                 $themes[$dir] = $templateDir;
                 $this->_io->verbose(sprintf("- %s -> %s", $dir, $templateDir));
             }
         }
     }
     return $themes;
 }
예제 #2
0
 /**
  * Gets the shell command listing.
  *
  * @return array
  */
 public function getShellList()
 {
     $skipFiles = ['AppShell'];
     $hiddenCommands = ['CommandListShell', 'CompletionShell'];
     $plugins = Plugin::loaded();
     $shellList = array_fill_keys($plugins, null) + ['CORE' => null, 'app' => null];
     $corePath = App::core('Console/Command');
     $shells = App::objects('file', $corePath[0]);
     $shells = array_diff($shells, $skipFiles, $hiddenCommands);
     $this->_appendShells('CORE', $shells, $shellList);
     $appShells = App::objects('Console/Command', null, false);
     $appShells = array_diff($appShells, $shells, $skipFiles);
     $this->_appendShells('app', $appShells, $shellList);
     foreach ($plugins as $plugin) {
         $pluginShells = App::objects($plugin . '.Console/Command');
         $this->_appendShells($plugin, $pluginShells, $shellList);
     }
     return array_filter($shellList);
 }
예제 #3
0
 /**
  * Sets the plugins folder for this test
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     App::objects('Plugin', null, false);
 }
예제 #4
0
 /**
  * Tests listing objects within a plugin
  *
  * @return void
  */
 public function testListObjectsInPlugin()
 {
     Plugin::load(array('TestPlugin', 'TestPluginTwo'));
     $result = App::objects('TestPlugin.Model/Table');
     $this->assertContains('TestPluginCommentsTable', $result);
     $result = App::objects('TestPlugin.Model/Behavior');
     $this->assertTrue(in_array('PersisterOneBehavior', $result));
     $result = App::objects('TestPlugin.View/Helper');
     $expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
     $this->assertEquals($expected, $result);
     $result = App::objects('TestPlugin.Controller/Component');
     $this->assertTrue(in_array('OtherComponent', $result));
     $result = App::objects('TestPluginTwo.Model/Behavior');
     $this->assertSame(array(), $result);
     $result = App::objects('Model/Table', null, false);
     $this->assertContains('PostsTable', $result);
     $this->assertContains('ArticlesTable', $result);
 }
예제 #5
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Cache::disable();
     App::objects('Plugin', null, true);
 }
예제 #6
0
 /**
  * Returns filename of given action's template file (.ctp) as a string.
  * CamelCased action names will be under_scored! This means that you can have
  * LongActionNames that refer to long_action_names.ctp views.
  *
  * @param string $name Controller action to find template filename for
  * @return string Template filename
  * @throws \Cake\View\Error\MissingViewException when a view file could not be found.
  */
 protected function _getViewFileName($name = null)
 {
     $subDir = null;
     if ($this->subDir !== null) {
         $subDir = $this->subDir . DS;
     }
     if ($name === null) {
         $name = $this->view;
     }
     $name = str_replace('/', DS, $name);
     list($plugin, $name) = $this->pluginSplit($name);
     if (strpos($name, DS) === false && $name[0] !== '.') {
         $name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
     } elseif (strpos($name, DS) !== false) {
         if ($name[0] === DS || $name[1] === ':') {
             if (is_file($name)) {
                 return $name;
             }
             $name = trim($name, DS);
         } elseif ($name[0] === '.') {
             $name = substr($name, 3);
         } elseif (!$plugin || $this->viewPath !== $this->name) {
             $name = $this->viewPath . DS . $subDir . $name;
         }
     }
     $paths = $this->_paths($plugin);
     $exts = $this->_getExtensions();
     foreach ($exts as $ext) {
         foreach ($paths as $path) {
             if (file_exists($path . $name . $ext)) {
                 return $path . $name . $ext;
             }
         }
     }
     $defaultPath = $paths[0];
     if ($this->plugin) {
         $pluginPaths = App::objects('Plugin');
         foreach ($paths as $path) {
             if (strpos($path, $pluginPaths[0]) === 0) {
                 $defaultPath = $path;
                 break;
             }
         }
     }
     throw new Error\MissingViewException(array('file' => $defaultPath . $name . $this->_ext));
 }
예제 #7
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $request = new Request();
     $this->Controller = new Controller($request);
     $this->PostsController = new ViewPostsController($request);
     $this->PostsController->viewPath = 'Posts';
     $this->PostsController->index();
     $this->View = $this->PostsController->createView();
     $themeRequest = new Request('posts/index');
     $this->ThemeController = new Controller($themeRequest);
     $this->ThemePostsController = new ThemePostsController($themeRequest);
     $this->ThemePostsController->viewPath = 'Posts';
     $this->ThemePostsController->index();
     $this->ThemeView = $this->ThemePostsController->createView();
     App::objects('Plugin', null, false);
     Plugin::load(array('TestPlugin', 'TestPlugin', 'PluginJs'));
     Configure::write('debug', true);
 }
예제 #8
0
 /**
  * Will load all the plugins located in the default plugin folder.
  *
  * If passed an options array, it will be used as a common default for all plugins to be loaded
  * It is possible to set specific defaults for each plugins in the options array. Examples:
  *
  * {{{
  *  Plugin::loadAll([
  *      ['bootstrap' => true],
  *      'DebugKit' => ['routes' => true],
  *  ]);
  * }}}
  *
  * The above example will load the bootstrap file for all plugins, but for DebugKit it will only load the routes file
  * and will not look for any bootstrap script.
  *
  * If a plugin has been loaded already, it will not be reloaded by loadAll().
  *
  * @param array $options
  * @return void
  */
 public static function loadAll(array $options = [])
 {
     $plugins = App::objects('Plugin');
     foreach ($plugins as $p) {
         $opts = isset($options[$p]) ? $options[$p] : null;
         if ($opts === null && isset($options[0])) {
             $opts = $options[0];
         }
         if (isset(static::$_plugins[$p])) {
             continue;
         }
         static::load($p, (array) $opts);
     }
 }
예제 #9
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $_GET = [];
     Configure::write('App.base', false);
     Configure::write('App.baseUrl', false);
     Configure::write('App.dir', 'app');
     Configure::write('App.webroot', 'webroot');
     Configure::write('App.namespace', 'TestApp');
     Cache::disable();
     App::objects('Plugin', null, false);
 }