26faf2ba624576694136fae9b3f4332811dba3a3

Author: AD7six

Date: 2009-02-10 00:30:42 +0100

initial commit

diff --git a/.gitignore b/.gitignore index e69de29..cdc7698 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +api_config.ini +errors.err +*.swp +*.swo +*~ +config/core.php +config/database.php +tmp/* \ No newline at end of file diff --git a/vendors/mi.php b/vendors/mi.php new file mode 100644 index 0000000..498df68 --- /dev/null +++ b/vendors/mi.php @@ -0,0 +1,479 @@ +<?php +/* SVN FILE: $Id: mi.php 778 2009-02-03 11:49:18Z ad7six $ */ +/** + * Short description for mi.php + * + * Long description for mi.php + * + * PHP versions 4 and 5 + * + * Copyright (c) 2008, Andy Dawson + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2008, Andy Dawson + * @link www.ad7six.com + * @package base + * @subpackage base.vendors + * @since v 1.0 + * @version $Revision: 778 $ + * @modifiedby $LastChangedBy: ad7six $ + * @lastmodified $Date: 2009-02-03 12:49:18 +0100 (Tue, 03 Feb 2009) $ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +/** + * Mi class + * + * A utility class + * + * @package base + * @subpackage base.vendors + */ +class Mi { +/** + * actions method + * + * @param mixed $controller + * @param string $diffTo + * @param array $excludePatterns + * @return void + * @access public + */ + public function actions($controller, $type = 'public', $plugin = false, $diffTo = 'Controller') { + if ($type == 'admin') { + $excludePatterns = array('/^(?!(admin)).*/'); + } else { + $excludePatterns = array('/admin_.*/'); + } + if (is_string($controller)) { + App::import('Core', 'Controller'); + App::import('Controller', ($plugin?$plugin . '.':'') . $controller); + $controller .= 'Controller'; + } + $return = array(); + $parent = get_parent_class($controller); + while ($controller !== $diffTo) { + $methods = array_diff(get_class_methods($controller), get_class_methods($parent)); + $system = array('hashPasswords', 'password'); + $methods = array_diff($methods, $system); + foreach ($methods as $i => $name) { + $skip = false; + if ($name[0] == '_') { + unset ($methods[$i]); + $skip = true; + continue; + } + foreach ($excludePatterns as $pattern) { + if (preg_match($pattern, $name)) { + unset ($methods[$i]); + $skip = true; + continue; + } + } + if (isset($return[$name])) { + $skip = true; + continue; + } + if (!$skip) { + $return[$name] = $controller . '::' . $name; + } + } + $controller = get_parent_class($controller); + $parent = get_parent_class($controller); + } + ksort($return); + return array_flip($return); + } +/** + * components method + * + * @param bool $plugin + * @param array $exclude + * @return void + * @access public + */ + public function components($plugin = false, $exclude = array('abstract', 'sunset')) { + $files = array(); + if ($plugin) { + $paths = Configure::read('pluginPaths'); + foreach ($paths as &$path) { + $path .= Inflector::underscore($plugin) . '/controllers/components/'; + } + } else { + $paths = Configure::read('componentPaths'); + } + foreach ($paths as $path) { + if (!strpos($path, 'components')) { + continue; + } + $files = Set::merge($files, Mi::files($path, $exclude)); + } + $return = array(); + foreach ($files as $file) { + $name = Inflector::Camelize(str_replace('.php', '', basename($file))); + if (isset($return[$name])) { + continue; + } + $return[$name] = $file; + } + ksort($return); + return array_flip($return); + } +/** + * behaviors method + * + * @param bool $plugin + * @param array $exclude + * @return void + * @access public + */ + public function behaviors($plugin = false, $exclude = array('abstract', 'sunset')) { + if ($plugin) { + $paths = Configure::read('pluginPaths'); + foreach ($paths as &$path) { + $path .= Inflector::underscore($plugin) . '/models/behaviors/'; + } + } else { + $paths = Configure::read('behaviorPaths'); + } + $files = array(); + foreach ($paths as $path) { + if (!strpos($path, 'behaviors')) { + continue; + } + $files = Set::merge($files, Mi::Files($path, $exclude)); + } + $return = array(); + foreach ($files as $file) { + $name = Inflector::Camelize(str_replace('.php', '', basename($file))); + if (isset($return[$name])) { + continue; + } + $return[$name] = $file; + } + ksort($return); + return array_flip($return); + } +/** + * controllers method + * + * @param bool $plugin + * @return void + * @access public + */ + public function controllers($plugin = false, $exclude = array('abstract', 'components', 'sunset')) { + $files = array(); + if ($plugin) { + $paths = Configure::read('pluginPaths'); + foreach ($paths as &$path) { + $path .= Inflector::underscore($plugin) . '/controllers/'; + } + } else { + $paths = Configure::read('controllerPaths'); + } + foreach ($paths as $path) { + if (!strpos($path, 'controllers')) { + continue; + } + $files = Set::merge($files, Mi::files($path, $exclude)); + } + $return = array(); + foreach ($files as $file) { + $name = Inflector::Camelize(str_replace('_controller.php', '', basename($file))); + if (isset($return[$name])) { + continue; + } + $return[$name] = $file; + } + ksort($return); + return array_flip($return); + } +/** + * datasources method + * + * @param bool $plugin + * @param array $exclude + * @param 'sunset') $'sunset') + * @return void + * @access public + */ + public function datasources($plugin = false, $exclude = array('abstract', 'sunset')) { + if ($plugin) { + $paths = Configure::read('pluginPaths'); + foreach ($paths as &$path) { + $path .= Inflector::underscore($plugin) . '/models/datasources/'; + } + } else { + $paths = Configure::read('modelPaths'); + foreach ($paths as &$path) { + $path .= 'datasources'; + } + } + $files = array(); + foreach ($paths as $path) { + $files = Set::merge($files, Mi::Files($path, $exclude)); + } + $return = array(); + foreach ($files as $file) { + $name = Inflector::Camelize(str_replace('.php', '', basename($file))); + if (isset($return[$name])) { + continue; + } + $return[$name] = $file; + } + ksort($return); + return array_flip($return); + } + +/** + * files method + * + * @param mixed $path + * @param array $excludePaths + * @param string $pattern + * @return void + * @access public + */ + public function files($path = null, $excludePaths = array(), $pattern = '.*php') { + $folder = new Folder($path); + $return = $folder->findRecursive($pattern); + foreach ((array)$excludePaths as $excludePath) { + if (!is_dir($path . $excludePath)) { + continue; + } + $folder = new Folder($path . $excludePath); + $return = array_diff($return, $folder->findRecursive($pattern)); + } + return $return; + } +/** + * helpers method + * + * @param bool $plugin + * @param array $exclude + * @param 'sunset') $'sunset') + * @return void + * @access public + */ + public function helpers($plugin = false, $exclude = array('abstract', 'sunset')) { + if ($plugin) { + $paths = Configure::read('pluginPaths'); + foreach ($paths as &$path) { + $path .= Inflector::underscore($plugin) . '/views/helpers/'; + } + } else { + $paths = Configure::read('helperPaths'); + } + $files = array(); + foreach ($paths as $path) { + if (!strpos($path, 'helpers')) { + continue; + } + $files = Set::merge($files, Mi::Files($path, $exclude)); + } + $return = array(); + foreach ($files as $file) { + $name = Inflector::Camelize(str_replace('.php', '', basename($file))); + if (isset($return[$name])) { + continue; + } + $return[$name] = $file; + } + ksort($return); + return array_flip($return); + } + +/** + * models method + * + * @param bool $plugin + * @return void + * @access public + */ + public function models($plugin = false, $exclude = array('abstract', 'behaviors', 'datasources', 'sunset')) { + if ($plugin) { + $paths = Configure::read('pluginPaths'); + foreach ($paths as &$path) { + $path .= Inflector::underscore($plugin) . '/models/'; + } + } else { + $paths = Configure::read('modelPaths'); + } + $files = array(); + foreach ($paths as $path) { + if (!strpos($path, 'models')) { + continue; + } + $files = Set::merge($files, Mi::Files($path, $exclude)); + } + $return = array(); + App::import('Core', 'Model'); + App::import('Model', 'AppModel'); + $connections['base'] = Mi::tables('base'); + foreach ($files as $file) { + $name = Inflector::Camelize(str_replace('.php', '', basename($file))); + if (isset($return[$name])) { + continue; + } + if (!class_exists($name)) { + include_once($file); + } + $vars = get_class_vars($name); + if (!$vars) { + continue; + } + if (array_key_exists('useTable', $vars) && $vars['useTable'] !== false) { + if (empty($vars['userDbConfig'])) { + continue; + } + $config = $vars['useDbConfig']; + if (!isset($connections[$config])) { + $connections[$config] = Mi::tables($config); + } + $tables = $connections[$config]; + $table = $vars['tablePrefix']; + if ($vars['useTable']) { + $table .= $vars['useTable']; + } else { + $table .= Inflector::tableize($name); + } + if (!in_array($table, $connections[$config]) && !in_array($table, $connections['base'])) { + continue; + } + } + $return[$name] = $file; + } + ksort($return); + return array_flip($return); + } +/** + * objects method + * + * @param mixed $type + * @static + * @return void + * @access public + */ + static function objects($type) { + $params = func_get_args(); + unset($params[0]); + $function = Inflector::pluralize(Inflector::Classify($type)); + $function[0] = low($function[0]); + return call_user_func_array(array('Mi', $function), $params); + } +/** + * plugins method + * + * @return void + * @access public + */ + public function plugins() { + $paths = Configure::read('pluginPaths'); + $return = array(); + foreach ($paths as $path) { + $folder = new Folder($path); + list($folders) = $folder->ls(); + foreach ($folders as $name) { + if ($name[0] === '.' || isset($return[$name])) { + continue; + } + $return[$name] = $path . $name; + } + } + ksort($return); + return array_flip($return); + } +/** + * tables method + * + * @param string $useDbConfig + * @return void + * @access public + */ + public function tables($useDbConfig = 'default') { + if ($useDbConfig == '*') { + $connections = get_class_vars('DATABASE_CONFIG'); + $return = array(); + foreach ($connections as $useDbConfig => $_) { + $return = array_merge($return, Mi::tables($useDbConfig)); + } + $return = array_flip($return); + ksort($return); + $return = array_flip($return); + return $return; + } + if (!$useDbConfig) { + return array(); + } + $connections = get_class_vars('DATABASE_CONFIG'); + if (!isset($connections[$useDbConfig])) { + return array(); + } + $db =& ConnectionManager::getDataSource($useDbConfig); + if (!$db) { + return array(); + } + $usePrefix = empty($db->config['prefix']) ? '': $db->config['prefix']; + $tables = array(); + if ($usePrefix) { + foreach ($db->listSources() as $table) { + if (!strncmp($table, $usePrefix, strlen($usePrefix))) { + $tables[$useDbConfig . '::' . $table] = substr($table, strlen($usePrefix)); + } + } + } else { + $_tables = $db->listSources(); + foreach ($_tables as $table) { + $tables[$useDbConfig . '::' . $table] = $table; + } + } + return $tables; + } +/** + * views method + * + * @param mixed $controllerName + * @param mixed $plugin + * @param array $excludePatterns + * @return void + * @access public + */ + function views($controllerName, $plugin = null, $excludePatterns = array('/admin.*/'), $nameOnly = true) { + if ($plugin) { + $paths = Configure::read('pluginPaths'); + foreach ($paths as &$path) { + $path .= Inflector::underscore($plugin) . '/views/' . Inflector::underscore($controllerName); + } + } else { + $paths = Configure::read('viewPaths'); + foreach ($paths as &$path) { + $path .= Inflector::underscore($controllerName); + } + } + $files = array(); + foreach ($paths as $path) { + if (!strpos($path, 'views')) { + continue; + } + $files = Set::merge($files, Mi::files($path, null, '.*ctp')); + } + $return = array(); + foreach ($files as $file) { + if ($nameOnly) { + $name = str_replace('.ctp', '', basename($file)); + } else { + $name = preg_replace('@^.*/views/@', '', $file); + $name = str_replace('.ctp', '', $name); + } + if (isset($return[$name])) { + continue; + } + $return[$name] = $file; + } + ksort($return); + return array_flip($return); + } +} +?> \ No newline at end of file diff --git a/vendors/shells/editor.php b/vendors/shells/editor.php new file mode 100644 index 0000000..ede1967 --- /dev/null +++ b/vendors/shells/editor.php @@ -0,0 +1,697 @@ +<?php +/* SVN FILE: $Id: editor.php 787 2009-02-09 22:46:23Z ad7six $ */ +/** + * Short description for editor.php + * + * Long description for editor.php + * + * PHP version 4 and 5 + * + * Copyright (c) 2009, YourNameOrCompany + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2009, YourNameOrCompany + * @link www.yoursite.com + * @package base + * @subpackage base.vendors.shells + * @since v 1.0 (09-Feb-2009) + * @version $Revision: 787 $ + * @modifiedby $LastChangedBy: ad7six $ + * @lastmodified $Date: 2009-02-09 23:46:23 +0100 (Mon, 09 Feb 2009) $ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +/** + * EditorShell class + * + * @uses Shell + * @package base + * @subpackage base.vendors.shells + */ +class EditorShell extends Shell { +/** + * settings property + * + * @var array + * @access public + */ + public $settings = array( + 'versionControl' => 'svn', // TODO used or not? + 'configPaths' => array(), + 'base' => null, + 'signatureFiles' => array( + 'app' => 'DSconfigDSroutes.php', + 'cake' => 'DScakeDSbasics.php' + ), + ); +/** + * initialized property + * + * $this->out() messages are suppressed before the main function of this shell is run. This prevents the normal + * header "--- ... Welcome to the console ...---" messages from being output, aiding parsing of responses + * + * @var bool false + * @access private + */ + private $__initialized = false; +/** + * regex property + * + * Regexes used by the class + * + * @var array + * @access private + */ + private $__regex = array( + 'class' => '/^\s*(abstract\s*)?(?:class|interface)\s+(\w+)*\s*(?:extends\s+(\w+))?(?:\s*implements\s*(\w+))?[^\{]*/', + 'property' => '/^\s*(var|private|protected|public)\s*\$(\w+)\s*=\s*([^;]*);?\s*$/', + 'function' => '/^\s*(private|protected|public)?\s*function\s*(\w+)\s*\((.*)\)\s{?/', + 'params' => '/\$(\w+)\s*(?:=\s*)?([^,\s]+)?\s*,?/', + 'array' => '/^array/', + 'float' => '/^[0-9]*\.[0-9]+/', + 'int' => '/^[0-9]+/', + 'string' => '/[\'"]/', + 'bool' => '/(true|false)/', + ); +/** + * viewVars property + * + * Additional variables used when rendering a doc block + * + * @var array + * @access private + */ + private $__viewVars = array(); +/** + * help method + * + * @return void + * @access public + */ + public function help() { + $this->out('Editor Shell. The workhorse for any and all editor plugins. Usage:'); + if (!empty($this->args[0])) { + switch (low($this->args[0])) { + case 'inflect': + $this->out('cake editor inflect camelize <string>'); + $this->out('cake editor inflect type <string>'); + $this->out('cake editor inflect humanize <string>'); + $this->out('cake editor inflect pluralize <string>'); + $this->out('cake editor inflect singularize <string>'); + $this->out('cake editor inflect slug <string>'); + $this->out('cake editor inflect tableize <string>'); + $this->out('cake editor inflect underscore <string>'); + $this->out('cake editor inflect variable <string>'); + $this->out('You can also chain mulitlpe calls together:'); + $this->out('cake editor inflect camelize underscore <string>'); + $this->hr(); + return; + case 'paths': + $this->out('cake editor paths controllers'); + $this->out('cake editor paths models'); + $this->out('cake editor paths views <controllername>'); + $this->hr(); + return; + case 'path': + $this->out('cake editor path controller <name>'); + $this->out('cake editor path model <name>'); + $this->hr(); + return; + case 'setup': + $this->out('cake editor setup'); + $this->out(' - If called from the an app folder, will write the config files for that app'); + $this->out(' - Otherwise, will write the default config files'); + $this->hr(); + return; + + default: + debug ('cake editor ' . implode($this->args, ' ')); + $this->out(__('Sorry, no specific help on that', true)); + } + } + $this->out('cake editor help'); + $this->out(' - this text'); + $this->out('cake editor base <filepath>'); + $this->out(' - Return the base app or core path'); + $this->out('cake editor project <filepath>'); + $this->out(' - Return the project and subproject for the current file'); + $this->out('cake editor inflect <method> <string>'); + $this->out(' - Return the result of calling Inflector::<method>(<string>)'); + $this->out('cake editor paths <type>'); + $this->out(' - Return the names and paths to all <type> files. Return is tab delimited'); + $this->out('cake editor path <type> <name>'); + $this->out(' - Return the filepath to the <type> <name>'); + $this->out('cake editor setup'); + $this->out(' - Write config files'); + $this->hr(); + } +/** + * initialize method + * + * @return void + * @access public + */ + public function initialize() { + foreach ($this->settings['signatureFiles'] as $key => &$val) { + $val = str_replace('DS', DS, $val); + } + $this->settings['configPaths'] = array(CAKE_CORE_INCLUDE_PATH); + if (file_exists(CONFIGS . 'routes.php')) { + $this->settings['configPaths'][] = CONFIGS; + } + App::import('Core', 'Controller'); + $this->Controller = new Controller(); + $this->Controller->layout = false; + $this->Controller->viewPath = 'default'; // TODO configure this + App::import('Controller', 'AppController'); + App::import('vendor', 'Mi'); + return true; + } +/** + * main method + * + * Enable the out method, and send initial response marker + * Call the requested method + * + * @return void + * @access public + */ + public function main() { + $this->__initialized = true; + $this->log($this); + $this->out('--response--'); + $shortKeys = array('e' => 'exclude'); + foreach ($this->params as $key => $value) { + if (in_array($key, array('app', 'root', 'working'))) { + $this->settings[$key] = $value; + continue; + } + if (isset($shortKeys[$key])) { + $key = $shortKeys[$key]; + } + if (isset($this->$key) && is_array($this->$key)) { + $value = explode(',', $value); + } + $this->$key = $value; + } + if(!$this->args || low($this->args[0]) == 'help') { + $this->help(); + return; + } + $method = '_' . low($this->args[0]); + if (!method_exists($this, $method)) { + $this->help(); + return; + } + return $this->$method(); + } +/** + * out method + * + * Suppress the normal console header + * + * @param mixed $string + * @return void + * @access public + */ + public function out($string) { + if (!$this->__initialized) { + return; + } + parent::out($string); + } +/** + * base method + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _base($return = false) { + if ($this->settings['base']) { + return $this->_out($this->settings['base'], $return); + } + $path = $this->__path(); + $base = null; + foreach ($this->settings['signatureFiles'] as $signatureFile) { + $_path = $path; + while (empty($base) && $_path !== dirname($_path)) { + if (file_exists($_path . $signatureFile)) { + $base = $_path; + } + $_path = dirname($_path); + } + if ($base) { + break; + } + } + $this->settings['base'] = $base; + return $this->_out($this->settings['base'], $return); + } +/** + * doc method + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _doc($return = false) { + if (empty($this->args[1])) { + return $this->help(); + } + $file = $this->args[1]; + $type = $this->_type($file); + $line = $lineNumber = $lineType = null; + if (isset($this->args[2])) { + $line = $this->args[2]; + } + if (isset($this->args[3])) { + $lineNumber = $this->args[3]; + } + if ($lineNumber == 1) { + $this->__setViewVars(); + if ($type === 'template') { + $this->Controller->render('view_file_header'); + } else { + $this->Controller->render('class_file_header'); + } + } else { + $lineType = $this->__lineType($line, $file, $lineNumber); + if ($lineType) { + $this->__setViewVars(); + $this->Controller->render($lineType . '_doc'); + } + } + if ($this->Controller->output) { + $out = $this->Controller->output; + $this->Controller->output = null; + return $this->_out($out, $return); + } + // TODO temporary debug + return 'No Docs for Line: "' . $line . '" lineNumber:' . $lineNumber; + } +/** + * docHead method + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _docHead($return = false) { + if (empty($this->args[1])) { + return $this->help(); + } + $file = $this->args[1]; + $type = $this->_type($file); + $this->__setViewVars('docHead'); + if ($type === 'template') { + $this->Controller->render('view_file_header'); + } else { + $this->Controller->render('class_file_header'); + } + $out = $this->Controller->output; + $this->Controller->output = null; + return $this->_out($out, $return); + } +/** + * inflect method + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _inflect($return = false) { + if (empty($this->args[2])) { + return $this->help(); + } + $methods = $this->args; + array_shift($methods); + $string = array_pop($methods); + $methods = array_reverse($methods); + foreach ($methods as $method) { + if (!method_exists('Inflector', $method)) { + $this->out('Inflector::' . $method . '() doesn\'t exist'); + return $this->help(); + } + $string = Inflector::$method($string); + } + return $this->_out($string, $return); + } +/** + * model method + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _model($return = false) { + $class = $this->_type(true); + $names = array(); + $pluginPath = ''; + if ($class === 'controller') { + $file = $this->args[1]; + $controller = str_replace('_controller.php', '', basename($this->args[1])); + if (App::import('Controller', $pluginPath . $controller)) { + $controller .= 'Controller'; + $Class = new $controller(); + $Class->__mergeVars(); // TODO visiblity violation + $names = $Class->uses; + if(!$names) { + $names = array($Class->modelClass); } } if(!$names) { + $names = array(Inflector::type(str_replace('Controller', '', $controller))); + } + $models = array_flip(Mi::models()); + foreach ($names as &$name) { + if (isset($models[$name])) { + $name .= "\t" . $models[$name]; + } else { + $name .= "\t" . MODELS . Inflector::underscore($name) . '.php'; + } + } + return $this->_out($names, $return); + } + $this->_out('???', $return); + } +/** + * out method + * + * Return the passed arg if $return is true, otherwise send to the calling program + * one line at a time + * + * @param array $response array() + * @param bool $return false + * @return void + * @access protected + */ + protected function _out($response = array(), $return = false) { + if ($return) { + return $response; + } + foreach ((array)$response as $row) { + $this->out($row); + } + } +/** + * package method + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _package($return = false) { + $path = $this->__path(); + $this->_base(true); + $package = $subPackage = ''; + $relativePath = explode(DS, str_replace($this->settings['base'] . DS, '', $path)); + if ($this->settings['app']) { + if ($this->settings['app'] !== 'app') { + $package = $subPackage = $this->settings['app']; + } else { + $package = $subPackage = array_pop(explode(DS, $this->settings['base'])); + } + } + if ($relativePath) { + $subPackage .= '.' . implode($relativePath, '.'); + } + return $this->_out(array($package, $subPackage), $return); + } +/** + * path method + * + * Return the path to the existing matching file (controller for x) or return the path to the file where it should be created + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _path($return = false) { + if (empty($this->args[2])) { + return $this->help(); + } + list($_, $type, $name) = $this->args; + $function = Inflector::pluralize(Inflector::Classify($type)); + $function[0] = low($function[0]); + $results = call_user_func_array(array('Mi', $function), array()); + $results = array_flip($results); + if (isset($results[$name])) { + return $this->_out($results[$name], $return); + } + $name = Inflector::underscore($name); + $map = array( + 'controllers' => 'controllers' . DS . $name . '_controller.php', + 'components' => 'controllers' . DS . 'components' . DS . $name . '.php', + 'models' => 'models' . DS . $name . '.php', + 'behaviors' => 'models' . DS . 'behaviors' . DS . $name . '.php', + 'datasources' => 'models' . DS . 'datasources' . DS . $name . '.php', + 'views' => 'views' . DS . $name . '.ctp', + 'elements' => 'views' . DS . 'elements' . DS . $name . '.ctp', + 'emails' => 'views' . DS . 'elements' . DS . 'emails' . DS . $name . '.ctp', + 'layouts' => 'views' . DS . 'layouts' . DS . $name . '.ctp', + 'helpers' => 'views' . DS . 'helpers' . DS . $name . '.ctp', + ); + $partialPath = $map[$function]; + $path = $this->settings['working'] . DS . $partialPath; + return $this->_out($path, $return); + } +/** + * paths method + * + * Return the paths to all files of the requested type. Returns a tab delimited list of the form: + * Foos /full/path/to/foos_controller.php + * Bars /full/different/path/to/vendor/included/bars_controller.php + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _paths($return = false) { + if (empty($this->args[1])) { + return $this->help(); + } + $function = Inflector::pluralize(Inflector::Classify($this->args[1])); + $function[0] = low($function[0]); + $args = $this->args; + array_shift($args); + array_shift($args); + $results = call_user_func_array(array('Mi', $function), $args); + if ($return) { + return $results; + } + foreach ($results as $path => $name) { + $this->_out($name . "\t" . $path, false); + } + } +/** + * setup method + * + * @param bool $return false + * @return void + * @access protected + */ + protected function _setup($return = false) { + if (!empty($this->args[1])) { + $path = $this->args[1]; + } else { + foreach ($this->settings['configPaths'] as $path) { + $path = rtrim($path, DS) . DS . 'editor_config.php'; + if (file_exists($path)) { + break; + } + } + } + $this->__writeConfig(array('user' => '"YourName"'), $path, false); + } +/** + * type method + * + * @param bool $return false + * @return void + * @access protected + */ + + protected function _type($return = false) { + $file = $this->args[1]; + if (file_exists($file)) { + $file = realpath($file); + } + $ext = substr($file, strrpos($file, '.') + 1); + if ($ext === 'ctp') { + return $this->_out('template', $return); + } elseif (strpos($file, '_controller.')) { + return $this->_out('controller', $return); + } elseif (strpos($file, '_model.')) { + return $this->_out('model', $return); + } elseif (strpos($file, '_helper.')) { + return $this->_out('helper', $return); + } + $types = array('helper', 'behavior', 'datasource', 'model', 'component', 'controller'); + $paths = Configure::read('pluginPaths'); + foreach ($paths as $path) { + if (!strpos($file, $path)) { + continue; + } + $path = str_replace($path, '', $file); + foreach ($types as $type) { + if (strpos(Inflector::pluralize($type) . DS, $file) !== false) { + return $this->_out($type, $return); + } + } + } + foreach ($types as $type) { + $paths = Configure::read($type . 'Paths'); + foreach ($paths as $path) { + if ($path === APP) { + continue; + } + if (strpos($file, $path) === 0) { + return $this->_out($type, $return); + } + } + } + return $this->_out('php', $return); + } +/** + * lineType method + * + * @param string $line '' + * @return void + * @access private + */ + private function __lineType($line = '') { + if (preg_match($this->__regex['class'], $line, $match)) { + $abstract = $match[1]; + $name = $match[2]; + if (isset($match[3])) { + $uses = $match[3]; + } else { + $uses = false; + } + $this->__viewVars = compact('abstract', 'name', 'uses'); + return 'class'; + } elseif (preg_match($this->__regex['property'], $line, $match)) { + $visibility = $this->__varVisiblity($match[1], $match[2]); + $name = ltrim($match[2], '_'); + $type = $this->__varType($match[3]); + + if ($type === 'array') { + $default = false; + } else { + $default = $match[3]; + } + $this->__viewVars = compact('visibility', 'name', 'type', 'default'); + return 'property'; + } elseif (preg_match($this->__regex['function'], $line, $match)) { + $visibility = $this->__varVisiblity($match[1], $match[2]); + $name = ltrim($match[2], '_'); + $params = array(); + preg_match_all($this->__regex['params'], $match[3], $paramMatch); + foreach ($paramMatch[1] as $key => $param) { + $params[$key]['name'] = $param; + $params[$key]['type'] = $this->__varType($paramMatch[2][$key]); + $params[$key]['default'] = $paramMatch[2][$key]; + } + $this->__viewVars = compact('visibility', 'name', 'type', 'params'); + return 'function'; + } + return ''; + } +/** + * path method + * + * Return the working path for the current request + * + * @return void + * @access private + */ + private function __path() { + if (!empty($this->args[1])) { + $path = $this->args[1]; + if ($path[0] != DS) { + $path = $this->params['working'] . DS . $path; + } + if (is_file($path) && !is_dir($path)) { + $path = dirname($path); + } + } else { + $path = $this->params['working']; + } + return $path; + } +/** + * setViewVars method + * + * @return void + * @access private + */ + private function __setViewVars() { + $nl = "\n"; // TODO configure or detect + $description[] = 'Short description for ' . basename($this->args[1]); + $description[] = ''; + $description[] = 'Long description for ' . basename($this->args[1]); + list($package, $subPackage) = $this->_package(true); + $this->Controller->set(compact('nl', 'description', 'package', 'subPackage')); + $this->Controller->set($this->__viewVars); + } +/** + * var method + * + * @param mixed $var + * @return void + * @access private + */ + private function __varType($var) { + if (preg_match($this->__regex['array'], $var)) { + return 'array'; + } elseif (preg_match($this->__regex['float'], $var)) { + return 'float'; + } elseif (preg_match($this->__regex['int'], $var)) { + return 'int'; + } elseif (preg_match($this->__regex['string'], $var)) { + return 'string'; + } elseif (preg_match($this->__regex['bool'], $var)) { + return 'bool'; + } + return 'mixed'; + } +/** + * name method + * + * @param mixed $visiblity + * @param mixed $name + * @return void + * @access private + */ + private function __varVisiblity($visiblity, $name) { + if (!$visiblity || $visiblity === 'var') { + if ($name[1] === '_') { + return 'private'; + } elseif ($name[0] === '_') { + return 'protected'; + } + return 'public'; + } + return $visiblity; + } +/** + * writeConfig method + * + * @TODO decide if this is needed at all + * @param mixed $config + * @param string $filePath + * @return void + * @access private + */ + private function __writeConfig($config, $filePath = '') { + return; // not needed? + $File = new File($filePath, true); + $contents = array('<?php', '$config = array('); + foreach ($config as $key => $string) { + $contents[] = "\t" . "'$key' => $string,"; + } + $contents[] = ");"; + $File->write(implode($contents, "\r\n")); + } +} +?> \ No newline at end of file diff --git a/views/default/class_doc.ctp b/views/default/class_doc.ctp new file mode 100644 index 0000000..a9862ba --- /dev/null +++ b/views/default/class_doc.ctp @@ -0,0 +1,7 @@ +/** + * <?php echo $name ?> class + * + * @uses <?php echo $uses . $nl ?> + * @package <?php echo $package . $nl ?> + * @subpackage <?php echo $subPackage . $nl ?> + */ diff --git a/views/default/class_file_header.ctp b/views/default/class_file_header.ctp new file mode 100644 index 0000000..0e08bc1 --- /dev/null +++ b/views/default/class_file_header.ctp @@ -0,0 +1,23 @@ +<?php echo '<?ph' ?>p +/* SVN FILE: <?php echo '$' ?>Id$ */ +/** + * <?php echo implode((array)$description, "$nl * ") . $nl ?> + * + * PHP version 4 and 5 + * + * Copyright (c) <?php echo date('Y') ?>, YourNameOrCompany + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) <?php echo date('Y') ?>, YourNameOrCompany + * @link www.yoursite.com + * @package <?php echo $package . $nl ?> + * @subpackage <?php echo $subPackage . $nl ?> + * @since v 1.0 (<?php echo date('d-M-Y') ?>) + * @version <?php echo '$' ?>Revision$ + * @modifiedby <?php echo '$' ?>LastChangedBy$ + * @lastmodified <?php echo '$' ?>Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ diff --git a/views/default/function_doc.ctp b/views/default/function_doc.ctp new file mode 100644 index 0000000..fad7bab --- /dev/null +++ b/views/default/function_doc.ctp @@ -0,0 +1,9 @@ +/** + * <?php echo $name ?> method + * +<?php foreach ($params as $param): ?> + * @param <?php echo $param['type'] . ' $' . $param['name'] . ' ' . $param['default'] . $nl ?> +<?php endforeach; ?> + * @return void + * @access <?php echo $visibility . $nl ?> + */ diff --git a/views/default/property_doc.ctp b/views/default/property_doc.ctp new file mode 100644 index 0000000..28e7580 --- /dev/null +++ b/views/default/property_doc.ctp @@ -0,0 +1,6 @@ +/** + * <?php echo $name ?> property + * + * @var <?php echo $type . ' ' . $default . $nl ?> + * @access <?php echo $visibility . $nl ?> + */ diff --git a/views/default/view_file_header.ctp b/views/default/view_file_header.ctp new file mode 100644 index 0000000..569946b --- /dev/null +++ b/views/default/view_file_header.ctp @@ -0,0 +1 @@ +<?php echo "<?php\r\n" ?> /* SVN FILE: $' . 'Id$ */ ?> \ No newline at end of file