Exemple #1
0
 /**
  * Find the paths to all the installed shell templates in the app.
  *
  * Bake templates are directories under `Template/Bake` path.
  * They are listed in this order: app -> plugin -> default
  *
  * @return array Array of bake templates that are installed.
  */
 protected function _findTemplates()
 {
     $paths = App::path('Template');
     $plugins = Plugin::loaded();
     foreach ($plugins as $plugin) {
         $paths[] = Plugin::classPath($plugin) . 'Template' . DS;
     }
     $core = current(App::core('Template'));
     $Folder = new Folder($core . 'Bake' . DS . 'default');
     $contents = $Folder->read();
     $templateFolders = $contents[0];
     $paths[] = $core;
     foreach ($paths as $i => $path) {
         $paths[$i] = rtrim($path, DS) . DS;
     }
     $this->_io->verbose('Found the following bake templates:');
     $templates = [];
     foreach ($paths as $path) {
         $Folder = new Folder($path . 'Bake', false);
         $contents = $Folder->read();
         $subDirs = $contents[0];
         foreach ($subDirs as $dir) {
             $Folder = new Folder($path . 'Bake' . DS . $dir);
             $contents = $Folder->read();
             $subDirs = $contents[0];
             if (array_intersect($contents[0], $templateFolders)) {
                 $templateDir = $path . 'Bake' . DS . $dir . DS;
                 $templates[$dir] = $templateDir;
                 $this->_io->verbose(sprintf("- %s -> %s", $dir, $templateDir));
             }
         }
     }
     return $templates;
 }
Exemple #2
0
 /**
  * Inits PO file from POT file.
  *
  * @param string|null $language Language code to use.
  * @return int|null
  */
 public function init($language = null)
 {
     if (!$language) {
         $language = $this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.');
     }
     if (strlen($language) < 2) {
         return $this->error('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
     }
     $this->_paths = [APP];
     if ($this->param('plugin')) {
         $plugin = Inflector::camelize($this->param('plugin'));
         $this->_paths = [Plugin::classPath($plugin)];
     }
     $response = $this->in('What folder?', null, rtrim($this->_paths[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'Locale');
     $sourceFolder = rtrim($response, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     $targetFolder = $sourceFolder . $language . DIRECTORY_SEPARATOR;
     if (!is_dir($targetFolder)) {
         mkdir($targetFolder, 0775, true);
     }
     $count = 0;
     $iterator = new DirectoryIterator($sourceFolder);
     foreach ($iterator as $fileinfo) {
         if (!$fileinfo->isFile()) {
             continue;
         }
         $filename = $fileinfo->getFilename();
         $newFilename = $fileinfo->getBasename('.pot');
         $newFilename = $newFilename . '.po';
         $this->createFile($targetFolder . $newFilename, file_get_contents($sourceFolder . $filename));
         $count++;
     }
     $this->out('Generated ' . $count . ' PO files in ' . $targetFolder);
 }
Exemple #3
0
 /**
  * Locate the tasks bake will use.
  *
  * Scans the following paths for tasks that are subclasses of
  * Cake\Shell\Task\BakeTask:
  *
  * - Cake/Shell/Task/
  * - App/Shell/Task/
  * - Shell/Task for each loaded plugin
  *
  * @return void
  */
 public function loadTasks()
 {
     $tasks = [];
     $tasks = $this->_findTasks($tasks, APP, Configure::read('App.namespace'));
     foreach (Plugin::loaded() as $plugin) {
         $tasks = $this->_findTasks($tasks, Plugin::classPath($plugin), $plugin, $plugin);
     }
     $this->tasks = array_values($tasks);
     parent::loadTasks();
 }
Exemple #4
0
 /**
  * Execution method always used for tasks.
  *
  * @return void
  */
 public function main()
 {
     if (!empty($this->params['exclude'])) {
         $this->_exclude = explode(',', $this->params['exclude']);
     }
     if (isset($this->params['files']) && !is_array($this->params['files'])) {
         $this->_files = explode(',', $this->params['files']);
     }
     if (isset($this->params['paths'])) {
         $this->_paths = explode(',', $this->params['paths']);
     } elseif (isset($this->params['plugin'])) {
         $plugin = Inflector::camelize($this->params['plugin']);
         if (!Plugin::loaded($plugin)) {
             Plugin::load($plugin);
         }
         $this->_paths = [Plugin::classPath($plugin)];
         $this->params['plugin'] = $plugin;
     } else {
         $this->_getPaths();
     }
     if (isset($this->params['extract-core'])) {
         $this->_extractCore = !(strtolower($this->params['extract-core']) === 'no');
     } else {
         $response = $this->in('Would you like to extract the messages from the CakePHP core?', ['y', 'n'], 'n');
         $this->_extractCore = strtolower($response) === 'y';
     }
     if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
         $this->_exclude = array_merge($this->_exclude, App::path('Plugin'));
     }
     if (!empty($this->params['validation-domain'])) {
         $this->_validationDomain = $this->params['validation-domain'];
     }
     if ($this->_extractCore) {
         $this->_paths[] = CAKE;
     }
     if (isset($this->params['merge'])) {
         $this->_merge = !(strtolower($this->params['merge']) === 'no');
     } else {
         $this->out();
         $response = $this->in('Would you like to merge all domain strings into the default.pot file?', ['y', 'n'], 'n');
         $this->_merge = strtolower($response) === 'y';
     }
     if (empty($this->_files)) {
         $this->_searchFiles();
     }
     $this->_extract();
 }
Exemple #5
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];
     $appPath = App::path('Shell');
     $appShells = $this->_scanDir($appPath[0]);
     $appShells = array_diff($appShells, $skipFiles);
     $shellList = $this->_appendShells('app', $appShells, $shellList);
     $shells = $this->_scanDir(dirname(__DIR__));
     $shells = array_diff($shells, $appShells, $skipFiles, $hiddenCommands);
     $shellList = $this->_appendShells('CORE', $shells, $shellList);
     foreach ($plugins as $plugin) {
         $pluginPath = Plugin::classPath($plugin) . 'Shell';
         $pluginShells = $this->_scanDir($pluginPath);
         $shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
     }
     return array_filter($shellList);
 }
 /**
  * Returns an array with avilable widget identifiers
  *
  * @return array
  */
 public static function getAvailableWidgets()
 {
     $widgets = [];
     $config = Configure::read('Cms.Widgets.availableWidgets');
     if (is_array($config)) {
         return $config;
     }
     $namespace = Configure::read('App.namespace');
     $widgetPaths = App::path('Widget');
     foreach ($widgetPaths as $widgetPath) {
         $appWidgetsFolder = new Folder($widgetPath);
         $contents = $appWidgetsFolder->read(true);
         foreach ($contents[0] as $folderName) {
             $widgetIdentifier = "{$namespace}.{$folderName}";
             if (self::widgetExists($widgetIdentifier)) {
                 $widgets[] = $widgetIdentifier;
             }
         }
     }
     $plugins = Plugin::loaded();
     foreach ($plugins as $plugin) {
         $widgetsPath = Plugin::classPath($plugin) . 'Widget/';
         if (!is_dir($widgetsPath)) {
             continue;
         }
         $pluginWidgetsFolder = new Folder($widgetsPath);
         $contents = $pluginWidgetsFolder->read(true);
         foreach ($contents[0] as $folderName) {
             $widgetIdentifier = "{$plugin}.{$folderName}";
             if (self::widgetExists($widgetIdentifier)) {
                 $widgets[] = $widgetIdentifier;
             }
         }
     }
     $excludedWidgets = Configure::read('Cms.Widgets.excludedWidgets');
     $widgets = array_filter($widgets, function ($widgetIdentifier) use($excludedWidgets) {
         return !in_array($widgetIdentifier, $excludedWidgets);
     });
     return $widgets;
 }
Exemple #7
0
 /**
  * Gets the option parser instance and configures it.
  *
  * @return \Cake\Console\ConsoleOptionParser
  */
 public function getOptionParser()
 {
     $parser = parent::getOptionParser();
     $bakeThemes = [];
     foreach (Plugin::loaded() as $plugin) {
         $path = Plugin::classPath($plugin);
         if (is_dir($path . 'Template' . DS . 'Bake')) {
             $bakeThemes[] = $plugin;
         }
     }
     $parser->description('The Super Bake shell generates plugins, models, views, files and menus ' . 'for your application.' . ' If run with no command line arguments, superBake will guide you through the creation process.' . ' You can use arguments to a quicker generation.' . "\n\n This help system is quite broken, use the docs instead.")->addSubcommand('plugins', ['help' => __d('superBake', 'Creates all the plugins directories skeletons.')])->addSubcommand('mvc', ['help' => __d('superBake', 'Bakes all Models/Controllers/Views, in their specific plugin dirs.')])->addSubcommand('all', ['help' => __d('superBake', 'Bakes all Models/Controllers/Views/menus/files, in their specific plugin dirs, and copies required files. Use with care.')])->addSubcommand('models', ['help' => __d('superBake', 'Bakes all the models, in their specfic plugin dir.')])->addSubcommand('controllers', ['help' => __d('superBake', 'Bakes all controllers in their specific plugin dir.')])->addSubcommand('views', ['help' => __d('superBake', 'Bakes all views, for controllers methods, in their specific plugin dir')])->addSubcommand('pluginMVC', ['help' => __d('superBake', '<pluginName> - Bakes all MVC for a specific plugin.')])->addSubcommand('pluginModels', ['help' => __d('superBake', '<pluginName> - Bakes all models in a plugin.')])->addSubcommand('model', ['help' => __d('superBake', '<pluginName>.<modelName> - Bakes a specific model.')])->addSubcommand('pluginControllers', ['help' => __d('superBake', '<pluginName> - Bakes all controllers in a plugin.')])->addSubcommand('controller', ['help' => __d('superBake', '<pluginName>.<controllerName> - Bakes a specific controller.')])->addSubcommand('pluginViews', ['help' => __d('superBake', '<pluginName> - Bakes all views in a plugin.')])->addSubcommand('controllerViews', ['help' => __d('superBake', '<pluginName>.<ControllerName> - Bakes all views in a plugin.')])->addSubcommand('view', ['help' => __d('superBake', '<pluginName>.<controllerName>.<actionName> - Bakes a specific view.')])->addSubcommand('menus', ['help' => __d('superBake', 'Creates the menu file(s).')])->addSubcommand('files', ['help' => __d('superBake', 'Generates standalone files.')])->addSubcommand('required', ['help' => __d('superBake', 'Copies files and folders.')]);
     foreach ($this->_taskMap as $task => $config) {
         $taskParser = $this->{$task}->getOptionParser();
         $parser->addSubcommand(Inflector::underscore($task), ['help' => $taskParser->description(), 'parser' => $taskParser]);
     }
     return $parser;
 }
Exemple #8
0
 /**
  * Initializes the crud-view template paths
  *
  * @return void
  */
 protected function _setupPaths()
 {
     $paths = Configure::read('App.paths.templates');
     $extraPaths = Configure::read('CrudView.templatePaths');
     if (!empty($extraPaths)) {
         $paths = array_merge($paths, (array) $extraPaths);
     }
     $paths[] = Plugin::classPath('CrudView') . 'Template' . DS;
     Configure::write('App.paths.templates', $paths);
 }
Exemple #9
0
 /**
  * Gets the option parser instance and configures it.
  *
  * @return \Cake\Console\ConsoleOptionParser
  */
 public function getOptionParser()
 {
     $parser = parent::getOptionParser();
     $bakeThemes = [];
     foreach (Plugin::loaded() as $plugin) {
         $path = Plugin::classPath($plugin);
         if (is_dir($path . 'Template' . DS . 'Bake')) {
             $bakeThemes[] = $plugin;
         }
     }
     $parser->description('The Bake script generates controllers, views and models for your application.' . ' If run with no command line arguments, Bake guides the user through the class creation process.' . ' You can customize the generation process by telling Bake where different parts of your application' . ' are using command line arguments.')->addSubcommand('all', ['help' => 'Bake a complete MVC skeleton.'])->addOption('connection', ['help' => 'Database connection to use in conjunction with `bake all`.', 'short' => 'c', 'default' => 'default'])->addOption('theme', ['short' => 't', 'help' => 'The theme to use when baking code.', 'choices' => $bakeThemes]);
     foreach ($this->_taskMap as $task => $config) {
         $taskParser = $this->{$task}->getOptionParser();
         $parser->addSubcommand(Inflector::underscore($task), ['help' => $taskParser->description(), 'parser' => $taskParser]);
     }
     return $parser;
 }
 /**
  * Returns the folders where the file should be looked for according to the locale
  * and package name.
  *
  * @return array The list of folders where the translation file should be looked for
  */
 public function translationsFolders()
 {
     $locale = Locale::parseLocale($this->_locale) + ['region' => null];
     $folders = [implode('_', [$locale['language'], $locale['region']]), $locale['language']];
     // If space is not added after slash, the character after it remains lowercased
     $pluginName = Inflector::camelize(str_replace('/', '/ ', $this->_name));
     $basePath = APP . 'Locale' . DS;
     $searchPath = [];
     foreach ($folders as $folder) {
         $searchPath[] = $basePath . $folder . DS;
     }
     if (Plugin::loaded($pluginName)) {
         $basePath = Plugin::classPath($pluginName) . 'Locale' . DS;
         foreach ($folders as $folder) {
             $searchPath[] = $basePath . $folder . DS;
         }
     }
     return $searchPath;
 }
 /**
  * Gets an instance of AYAH library.
  *
  * @return object
  */
 protected function _getLib()
 {
     require_once Plugin::classPath('Captcha') . 'Lib/ayah.php';
     return new \AYAH(['publisher_key' => $this->config('publisherKey'), 'scoring_key' => $this->config('scoringKey'), 'web_service_host' => 'ws.areyouahuman.com', 'use_curl' => true, 'debug_mode' => Configure::read('debug')]);
 }
<?php

/**
 * Source code for the Database.FormattableBehavior unit test class.
 *
 */
namespace Database\Test\TestCase\Model\Behavior;

use Cake\Core\Plugin;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
require_once Plugin::classPath('Database') . DS . '..' . DS . 'tests' . DS . 'Fixture' . DS . 'items_table.php';
/**
 * The class Database.FormattableBehaviorTest is responsible for testing the
 * Database.FormattableBehavior class.
 *
 * @fixme: be sure to remove App global config for the tests
 */
class FormattableBehaviorTest extends TestCase
{
    /**
     * fixtures
     *
     * @var array
     */
    public $fixtures = ['plugin.Database.Items'];
    /**
     * Original intl.default_locale.
     *
     * @var string
     */
 /**
  * Returns the absolute path to the Widget's base folder.
  *
  * @return string
  */
 public function getWidgetPath()
 {
     if ($this->_plugin) {
         $widgetPath = Plugin::classPath($this->_plugin) . 'Widget/';
     } else {
         $widgetPath = current(App::path('Widget'));
     }
     return $widgetPath . $this->_identifier . '/';
 }
Exemple #14
0
 /**
  * Test that multiple paths can be used in App.paths.templates.
  *
  * @return void
  */
 public function testMultipleAppPaths()
 {
     $viewOptions = ['plugin' => 'TestPlugin', 'name' => 'TestPlugin', 'viewPath' => 'Tests', 'view' => 'index', 'theme' => 'TestTheme'];
     $paths = Configure::read('App.paths.templates');
     $paths[] = Plugin::classPath('TestPlugin') . 'Template' . DS;
     Configure::write('App.paths.templates', $paths);
     $View = new TestView(null, null, null, $viewOptions);
     $paths = $View->paths('TestPlugin');
     $pluginPath = Plugin::path('TestPlugin');
     $themePath = Plugin::path('TestTheme');
     $expected = [$themePath . 'src' . DS . 'Template' . DS . 'Plugin' . DS . 'TestPlugin' . DS, $themePath . 'src' . DS . 'Template' . DS, TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Plugin' . DS . 'TestPlugin' . DS, $pluginPath . 'src' . DS . 'Template' . DS . 'Plugin' . DS . 'TestPlugin' . DS, $pluginPath . 'src' . DS . 'Template' . DS, TEST_APP . 'TestApp' . DS . 'Template' . DS, TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS . 'src' . DS . 'Template' . DS, CAKE . 'Template' . DS];
     $this->assertPathEquals($expected, $paths);
 }
Exemple #15
0
 /**
  * Used to read information stored path
  *
  * Usage:
  *
  * `App::path('Plugin');`
  *
  * Will return the configured paths for plugins. This is a simpler way to access
  * the `App.paths.plugins` configure variable.
  *
  * `App::path('Model/Datasource', 'MyPlugin');`
  *
  * Will return the path for datasources under the 'MyPlugin' plugin.
  *
  * @param string $type type of path
  * @param string $plugin name of plugin
  * @return array
  * @link http://book.cakephp.org/3.0/en/core-libraries/app.html#finding-paths-to-namespaces
  */
 public static function path($type, $plugin = null)
 {
     if ($type === 'Plugin') {
         return (array) Configure::read('App.paths.plugins');
     }
     if (empty($plugin) && $type === 'Locale') {
         return (array) Configure::read('App.paths.locales');
     }
     if (empty($plugin) && $type === 'Template') {
         return (array) Configure::read('App.paths.templates');
     }
     if (!empty($plugin)) {
         return [Plugin::classPath($plugin) . $type . DS];
     }
     return [APP . $type . DS];
 }
 /**
  * Fallback for template location when extending Field UI API.
  *
  * If controller tries to render an unexisting template under its Template
  * directory, then we try to find that view under `Field/Template/FieldUI`
  * directory.
  *
  * ### Example:
  *
  * Suppose you are using this trait to manage fields attached to `Persons`
  * entities. You would probably have a `Person` plugin and a `clean` controller
  * as follow:
  *
  * ```
  * // http://example.com/admin/person/fields_manager
  * Person\Controller\FieldsManagerController::index()
  * ```
  *
  * The above controller action will try to render
  * `/plugins/Person/Template/FieldsManager/index.ctp`. But if does not exists
  * then `<QuickAppsCorePath>/plugins/Field/Template/FieldUI/index.ctp`
  * will be used instead.
  *
  * Of course you may create your own template and skip this fallback
  * functionality.
  *
  * @param \Cake\Event\Event $event the event instance.
  * @return void
  */
 public function beforeRender(Event $event)
 {
     $plugin = Inflector::camelize($event->subject()->request->params['plugin']);
     $controller = Inflector::camelize($event->subject()->request->params['controller']);
     $action = Inflector::underscore($event->subject()->request->params['action']);
     $templatePath = Plugin::classPath($plugin) . "Template/{$controller}/{$action}.ctp";
     if (!is_readable($templatePath)) {
         $alternativeTemplatePath = Plugin::classPath('Field') . 'Template/FieldUI';
         if (is_readable("{$alternativeTemplatePath}/{$action}.ctp")) {
             $this->plugin = 'Field';
             $this->viewBuilder()->templatePath('FieldUI');
         }
     }
     parent::beforeRender($event);
 }
Exemple #17
0
 /**
  * Returns the folders where the file should be looked for according to the locale
  * and package name.
  *
  * @return array The list of folders where the translation file should be looked for
  */
 public function translationsFolders()
 {
     $locale = Locale::parseLocale($this->_locale) + ['region' => null];
     $folders = [implode('_', [$locale['language'], $locale['region']]), $locale['language']];
     $searchPaths = [];
     $localePaths = App::path('Locale');
     if (empty($localePaths)) {
         $localePaths[] = APP . 'Locale' . DIRECTORY_SEPARATOR;
     }
     foreach ($localePaths as $path) {
         foreach ($folders as $folder) {
             $searchPaths[] = $path . $folder . DIRECTORY_SEPARATOR;
         }
     }
     // If space is not added after slash, the character after it remains lowercased
     $pluginName = Inflector::camelize(str_replace('/', '/ ', $this->_name));
     if (Plugin::loaded($pluginName)) {
         $basePath = Plugin::classPath($pluginName) . 'Locale' . DIRECTORY_SEPARATOR;
         foreach ($folders as $folder) {
             $searchPaths[] = $basePath . $folder . DIRECTORY_SEPARATOR;
         }
     }
     return $searchPaths;
 }
 /**
  * Creates a thumbnail for the given image.
  *
  * @param string $filePath Full path to original image file
  * @param string $previewSize A valid preview preset
  * @return false|string Full path to thumbnail file on success, false otherwise
  */
 public static function thumbnail($filePath, $previewSize)
 {
     $filePath = normalizePath($filePath);
     if (!is_readable($filePath)) {
         return false;
     }
     $srcFileName = basename($filePath);
     $srcPath = dirname($filePath) . DS;
     $dstPath = normalizePath("{$srcPath}/.tmb/");
     $previewInfo = static::getPreviews($previewSize);
     require_once Plugin::classPath('Field') . 'Lib/class.upload.php';
     $handle = new \upload($srcPath . $srcFileName);
     if (empty($previewInfo)) {
         $previews = static::getPreviews();
         $previewInfo = reset($previews);
     }
     $dstFileNameBody = static::removeExt("{$previewInfo['width']}x{$previewInfo['height']}_{$srcFileName}");
     $dstFilePath = normalizePath("{$dstPath}/{$dstFileNameBody}.jpg");
     if (is_readable($dstFilePath)) {
         return $dstFilePath;
     }
     $handle->image_x = $previewInfo['width'];
     $handle->image_y = $previewInfo['height'];
     $handle->image_resize = true;
     $handle->image_ratio = false;
     $handle->image_ratio_crop = true;
     $handle->image_convert = 'jpg';
     $handle->file_new_name_body = $dstFileNameBody;
     $handle->process($dstPath);
     if (empty($handle->error)) {
         return $handle->file_dst_pathname;
     }
     return false;
 }
Exemple #19
0
 /**
  * Tests that Plugin::classPath() throws an exception on unknown plugin
  *
  * @return void
  * @expectedException \Cake\Core\Exception\MissingPluginException
  */
 public function testClassPathNotFound()
 {
     Plugin::classPath('TestPlugin');
 }
Exemple #20
0
 /**
  * Get the possible classes for a given type.
  *
  * @param string $namespace The namespace fragment to look for classes in.
  * @return array
  */
 protected function _getClassOptions($namespace)
 {
     $classes = [];
     $base = APP;
     if ($this->plugin) {
         $base = Plugin::classPath($this->plugin);
     }
     $path = $base . str_replace('\\', DS, $namespace);
     $folder = new Folder($path);
     list(, $files) = $folder->read();
     foreach ($files as $file) {
         $classes[] = str_replace('.php', '', $file);
     }
     return $classes;
 }
 /**
  * Gets the option parser instance and configures it.
  *
  * @return \Cake\Console\ConsoleOptionParser
  */
 public function getOptionParser()
 {
     $parser = parent::getOptionParser();
     $bakeThemes = [];
     foreach (Plugin::loaded() as $plugin) {
         $path = Plugin::classPath($plugin);
         if (is_dir($path . 'Template' . DS . 'Bake')) {
             $bakeThemes[] = $plugin;
         }
     }
     $parser->description('The Bake script generates controllers, models and template files for your application.' . ' If run with no command line arguments, Bake guides the user through the class creation process.' . ' You can customize the generation process by telling Bake where different parts of your application' . ' are using command line arguments.')->addSubcommand('all', ['help' => 'Bake a complete MVC skeleton.'])->addOption('everything', ['help' => 'Bake a complete MVC skeleton, using all the available tables. ' . 'Usage: "bake all --everything"', 'default' => false, 'boolean' => true])->addOption('connection', ['help' => 'Database connection to use in conjunction with `bake all`.', 'short' => 'c', 'default' => 'default'])->addOption('force', ['short' => 'f', 'boolean' => true, 'help' => 'Force overwriting existing files without prompting.'])->addOption('plugin', ['short' => 'p', 'help' => 'Plugin to bake into.'])->addOption('prefix', ['help' => 'Prefix to bake controllers and templates into.'])->addOption('theme', ['short' => 't', 'help' => 'The theme to use when baking code.', 'choices' => $bakeThemes]);
     foreach ($this->_taskMap as $task => $config) {
         $taskParser = $this->{$task}->getOptionParser();
         $parser->addSubcommand(Inflector::underscore($task), ['help' => $taskParser->description(), 'parser' => $taskParser]);
     }
     return $parser;
 }
Exemple #22
0
 /**
  * Gets the option parser instance and configures it.
  *
  * @return \Cake\Console\ConsoleOptionParser
  */
 public function getOptionParser()
 {
     $name = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
     $parser = new ConsoleOptionParser($name);
     $bakeThemes = [];
     foreach (Plugin::loaded() as $plugin) {
         $path = Plugin::classPath($plugin);
         if (is_dir($path . 'Template' . DS . 'Bake')) {
             $bakeThemes[] = $plugin;
         }
     }
     $parser->description('Bake seed class.')->addOption('plugin', ['short' => 'p', 'help' => 'Plugin to bake into.'])->addOption('force', ['short' => 'f', 'boolean' => true, 'help' => 'Force overwriting existing files without prompting.'])->addOption('connection', ['short' => 'c', 'default' => 'default', 'help' => 'The datasource connection to get data from.'])->addOption('table', ['help' => 'The database table to use.'])->addOption('theme', ['short' => 't', 'help' => 'The theme to use when baking code.', 'choices' => $bakeThemes])->addArgument('name', ['help' => 'Name of the seed to bake. Can use Plugin.name to bake plugin models.']);
     return $parser;
 }
Exemple #23
0
 /**
  * Get twig filesystem loader
  *
  * @return Twig_Loader_Filesystem
  * @throws \Twig_Error_Loader
  */
 protected function getFilesystemLoader()
 {
     $mainPath = CAKE . 'Template';
     $appPath = APP . 'Template';
     $this->paths[] = ['path' => $mainPath, 'namespace' => Twig_Loader_Filesystem::MAIN_NAMESPACE];
     $this->paths[] = ['path' => $appPath, 'namespace' => Twig_Loader_Filesystem::MAIN_NAMESPACE];
     $filesystemLoader = new Twig_Loader_Filesystem([$appPath, $mainPath]);
     foreach (Plugin::loaded() as $plugin) {
         $pluginTemplatePath = Plugin::classPath($plugin) . 'Template';
         $appPluginPath = $appPath . 'Plugin' . DS . $plugin;
         if (is_dir($pluginTemplatePath)) {
             $this->paths[] = ['path' => $pluginTemplatePath, 'namespace' => $this->getPluginNamespace($plugin)];
             if ($this->theme) {
                 $filesystemLoader->addPath(Plugin::classPath($this->theme) . 'Template', Inflector::underscore($plugin));
             }
             $filesystemLoader->addPath($pluginTemplatePath, $this->getPluginNamespace($plugin));
             $filesystemLoader->addPath($appPath, $this->getPluginNamespace($plugin));
             $filesystemLoader->addPath($mainPath, $this->getPluginNamespace($plugin));
         }
         if (is_dir($appPluginPath)) {
             $this->paths[] = ['path' => $appPath, 'namespace' => $this->getPluginNamespace($plugin)];
             $filesystemLoader->addPath($appPluginPath, $this->getPluginNamespace($plugin));
         }
     }
     return $filesystemLoader;
 }
Exemple #24
0
 /**
  * Execution method always used for tasks
  *
  * @return void
  */
 public function main()
 {
     if (!empty($this->params['exclude'])) {
         $this->_exclude = explode(',', $this->params['exclude']);
     }
     if (isset($this->params['files']) && !is_array($this->params['files'])) {
         $this->_files = explode(',', $this->params['files']);
     }
     if (isset($this->params['paths'])) {
         $this->_paths = explode(',', $this->params['paths']);
     } elseif (isset($this->params['plugin'])) {
         $plugin = Inflector::camelize($this->params['plugin']);
         if (!Plugin::loaded($plugin)) {
             Plugin::load($plugin);
         }
         $this->_paths = [Plugin::classPath($plugin)];
         $this->params['plugin'] = $plugin;
     } else {
         $this->_getPaths();
     }
     if (isset($this->params['extract-core'])) {
         $this->_extractCore = !(strtolower($this->params['extract-core']) === 'no');
     } else {
         $response = $this->in('Would you like to extract the messages from the CakePHP core?', ['y', 'n'], 'n');
         $this->_extractCore = strtolower($response) === 'y';
     }
     if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
         $this->_exclude = array_merge($this->_exclude, App::path('Plugin'));
     }
     if (!empty($this->params['validation-domain'])) {
         $this->_validationDomain = $this->params['validation-domain'];
     }
     if ($this->_extractCore) {
         $this->_paths[] = CAKE;
     }
     if (isset($this->params['output'])) {
         $this->_output = $this->params['output'];
     } elseif (isset($this->params['plugin'])) {
         $this->_output = $this->_paths[0] . 'Locale';
     } else {
         $message = "What is the path you would like to output?\n[Q]uit";
         while (true) {
             $response = $this->in($message, null, rtrim($this->_paths[0], DS) . DS . 'Locale');
             if (strtoupper($response) === 'Q') {
                 $this->err('Extract Aborted');
                 $this->_stop();
                 return;
             } elseif ($this->_isPathUsable($response)) {
                 $this->_output = $response . DS;
                 break;
             } else {
                 $this->err('');
                 $this->err('<error>The directory path you supplied was ' . 'not found. Please try again.</error>');
             }
             $this->out();
         }
     }
     if (isset($this->params['merge'])) {
         $this->_merge = !(strtolower($this->params['merge']) === 'no');
     } else {
         $this->out();
         $response = $this->in('Would you like to merge all domain strings into the default.pot file?', ['y', 'n'], 'n');
         $this->_merge = strtolower($response) === 'y';
     }
     if (empty($this->_files)) {
         $this->_searchFiles();
     }
     $this->_output = rtrim($this->_output, DS) . DS;
     if (!$this->_isPathUsable($this->_output)) {
         $this->err(sprintf('The output directory %s was not found or writable.', $this->_output));
         $this->_stop();
         return;
     }
     $this->_extract();
 }
 /**
  * Path for Table folder
  *
  * @param string $pluginName Plugin name if exists
  * @return string : path to Table Folder. Default to App Table Path
  */
 public function getModelPath($pluginName = null)
 {
     if (!is_null($pluginName) && Plugin::loaded($pluginName)) {
         return Plugin::classPath($pluginName) . 'Model' . DS . 'Table' . DS;
     }
     return APP . 'Model' . DS . 'Table' . DS;
 }
Exemple #26
-1
 /**
  * Get the option parser for this task.
  *
  * This base class method sets up some commonly used options.
  *
  * @return \Cake\Console\ConsoleOptionParser
  */
 public function getOptionParser()
 {
     $parser = parent::getOptionParser();
     $bakeThemes = [];
     foreach (Plugin::loaded() as $plugin) {
         $path = Plugin::classPath($plugin);
         if (is_dir($path . 'Template' . DS . 'Bake')) {
             $bakeThemes[] = $plugin;
         }
     }
     $parser->addOption('plugin', ['short' => 'p', 'help' => 'Plugin to bake into.'])->addOption('force', ['short' => 'f', 'boolean' => true, 'help' => 'Force overwriting existing files without prompting.'])->addOption('connection', ['short' => 'c', 'default' => 'default', 'help' => 'The datasource connection to get data from.'])->addOption('theme', ['short' => 't', 'help' => 'The theme to use when baking code.', 'choices' => $bakeThemes]);
     return $parser;
 }