code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
function _generatePossibleKeys() { $possible = array(); foreach ($this->_tables as $otherTable) { $tempOtherModel = & new Model(array('table' => $otherTable, 'ds' => $this->connection)); $modelFieldsTemp = $tempOtherModel->schema(true); foreach ($modelFieldsTemp as $fieldName => $field) { if ($field['type'] == 'integer' || $field['type'] == 'string') { $possible[$otherTable][] = $fieldName; } } } return $possible; }
Finds all possible keys to use on custom associations. @return array array of tables and possible keys
_generatePossibleKeys
php
Datawalke/Coordino
cake/console/libs/tasks/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/model.php
MIT
function bake($name, $data = array()) { if (is_object($name)) { if ($data == false) { $data = $associations = array(); $data['associations'] = $this->doAssociations($name, $associations); $data['validate'] = $this->doValidation($name); } $data['primaryKey'] = $name->primaryKey; $data['useTable'] = $name->table; $data['useDbConfig'] = $name->useDbConfig; $data['name'] = $name = $name->name; } else { $data['name'] = $name; } $defaults = array('associations' => array(), 'validate' => array(), 'primaryKey' => 'id', 'useTable' => null, 'useDbConfig' => 'default', 'displayField' => null); $data = array_merge($defaults, $data); $this->Template->set($data); $this->Template->set('plugin', Inflector::camelize($this->plugin)); $out = $this->Template->generate('classes', 'model'); $path = $this->getPath(); $filename = $path . Inflector::underscore($name) . '.php'; $this->out("\nBaking model class for $name..."); $this->createFile($filename, $out); ClassRegistry::flush(); return $out; }
Assembles and writes a Model file. @param mixed $name Model name or object @param mixed $data if array and $name is not an object assume bake data, otherwise boolean. @access private
bake
php
Datawalke/Coordino
cake/console/libs/tasks/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/model.php
MIT
function bakeTest($className) { $this->Test->interactive = $this->interactive; $this->Test->plugin = $this->plugin; $this->Test->connection = $this->connection; return $this->Test->bake('Model', $className); }
Assembles and writes a unit test file @param string $className Model class name @access private
bakeTest
php
Datawalke/Coordino
cake/console/libs/tasks/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/model.php
MIT
function listAll($useDbConfig = null) { $this->_tables = $this->getAllTables($useDbConfig); if ($this->interactive === true) { $this->out(__('Possible Models based on your current database:', true)); $this->_modelNames = array(); $count = count($this->_tables); for ($i = 0; $i < $count; $i++) { $this->_modelNames[] = $this->_modelName($this->_tables[$i]); $this->out($i + 1 . ". " . $this->_modelNames[$i]); } } return $this->_tables; }
outputs the a list of possible models or controllers from database @param string $useDbConfig Database configuration name @access public
listAll
php
Datawalke/Coordino
cake/console/libs/tasks/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/model.php
MIT
function getTable($modelName, $useDbConfig = null) { if (!isset($useDbConfig)) { $useDbConfig = $this->connection; } App::import('Model', 'ConnectionManager', false); $db =& ConnectionManager::getDataSource($useDbConfig); $useTable = Inflector::tableize($modelName); $fullTableName = $db->fullTableName($useTable, false); $tableIsGood = false; if (array_search($useTable, $this->_tables) === false) { $this->out(); $this->out(sprintf(__("Given your model named '%s',\nCake would expect a database table named '%s'", true), $modelName, $fullTableName)); $tableIsGood = $this->in(__('Do you want to use this table?', true), array('y','n'), 'y'); } if (strtolower($tableIsGood) == 'n') { $useTable = $this->in(__('What is the name of the table?', true)); } return $useTable; }
Interact with the user to determine the table name of a particular model @param string $modelName Name of the model you want a table for. @param string $useDbConfig Name of the database config you want to get tables from. @return void
getTable
php
Datawalke/Coordino
cake/console/libs/tasks/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/model.php
MIT
function getAllTables($useDbConfig = null) { if (!isset($useDbConfig)) { $useDbConfig = $this->connection; } App::import('Model', 'ConnectionManager', false); $tables = array(); $db =& ConnectionManager::getDataSource($useDbConfig); $db->cacheSources = false; $usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix']; if ($usePrefix) { foreach ($db->listSources() as $table) { if (!strncmp($table, $usePrefix, strlen($usePrefix))) { $tables[] = substr($table, strlen($usePrefix)); } } } else { $tables = $db->listSources(); } if (empty($tables)) { $this->err(__('Your database does not have any tables.', true)); $this->_stop(); } return $tables; }
Get an Array of all the tables in the supplied connection will halt the script if no tables are found. @param string $useDbConfig Connection name to scan. @return array Array of tables in the database.
getAllTables
php
Datawalke/Coordino
cake/console/libs/tasks/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/model.php
MIT
function getName($useDbConfig = null) { $this->listAll($useDbConfig); $enteredModel = ''; while ($enteredModel == '') { $enteredModel = $this->in(__("Enter a number from the list above,\ntype in the name of another model, or 'q' to exit", true), null, 'q'); if ($enteredModel === 'q') { $this->out(__("Exit", true)); $this->_stop(); } if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) { $this->err(__("The model name you supplied was empty,\nor the number you selected was not an option. Please try again.", true)); $enteredModel = ''; } } if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) { $currentModelName = $this->_modelNames[intval($enteredModel) - 1]; } else { $currentModelName = $enteredModel; } return $currentModelName; }
Forces the user to specify the model he wants to bake, and returns the selected model name. @return string the model name @access public
getName
php
Datawalke/Coordino
cake/console/libs/tasks/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/model.php
MIT
function bakeFixture($className, $useTable = null) { $this->Fixture->interactive = $this->interactive; $this->Fixture->connection = $this->connection; $this->Fixture->plugin = $this->plugin; $this->Fixture->bake($className, $useTable); }
Interact with FixtureTask to automatically bake fixtures when baking models. @param string $className Name of class to bake fixture for @param string $useTable Optional table name for fixture to use. @access public @return void @see FixtureTask::bake
bakeFixture
php
Datawalke/Coordino
cake/console/libs/tasks/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/model.php
MIT
function execute() { if (empty($this->params['skel'])) { $this->params['skel'] = ''; if (is_dir(CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel') === true) { $this->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel'; } } $plugin = null; if (isset($this->args[0])) { $plugin = Inflector::camelize($this->args[0]); $pluginPath = $this->_pluginPath($plugin); $this->Dispatch->shiftArgs(); if (is_dir($pluginPath)) { $this->out(sprintf(__('Plugin: %s', true), $plugin)); $this->out(sprintf(__('Path: %s', true), $pluginPath)); } elseif (isset($this->args[0])) { $this->err(sprintf(__('%s in path %s not found.', true), $plugin, $pluginPath)); $this->_stop(); } else { $this->__interactive($plugin); } } else { return $this->__interactive(); } if (isset($this->args[0])) { $task = Inflector::classify($this->args[0]); $this->Dispatch->shiftArgs(); if (in_array($task, $this->tasks)) { $this->{$task}->plugin = $plugin; $this->{$task}->path = $pluginPath . Inflector::underscore(Inflector::pluralize($task)) . DS; if (!is_dir($this->{$task}->path)) { $this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path)); } $this->{$task}->loadTasks(); return $this->{$task}->execute(); } } }
Execution method always used for tasks @return void
execute
php
Datawalke/Coordino
cake/console/libs/tasks/plugin.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/plugin.php
MIT
function __interactive($plugin = null) { while ($plugin === null) { $plugin = $this->in(__('Enter the name of the plugin in CamelCase format', true)); } if (!$this->bake($plugin)) { $this->err(sprintf(__("An error occured trying to bake: %s in %s", true), $plugin, $this->path . Inflector::underscore($pluginPath))); } }
Interactive interface @access private @return void
__interactive
php
Datawalke/Coordino
cake/console/libs/tasks/plugin.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/plugin.php
MIT
function bake($plugin) { $pluginPath = Inflector::underscore($plugin); $pathOptions = App::path('plugins'); if (count($pathOptions) > 1) { $this->findPath($pathOptions); } $this->hr(); $this->out(sprintf(__("Plugin Name: %s", true), $plugin)); $this->out(sprintf(__("Plugin Directory: %s", true), $this->path . $pluginPath)); $this->hr(); $looksGood = $this->in(__('Look okay?', true), array('y', 'n', 'q'), 'y'); if (strtolower($looksGood) == 'y') { $verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n'); $Folder =& new Folder($this->path . $pluginPath); $directories = array( 'config' . DS . 'schema', 'models' . DS . 'behaviors', 'models' . DS . 'datasources', 'controllers' . DS . 'components', 'libs', 'views' . DS . 'helpers', 'tests' . DS . 'cases' . DS . 'components', 'tests' . DS . 'cases' . DS . 'helpers', 'tests' . DS . 'cases' . DS . 'behaviors', 'tests' . DS . 'cases' . DS . 'controllers', 'tests' . DS . 'cases' . DS . 'models', 'tests' . DS . 'groups', 'tests' . DS . 'fixtures', 'vendors', 'vendors' . DS . 'shells' . DS . 'tasks', 'webroot' ); foreach ($directories as $directory) { $dirPath = $this->path . $pluginPath . DS . $directory; $Folder->create($dirPath); $File =& new File($dirPath . DS . 'empty', true); } if (strtolower($verbose) == 'y') { foreach ($Folder->messages() as $message) { $this->out($message); } } $errors = $Folder->errors(); if (!empty($errors)) { return false; } $controllerFileName = $pluginPath . '_app_controller.php'; $out = "<?php\n\n"; $out .= "class {$plugin}AppController extends AppController {\n\n"; $out .= "}\n\n"; $out .= "?>"; $this->createFile($this->path . $pluginPath. DS . $controllerFileName, $out); $modelFileName = $pluginPath . '_app_model.php'; $out = "<?php\n\n"; $out .= "class {$plugin}AppModel extends AppModel {\n\n"; $out .= "}\n\n"; $out .= "?>"; $this->createFile($this->path . $pluginPath . DS . $modelFileName, $out); $this->hr(); $this->out(sprintf(__("Created: %s in %s", true), $plugin, $this->path . $pluginPath)); $this->hr(); } return true; }
Bake the plugin, create directories and files @params $plugin name of the plugin in CamelCased format @access public @return bool
bake
php
Datawalke/Coordino
cake/console/libs/tasks/plugin.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/plugin.php
MIT
function findPath($pathOptions) { $valid = false; $max = count($pathOptions); while (!$valid) { foreach ($pathOptions as $i => $option) { $this->out($i + 1 .'. ' . $option); } $prompt = __('Choose a plugin path from the paths above.', true); $choice = $this->in($prompt); if (intval($choice) > 0 && intval($choice) <= $max) { $valid = true; } } $this->path = $pathOptions[$choice - 1]; }
find and change $this->path to the user selection @return void
findPath
php
Datawalke/Coordino
cake/console/libs/tasks/plugin.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/plugin.php
MIT
function execute($project = null) { if ($project === null) { if (isset($this->args[0])) { $project = $this->args[0]; } } if ($project) { $this->Dispatch->parseParams(array('-app', $project)); $project = $this->params['working']; } if (empty($this->params['skel'])) { $this->params['skel'] = ''; if (is_dir(CAKE . 'console' . DS . 'templates' . DS . 'skel') === true) { $this->params['skel'] = CAKE . 'console' . DS . 'templates' . DS . 'skel'; } } while (!$project) { $prompt = __("What is the full path for this app including the app directory name?\n Example:", true); $default = $this->params['working'] . DS . 'myapp'; $project = $this->in($prompt . $default, null, $default); } if ($project) { $response = false; while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) { $prompt = sprintf(__('A project already exists in this location: %s Overwrite?', true), $project); $response = $this->in($prompt, array('y','n'), 'n'); if (strtolower($response) === 'n') { $response = $project = false; } } } if ($this->bake($project)) { $path = Folder::slashTerm($project); if ($this->createHome($path)) { $this->out(__('Welcome page created', true)); } else { $this->out(__('The Welcome page was NOT created', true)); } if ($this->securitySalt($path) === true ) { $this->out(__('Random hash key created for \'Security.salt\'', true)); } else { $this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php')); } if ($this->securityCipherSeed($path) === true ) { $this->out(__('Random seed created for \'Security.cipherSeed\'', true)); } else { $this->err(sprintf(__('Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', true), CONFIGS . 'core.php')); } $corePath = $this->corePath($path); if ($corePath === true ) { $this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH)); $this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', true), CAKE_CORE_INCLUDE_PATH)); $this->out(__('Remember to check these value after moving to production server', true)); } elseif ($corePath === false) { $this->err(sprintf(__('Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', true), $path . 'webroot' .DS .'index.php')); } $Folder = new Folder($path); if (!$Folder->chmod($path . 'tmp', 0777)) { $this->err(sprintf(__('Could not set permissions on %s', true), $path . DS .'tmp')); $this->out(sprintf(__('chmod -R 0777 %s', true), $path . DS .'tmp')); } $this->params['working'] = $path; $this->params['app'] = basename($path); return true; } }
Checks that given project path does not already exist, and finds the app directory in it. Then it calls bake() with that information. @param string $project Project path @access public
execute
php
Datawalke/Coordino
cake/console/libs/tasks/project.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/project.php
MIT
function bake($path, $skel = null, $skip = array('empty')) { if (!$skel) { $skel = $this->params['skel']; } while (!$skel) { $skel = $this->in(sprintf(__("What is the path to the directory layout you wish to copy?\nExample: %s"), APP, null, ROOT . DS . 'myapp' . DS)); if ($skel == '') { $this->out(__('The directory path you supplied was empty. Please try again.', true)); } else { while (is_dir($skel) === false) { $skel = $this->in(__('Directory path does not exist please choose another:', true)); } } } $app = basename($path); $this->out(__('Bake Project', true)); $this->out(__("Skel Directory: ", true) . $skel); $this->out(__("Will be copied to: ", true) . $path); $this->hr(); $looksGood = $this->in(__('Look okay?', true), array('y', 'n', 'q'), 'y'); if (strtolower($looksGood) == 'y') { $verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n'); $Folder = new Folder($skel); if (!empty($this->params['empty'])) { $skip = array(); } if ($Folder->copy(array('to' => $path, 'skip' => $skip))) { $this->hr(); $this->out(sprintf(__("Created: %s in %s", true), $app, $path)); $this->hr(); } else { $this->err(sprintf(__(" '%s' could not be created properly", true), $app)); return false; } if (strtolower($verbose) == 'y') { foreach ($Folder->messages() as $message) { $this->out($message); } } return true; } elseif (strtolower($looksGood) == 'q') { $this->out(__('Bake Aborted.', true)); } else { $this->execute(false); return false; } }
Looks for a skeleton template of a Cake application, and if not found asks the user for a path. When there is a path this method will make a deep copy of the skeleton to the project directory. A default home page will be added, and the tmp file storage will be chmod'ed to 0777. @param string $path Project path @param string $skel Path to copy from @param string $skip array of directories to skip when copying @access private
bake
php
Datawalke/Coordino
cake/console/libs/tasks/project.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/project.php
MIT
function createHome($dir) { $app = basename($dir); $path = $dir . 'views' . DS . 'pages' . DS; $source = CAKE . 'console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp'; include($source); return $this->createFile($path.'home.ctp', $output); }
Writes a file with a default home page to the project. @param string $dir Path to project @return boolean Success @access public
createHome
php
Datawalke/Coordino
cake/console/libs/tasks/project.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/project.php
MIT
function securitySalt($path) { $File =& new File($path . 'config' . DS . 'core.php'); $contents = $File->read(); if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.salt\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { if (!class_exists('Security')) { require LIBS . 'security.php'; } $string = Security::generateAuthKey(); $result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \''.$string.'\');', $contents); if ($File->write($result)) { return true; } return false; } return false; }
Generates and writes 'Security.salt' @param string $path Project path @return boolean Success @access public
securitySalt
php
Datawalke/Coordino
cake/console/libs/tasks/project.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/project.php
MIT
function securityCipherSeed($path) { $File =& new File($path . 'config' . DS . 'core.php'); $contents = $File->read(); if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.cipherSeed\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { if (!class_exists('Security')) { require LIBS . 'security.php'; } $string = substr(bin2hex(Security::generateAuthKey()), 0, 30); $result = str_replace($match[0], "\t" . 'Configure::write(\'Security.cipherSeed\', \''.$string.'\');', $contents); if ($File->write($result)) { return true; } return false; } return false; }
Generates and writes 'Security.cipherSeed' @param string $path Project path @return boolean Success @access public
securityCipherSeed
php
Datawalke/Coordino
cake/console/libs/tasks/project.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/project.php
MIT
function corePath($path) { if (dirname($path) !== CAKE_CORE_INCLUDE_PATH) { $File =& new File($path . 'webroot' . DS . 'index.php'); $contents = $File->read(); if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { $root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " DS . '" : "'"; $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', " . $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "');", $contents); if (!$File->write($result)) { return false; } } else { return false; } $File =& new File($path . 'webroot' . DS . 'test.php'); $contents = $File->read(); if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', " . $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "');", $contents); if (!$File->write($result)) { return false; } } else { return false; } return true; } }
Generates and writes CAKE_CORE_INCLUDE_PATH @param string $path Project path @return boolean Success @access public
corePath
php
Datawalke/Coordino
cake/console/libs/tasks/project.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/project.php
MIT
function cakeAdmin($name) { $path = (empty($this->configPath)) ? CONFIGS : $this->configPath; $File =& new File($path . 'core.php'); $contents = $File->read(); if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.prefixes\',[\\t\\x20\'a-z,\)\(]*\\);)%', $contents, $match)) { $result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.prefixes\', array(\''.$name.'\'));', $contents); if ($File->write($result)) { Configure::write('Routing.prefixes', array($name)); return true; } else { return false; } } else { return false; } }
Enables Configure::read('Routing.prefixes') in /app/config/core.php @param string $name Name to use as admin routing @return boolean Success @access public
cakeAdmin
php
Datawalke/Coordino
cake/console/libs/tasks/project.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/project.php
MIT
function getPrefix() { $admin = ''; $prefixes = Configure::read('Routing.prefixes'); if (!empty($prefixes)) { if (count($prefixes) == 1) { return $prefixes[0] . '_'; } if ($this->interactive) { $this->out(); $this->out(__('You have more than one routing prefix configured', true)); } $options = array(); foreach ($prefixes as $i => $prefix) { $options[] = $i + 1; if ($this->interactive) { $this->out($i + 1 . '. ' . $prefix); } } $selection = $this->in(__('Please choose a prefix to bake with.', true), $options, 1); return $prefixes[$selection - 1] . '_'; } if ($this->interactive) { $this->hr(); $this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.'); $this->out(__('What would you like the prefix route to be?', true)); $this->out(__('Example: www.example.com/admin/controller', true)); while ($admin == '') { $admin = $this->in(__("Enter a routing prefix:", true), null, 'admin'); } if ($this->cakeAdmin($admin) !== true) { $this->out(__('Unable to write to /app/config/core.php.', true)); $this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.'); $this->_stop(); } return $admin . '_'; } return ''; }
Checks for Configure::read('Routing.prefixes') and forces user to input it if not enabled @return string Admin route to use @access public
getPrefix
php
Datawalke/Coordino
cake/console/libs/tasks/project.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/project.php
MIT
function initialize() { $this->templatePaths = $this->_findThemes(); }
Initialize callback. Setup paths for the template task. @access public @return void
initialize
php
Datawalke/Coordino
cake/console/libs/tasks/template.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/template.php
MIT
function _findThemes() { $paths = App::path('shells'); $core = array_pop($paths); $separator = DS === '/' ? '/' : '\\\\'; $core = preg_replace('#libs' . $separator . '$#', '', $core); $Folder =& new Folder($core . 'templates' . DS . 'default'); $contents = $Folder->read(); $themeFolders = $contents[0]; $plugins = App::objects('plugin'); foreach ($plugins as $plugin) { $paths[] = $this->_pluginPath($plugin) . 'vendors' . DS . 'shells' . DS; } $paths[] = $core; // TEMPORARY TODO remove when all paths are DS terminated foreach ($paths as $i => $path) { $paths[$i] = rtrim($path, DS) . DS; } $themes = array(); foreach ($paths as $path) { $Folder =& new Folder($path . 'templates', false); $contents = $Folder->read(); $subDirs = $contents[0]; foreach ($subDirs as $dir) { if (empty($dir) || preg_match('@^skel$|_skel$@', $dir)) { continue; } $Folder =& new Folder($path . 'templates' . DS . $dir); $contents = $Folder->read(); $subDirs = $contents[0]; if (array_intersect($contents[0], $themeFolders)) { $templateDir = $path . 'templates' . DS . $dir . DS; $themes[$dir] = $templateDir; } } } return $themes; }
Find the paths to all the installed shell themes in the app. Bake themes are directories not named `skel` inside a `vendors/shells/templates` path. @return array Array of bake themes that are installed.
_findThemes
php
Datawalke/Coordino
cake/console/libs/tasks/template.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/template.php
MIT
function set($one, $two = null) { $data = null; if (is_array($one)) { if (is_array($two)) { $data = array_combine($one, $two); } else { $data = $one; } } else { $data = array($one => $two); } if ($data == null) { return false; } $this->templateVars = $data + $this->templateVars; }
Set variable values to the template scope @param mixed $one A string or an array of data. @param mixed $two Value in case $one is a string (which then works as the key). Unused if $one is an associative array, otherwise serves as the values to $one's keys. @return void
set
php
Datawalke/Coordino
cake/console/libs/tasks/template.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/template.php
MIT
function generate($directory, $filename, $vars = null) { if ($vars !== null) { $this->set($vars); } if (empty($this->templatePaths)) { $this->initialize(); } $themePath = $this->getThemePath(); $templateFile = $this->_findTemplate($themePath, $directory, $filename); if ($templateFile) { extract($this->templateVars); ob_start(); ob_implicit_flush(0); include($templateFile); $content = ob_get_clean(); return $content; } return ''; }
Runs the template @param string $directory directory / type of thing you want @param string $filename template name @param string $vars Additional vars to set to template scope. @access public @return contents of generated code template
generate
php
Datawalke/Coordino
cake/console/libs/tasks/template.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/template.php
MIT
function getThemePath() { if (count($this->templatePaths) == 1) { $paths = array_values($this->templatePaths); return $paths[0]; } if (!empty($this->params['theme']) && isset($this->templatePaths[$this->params['theme']])) { return $this->templatePaths[$this->params['theme']]; } $this->hr(); $this->out(__('You have more than one set of templates installed.', true)); $this->out(__('Please choose the template set you wish to use:', true)); $this->hr(); $i = 1; $indexedPaths = array(); foreach ($this->templatePaths as $key => $path) { $this->out($i . '. ' . $key); $indexedPaths[$i] = $path; $i++; } $index = $this->in(__('Which bake theme would you like to use?', true), range(1, $i - 1), 1); $themeNames = array_keys($this->templatePaths); $this->Dispatch->params['theme'] = $themeNames[$index - 1]; return $indexedPaths[$index]; }
Find the theme name for the current operation. If there is only one theme in $templatePaths it will be used. If there is a -theme param in the cli args, it will be used. If there is more than one installed theme user interaction will happen @return string returns the path to the selected theme.
getThemePath
php
Datawalke/Coordino
cake/console/libs/tasks/template.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/template.php
MIT
function _findTemplate($path, $directory, $filename) { $themeFile = $path . $directory . DS . $filename . '.ctp'; if (file_exists($themeFile)) { return $themeFile; } foreach ($this->templatePaths as $path) { $templatePath = $path . $directory . DS . $filename . '.ctp'; if (file_exists($templatePath)) { return $templatePath; } } $this->err(sprintf(__('Could not find template for %s', true), $filename)); return false; }
Find a template inside a directory inside a path. Will scan all other theme dirs if the template is not found in the first directory. @param string $path The initial path to look for the file on. If it is not found fallbacks will be used. @param string $directory Subdirectory to look for ie. 'views', 'objects' @param string $filename lower_case_underscored filename you want. @access public @return string filename will exit program if template is not found.
_findTemplate
php
Datawalke/Coordino
cake/console/libs/tasks/template.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/template.php
MIT
function execute() { if (empty($this->args)) { $this->__interactive(); } if (count($this->args) == 1) { $this->__interactive($this->args[0]); } if (count($this->args) > 1) { $type = Inflector::underscore($this->args[0]); if ($this->bake($type, $this->args[1])) { $this->out('done'); } } }
Execution method always used for tasks @access public
execute
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function bake($type, $className) { if ($this->typeCanDetectFixtures($type) && $this->isLoadableClass($type, $className)) { $this->out(__('Bake is detecting possible fixtures..', true)); $testSubject =& $this->buildTestSubject($type, $className); $this->generateFixtureList($testSubject); } elseif ($this->interactive) { $this->getUserFixtures(); } $fullClassName = $this->getRealClassName($type, $className); $methods = array(); if (class_exists($fullClassName)) { $methods = $this->getTestableMethods($fullClassName); } $mock = $this->hasMockClass($type, $fullClassName); $construction = $this->generateConstructor($type, $fullClassName); $plugin = null; if ($this->plugin) { $plugin = $this->plugin . '.'; } $this->Template->set('fixtures', $this->_fixtures); $this->Template->set('plugin', $plugin); $this->Template->set(compact('className', 'methods', 'type', 'fullClassName', 'mock', 'construction')); $out = $this->Template->generate('classes', 'test'); $filename = $this->testCaseFileName($type, $className); $made = $this->createFile($filename, $out); if ($made) { return $out; } return false; }
Completes final steps for generating data to create test case. @param string $type Type of object to bake test case for ie. Model, Controller @param string $className the 'cake name' for the class ie. Posts for the PostsController @access public
bake
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function getObjectType() { $this->hr(); $this->out(__("Select an object type:", true)); $this->hr(); $keys = array(); foreach ($this->classTypes as $key => $option) { $this->out(++$key . '. ' . $option); $keys[] = $key; } $keys[] = 'q'; $selection = $this->in(__("Enter the type of object to bake a test for or (q)uit", true), $keys, 'q'); if ($selection == 'q') { return $this->_stop(); } return $this->classTypes[$selection - 1]; }
Interact with the user and get their chosen type. Can exit the script. @return string Users chosen type. @access public
getObjectType
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function getClassName($objectType) { $type = strtolower($objectType); if ($this->plugin) { $path = Inflector::pluralize($type); if ($type === 'helper') { $path = 'views' . DS . $path; } elseif ($type === 'component') { $path = 'controllers' . DS . $path; } elseif ($type === 'behavior') { $path = 'models' . DS . $path; } $options = App::objects($type, App::pluginPath($this->plugin) . $path, false); } else { $options = App::objects($type); } $this->out(sprintf(__('Choose a %s class', true), $objectType)); $keys = array(); foreach ($options as $key => $option) { $this->out(++$key . '. ' . $option); $keys[] = $key; } $selection = $this->in(__('Choose an existing class, or enter the name of a class that does not exist', true)); if (isset($options[$selection - 1])) { return $options[$selection - 1]; } return $selection; }
Get the user chosen Class name for the chosen type @param string $objectType Type of object to list classes for i.e. Model, Controller. @return string Class name the user chose. @access public
getClassName
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function typeCanDetectFixtures($type) { $type = strtolower($type); return ($type == 'controller' || $type == 'model'); }
Checks whether the chosen type can find its own fixtures. Currently only model, and controller are supported @param string $type The Type of object you are generating tests for eg. controller @param string $className the Classname of the class the test is being generated for. @return boolean @access public
typeCanDetectFixtures
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function isLoadableClass($type, $class) { return App::import($type, $class); }
Check if a class with the given type is loaded or can be loaded. @param string $type The Type of object you are generating tests for eg. controller @param string $className the Classname of the class the test is being generated for. @return boolean @access public
isLoadableClass
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function &buildTestSubject($type, $class) { ClassRegistry::flush(); App::import($type, $class); $class = $this->getRealClassName($type, $class); if (strtolower($type) == 'model') { $instance =& ClassRegistry::init($class); } else { $instance =& new $class(); } return $instance; }
Construct an instance of the class to be tested. So that fixtures can be detected @param string $type The Type of object you are generating tests for eg. controller @param string $class the Classname of the class the test is being generated for. @return object And instance of the class that is going to be tested. @access public
buildTestSubject
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function getRealClassName($type, $class) { if (strtolower($type) == 'model') { return $class; } return $class . $type; }
Gets the real class name from the cake short form. @param string $type The Type of object you are generating tests for eg. controller @param string $class the Classname of the class the test is being generated for. @return string Real classname @access public
getRealClassName
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function getTestableMethods($className) { $classMethods = get_class_methods($className); $parentMethods = get_class_methods(get_parent_class($className)); $thisMethods = array_diff($classMethods, $parentMethods); $out = array(); foreach ($thisMethods as $method) { if (substr($method, 0, 1) != '_' && $method != strtolower($className)) { $out[] = $method; } } return $out; }
Get methods declared in the class given. No parent methods will be returned @param string $className Name of class to look at. @return array Array of method names. @access public
getTestableMethods
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function generateFixtureList(&$subject) { $this->_fixtures = array(); if (is_a($subject, 'Model')) { $this->_processModel($subject); } elseif (is_a($subject, 'Controller')) { $this->_processController($subject); } return array_values($this->_fixtures); }
Generate the list of fixtures that will be required to run this test based on loaded models. @param object $subject The object you want to generate fixtures for. @return array Array of fixtures to be included in the test. @access public
generateFixtureList
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function _processModel(&$subject) { $this->_addFixture($subject->name); $associated = $subject->getAssociated(); foreach ($associated as $alias => $type) { $className = $subject->{$alias}->name; if (!isset($this->_fixtures[$className])) { $this->_processModel($subject->{$alias}); } if ($type == 'hasAndBelongsToMany') { $joinModel = Inflector::classify($subject->hasAndBelongsToMany[$alias]['joinTable']); if (!isset($this->_fixtures[$joinModel])) { $this->_processModel($subject->{$joinModel}); } } } }
Process a model recursively and pull out all the model names converting them to fixture names. @param Model $subject A Model class to scan for associations and pull fixtures off of. @return void @access protected
_processModel
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function _processController(&$subject) { $subject->constructClasses(); $models = array(Inflector::classify($subject->name)); if (!empty($subject->uses)) { $models = $subject->uses; } foreach ($models as $model) { $this->_processModel($subject->{$model}); } }
Process all the models attached to a controller and generate a fixture list. @param Controller $subject A controller to pull model names off of. @return void @access protected
_processController
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function _addFixture($name) { $parent = get_parent_class($name); $prefix = 'app.'; if (strtolower($parent) != 'appmodel' && strtolower(substr($parent, -8)) == 'appmodel') { $pluginName = substr($parent, 0, strlen($parent) -8); $prefix = 'plugin.' . Inflector::underscore($pluginName) . '.'; } $fixture = $prefix . Inflector::underscore($name); $this->_fixtures[$name] = $fixture; }
Add classname to the fixture list. Sets the app. or plugin.plugin_name. prefix. @param string $name Name of the Model class that a fixture might be required for. @return void @access protected
_addFixture
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function getUserFixtures() { $proceed = $this->in(__('Bake could not detect fixtures, would you like to add some?', true), array('y','n'), 'n'); $fixtures = array(); if (strtolower($proceed) == 'y') { $fixtureList = $this->in(__("Please provide a comma separated list of the fixtures names you'd like to use.\nExample: 'app.comment, app.post, plugin.forums.post'", true)); $fixtureListTrimmed = str_replace(' ', '', $fixtureList); $fixtures = explode(',', $fixtureListTrimmed); } $this->_fixtures = array_merge($this->_fixtures, $fixtures); return $fixtures; }
Interact with the user to get additional fixtures they want to use. @return array Array of fixtures the user wants to add. @access public
getUserFixtures
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function hasMockClass($type) { $type = strtolower($type); return $type == 'controller'; }
Is a mock class required for this type of test? Controllers require a mock class. @param string $type The type of object tests are being generated for eg. controller. @return boolean @access public
hasMockClass
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function generateConstructor($type, $fullClassName) { $type = strtolower($type); if ($type == 'model') { return "ClassRegistry::init('$fullClassName');\n"; } if ($type == 'controller') { $className = substr($fullClassName, 0, strlen($fullClassName) - 10); return "new Test$fullClassName();\n\t\t\$this->{$className}->constructClasses();\n"; } return "new $fullClassName();\n"; }
Generate a constructor code snippet for the type and classname @param string $type The Type of object you are generating tests for eg. controller @param string $className the Classname of the class the test is being generated for. @return string Constructor snippet for the thing you are building. @access public
generateConstructor
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function testCaseFileName($type, $className) { $path = $this->getPath();; $path .= 'cases' . DS . strtolower($type) . 's' . DS; if (strtolower($type) == 'controller') { $className = $this->getRealClassName($type, $className); } return $path . Inflector::underscore($className) . '.test.php'; }
Make the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed. @param string $type The Type of object you are generating tests for eg. controller @param string $className the Classname of the class the test is being generated for. @return string filename the test should be created on. @access public
testCaseFileName
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function help() { $this->hr(); $this->out("Usage: cake bake test <type> <class>"); $this->hr(); $this->out('Commands:'); $this->out(""); $this->out("test model post\n\tbakes a test case for the post model."); $this->out(""); $this->out("test controller comments\n\tbakes a test case for the comments controller."); $this->out(""); $this->out('Arguments:'); $this->out("\t<type> Can be any of the following 'controller', 'model', 'helper',\n\t'component', 'behavior'."); $this->out("\t<class> Any existing class for the chosen type."); $this->out(""); $this->out("Parameters:"); $this->out("\t-plugin CamelCased name of plugin to bake tests for."); $this->out(""); $this->_stop(); }
Show help file. @return void @access public
help
php
Datawalke/Coordino
cake/console/libs/tasks/test.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/test.php
MIT
function execute() { if (empty($this->args)) { $this->__interactive(); } if (empty($this->args[0])) { return; } if (!isset($this->connection)) { $this->connection = 'default'; } $controller = $action = $alias = null; $this->controllerName = $this->_controllerName($this->args[0]); $this->controllerPath = $this->_controllerPath($this->controllerName); $this->Project->interactive = false; if (strtolower($this->args[0]) == 'all') { return $this->all(); } if (isset($this->args[1])) { $this->template = $this->args[1]; } if (isset($this->args[2])) { $action = $this->args[2]; } if (!$action) { $action = $this->template; } if ($action) { return $this->bake($action, true); } $vars = $this->__loadController(); $methods = $this->_methodsToBake(); foreach ($methods as $method) { $content = $this->getContent($method, $vars); if ($content) { $this->bake($method, $content); } } }
Execution method always used for tasks @access public
execute
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function _methodsToBake() { $methods = array_diff( array_map('strtolower', get_class_methods($this->controllerName . 'Controller')), array_map('strtolower', get_class_methods('appcontroller')) ); $scaffoldActions = false; if (empty($methods)) { $scaffoldActions = true; $methods = $this->scaffoldActions; } $adminRoute = $this->Project->getPrefix(); foreach ($methods as $i => $method) { if ($adminRoute && isset($this->params['admin'])) { if ($scaffoldActions) { $methods[$i] = $adminRoute . $method; continue; } elseif (strpos($method, $adminRoute) === false) { unset($methods[$i]); } } if ($method[0] === '_' || $method == strtolower($this->controllerName . 'Controller')) { unset($methods[$i]); } } return $methods; }
Get a list of actions that can / should have views baked for them. @return array Array of action names that should be baked
_methodsToBake
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function all() { $this->Controller->interactive = false; $tables = $this->Controller->listAll($this->connection, false); $actions = null; if (isset($this->args[1])) { $actions = array($this->args[1]); } $this->interactive = false; foreach ($tables as $table) { $model = $this->_modelName($table); $this->controllerName = $this->_controllerName($model); $this->controllerPath = Inflector::underscore($this->controllerName); if (App::import('Model', $model)) { $vars = $this->__loadController(); if (!$actions) { $actions = $this->_methodsToBake(); } $this->bakeActions($actions, $vars); $actions = null; } } }
Bake All views for All controllers. @return void
all
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function __loadController() { if (!$this->controllerName) { $this->err(__('Controller not found', true)); } $import = $this->controllerName; if ($this->plugin) { $import = $this->plugin . '.' . $this->controllerName; } if (!App::import('Controller', $import)) { $file = $this->controllerPath . '_controller.php'; $this->err(sprintf(__("The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", true), $file)); $this->_stop(); } $controllerClassName = $this->controllerName . 'Controller'; $controllerObj =& new $controllerClassName(); $controllerObj->plugin = $this->plugin; $controllerObj->constructClasses(); $modelClass = $controllerObj->modelClass; $modelObj =& $controllerObj->{$controllerObj->modelClass}; if ($modelObj) { $primaryKey = $modelObj->primaryKey; $displayField = $modelObj->displayField; $singularVar = Inflector::variable($modelClass); $singularHumanName = $this->_singularHumanName($this->controllerName); $schema = $modelObj->schema(true); $fields = array_keys($schema); $associations = $this->__associations($modelObj); } else { $primaryKey = $displayField = null; $singularVar = Inflector::variable(Inflector::singularize($this->controllerName)); $singularHumanName = $this->_singularHumanName($this->controllerName); $fields = $schema = $associations = array(); } $pluralVar = Inflector::variable($this->controllerName); $pluralHumanName = $this->_pluralHumanName($this->controllerName); return compact('modelClass', 'schema', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', 'singularHumanName', 'pluralHumanName', 'fields','associations'); }
Loads Controller and sets variables for the template Available template variables 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', 'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys', 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany' @return array Returns an variables to be made available to a view template @access private
__loadController
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function bakeActions($actions, $vars) { foreach ($actions as $action) { $content = $this->getContent($action, $vars); $this->bake($action, $content); } }
Bake a view file for each of the supplied actions @param array $actions Array of actions to make files for. @return void
bakeActions
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function customAction() { $action = ''; while ($action == '') { $action = $this->in(__('Action Name? (use lowercase_underscored function name)', true)); if ($action == '') { $this->out(__('The action name you supplied was empty. Please try again.', true)); } } $this->out(); $this->hr(); $this->out(__('The following view will be created:', true)); $this->hr(); $this->out(sprintf(__('Controller Name: %s', true), $this->controllerName)); $this->out(sprintf(__('Action Name: %s', true), $action)); $this->out(sprintf(__('Path: %s', true), $this->params['app'] . DS . 'views' . DS . $this->controllerPath . DS . Inflector::underscore($action) . ".ctp")); $this->hr(); $looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y'); if (strtolower($looksGood) == 'y') { $this->bake($action, true); $this->_stop(); } else { $this->out(__('Bake Aborted.', true)); } }
handle creation of baking a custom action view file @return void
customAction
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function bake($action, $content = '') { if ($content === true) { $content = $this->getContent($action); } if (empty($content)) { return false; } $path = $this->getPath(); $filename = $path . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp'; return $this->createFile($filename, $content); }
Assembles and writes bakes the view file. @param string $action Action to bake @param string $content Content to write @return boolean Success @access public
bake
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function getContent($action, $vars = null) { if (!$vars) { $vars = $this->__loadController(); } $this->Template->set('action', $action); $this->Template->set('plugin', $this->plugin); $this->Template->set($vars); $template = $this->getTemplate($action); if ($template) { return $this->Template->generate('views', $template); } return false; }
Builds content from template and variables @param string $action name to generate content to @param array $vars passed for use in templates @return string content from template @access public
getContent
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function getTemplate($action) { if ($action != $this->template && in_array($action, $this->noTemplateActions)) { return false; } if (!empty($this->template) && $action != $this->template) { return $this->template; } $template = $action; $prefixes = Configure::read('Routing.prefixes'); foreach ((array)$prefixes as $prefix) { if (strpos($template, $prefix) !== false) { $template = str_replace($prefix . '_', '', $template); } } if (in_array($template, array('add', 'edit'))) { $template = 'form'; } elseif (preg_match('@(_add|_edit)$@', $template)) { $template = str_replace(array('_add', '_edit'), '_form', $template); } return $template; }
Gets the template name based on the action name @param string $action name @return string template name @access public
getTemplate
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function __associations(&$model) { $keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); $associations = array(); foreach ($keys as $key => $type) { foreach ($model->{$type} as $assocKey => $assocData) { $associations[$type][$assocKey]['primaryKey'] = $model->{$assocKey}->primaryKey; $associations[$type][$assocKey]['displayField'] = $model->{$assocKey}->displayField; $associations[$type][$assocKey]['foreignKey'] = $assocData['foreignKey']; $associations[$type][$assocKey]['controller'] = Inflector::pluralize(Inflector::underscore($assocData['className'])); $associations[$type][$assocKey]['fields'] = array_keys($model->{$assocKey}->schema(true)); } } return $associations; }
Returns associations for controllers models. @return array $associations @access private
__associations
php
Datawalke/Coordino
cake/console/libs/tasks/view.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/tasks/view.php
MIT
function display() { $path = func_get_args(); $count = count($path); if (!$count) { $this->redirect('/'); } $page = $subpage = $title_for_layout = null; if (!empty($path[0])) { $page = $path[0]; } if (!empty($path[1])) { $subpage = $path[1]; } if (!empty($path[$count - 1])) { $title_for_layout = Inflector::humanize($path[$count - 1]); } $this->set(compact('page', 'subpage', 'title_for_layout')); $this->render(implode('/', $path)); }
Displays a view @param mixed What page to display @access public
display
php
Datawalke/Coordino
cake/console/templates/skel/controllers/pages_controller.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/templates/skel/controllers/pages_controller.php
MIT
function make_clean_css($path, $name) { App::import('Vendor', 'csspp' . DS . 'csspp'); $data = file_get_contents($path); $csspp = new csspp(); $output = $csspp->compress($data); $ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100); $output = " /* file: $name, ratio: $ratio% */ " . $output; return $output; }
Make clean CSS @param unknown_type $path @param unknown_type $name @return unknown
make_clean_css
php
Datawalke/Coordino
cake/console/templates/skel/webroot/css.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/templates/skel/webroot/css.php
MIT
function write_css_cache($path, $content) { if (!is_dir(dirname($path))) { mkdir(dirname($path)); } $cache = new File($path); return $cache->write($content); }
Write CSS cache @param unknown_type $path @param unknown_type $content @return unknown
write_css_cache
php
Datawalke/Coordino
cake/console/templates/skel/webroot/css.php
https://github.com/Datawalke/Coordino/blob/master/cake/console/templates/skel/webroot/css.php
MIT
function &getInstance() { static $instance = array(); if (!$instance) { $instance[0] =& new Cache(); } return $instance[0]; }
Returns a singleton instance @return object @access public @static
getInstance
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function config($name = null, $settings = array()) { $self =& Cache::getInstance(); if (is_array($name)) { $settings = $name; } if ($name === null || !is_string($name)) { $name = $self->__name; } $current = array(); if (isset($self->__config[$name])) { $current = $self->__config[$name]; } if (!empty($settings)) { $self->__config[$name] = array_merge($current, $settings); } if (empty($self->__config[$name]['engine'])) { return false; } $engine = $self->__config[$name]['engine']; $self->__name = $name; if (!isset($self->_engines[$name])) { $self->_buildEngine($name); $settings = $self->__config[$name] = $self->settings($name); } elseif ($settings = $self->set($self->__config[$name])) { $self->__config[$name] = $settings; } return compact('engine', 'settings'); }
Set the cache configuration to use. config() can both create new configurations, return the settings for already configured configurations. It also sets the 'default' configuration to use for subsequent operations. To create a new configuration: `Cache::config('my_config', array('engine' => 'File', 'path' => TMP));` To get the settings for a configuration, and set it as the currently selected configuration `Cache::config('default');` The following keys are used in core cache engines: - `duration` Specify how long items in this cache configuration last. - `prefix` Prefix appended to all entries. Good for when you need to share a keyspace with either another cache config or annother application. - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable cache::gc from ever being called automatically. - `servers' Used by memcache. Give the address of the memcached servers to use. - `compress` Used by memcache. Enables memcache's compressed format. - `serialize` Used by FileCache. Should cache objects be serialized first. - `path` Used by FileCache. Path to where cachefiles should be saved. - `lock` Used by FileCache. Should files be locked before writing to them? - `user` Used by Xcache. Username for XCache - `password` Used by Xcache. Password for XCache @see app/config/core.php for configuration settings @param string $name Name of the configuration @param array $settings Optional associative array of settings passed to the engine @return array(engine, settings) on success, false on failure @access public @static
config
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function _buildEngine($name) { $config = $this->__config[$name]; list($plugin, $class) = pluginSplit($config['engine']); $cacheClass = $class . 'Engine'; if (!class_exists($cacheClass) && $this->__loadEngine($class, $plugin) === false) { return false; } $cacheClass = $class . 'Engine'; $this->_engines[$name] =& new $cacheClass(); if ($this->_engines[$name]->init($config)) { if ($this->_engines[$name]->settings['probability'] && time() % $this->_engines[$name]->settings['probability'] === 0) { $this->_engines[$name]->gc(); } return true; } return false; }
Finds and builds the instance of the required engine class. @param string $name Name of the config array that needs an engine instance built @return void @access protected
_buildEngine
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function configured() { $self =& Cache::getInstance(); return array_keys($self->__config); }
Returns an array containing the currently configured Cache settings. @return array Array of configured Cache config names.
configured
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function drop($name) { $self =& Cache::getInstance(); if (!isset($self->__config[$name])) { return false; } unset($self->__config[$name]); unset($self->_engines[$name]); return true; }
Drops a cache engine. Deletes the cache configuration information If the deleted configuration is the last configuration using an certain engine, the Engine instance is also unset. @param string $name A currently configured cache config you wish to remove. @return boolen success of the removal, returns false when the config does not exist.
drop
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function __loadEngine($name, $plugin = null) { if ($plugin) { return App::import('Lib', $plugin . '.cache' . DS . $name, false); } else { $core = App::core(); $path = $core['libs'][0] . 'cache' . DS . strtolower($name) . '.php'; if (file_exists($path)) { require $path; return true; } return App::import('Lib', 'cache' . DS . $name, false); } }
Tries to find and include a file for a cache engine and returns object instance @param $name Name of the engine (without 'Engine') @return mixed $engine object or null @access private
__loadEngine
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function set($settings = array(), $value = null) { $self =& Cache::getInstance(); if (!isset($self->__config[$self->__name]) || !isset($self->_engines[$self->__name])) { return false; } $name = $self->__name; if (!empty($settings)) { $self->__reset = true; } if ($self->__reset === true) { if (empty($settings)) { $self->__reset = false; $settings = $self->__config[$name]; } else { if (is_string($settings) && $value !== null) { $settings = array($settings => $value); } $settings = array_merge($self->__config[$name], $settings); if (isset($settings['duration']) && !is_numeric($settings['duration'])) { $settings['duration'] = strtotime($settings['duration']) - time(); } } $self->_engines[$name]->settings = $settings; } return $self->settings($name); }
Temporarily change settings to current config options. if no params are passed, resets settings if needed Cache::write() will reset the configuration changes made @param mixed $settings Optional string for simple name-value pair or array @param string $value Optional for a simple name-value pair @return array Array of settings. @access public @static
set
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function gc() { $self =& Cache::getInstance(); $self->_engines[$self->__name]->gc(); }
Garbage collection Permanently remove all expired and deleted data @return void @access public @static
gc
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function write($key, $value, $config = null) { $self =& Cache::getInstance(); if (!$config) { $config = $self->__name; } $settings = $self->settings($config); if (empty($settings)) { return null; } if (!$self->isInitialized($config)) { return false; } $key = $self->_engines[$config]->key($key); if (!$key || is_resource($value)) { return false; } $success = $self->_engines[$config]->write($settings['prefix'] . $key, $value, $settings['duration']); $self->set(); return $success; }
Write data for key into cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config() ### Usage: Writing to the active cache config: `Cache::write('cached_data', $data);` Writing to a specific cache config: `Cache::write('cached_data', $data, 'long_term');` @param string $key Identifier for the data @param mixed $value Data to be cached - anything except a resource @param string $config Optional string configuration name to write to. @return boolean True if the data was successfully cached, false on failure @access public @static
write
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function read($key, $config = null) { $self =& Cache::getInstance(); if (!$config) { $config = $self->__name; } $settings = $self->settings($config); if (empty($settings)) { return null; } if (!$self->isInitialized($config)) { return false; } $key = $self->_engines[$config]->key($key); if (!$key) { return false; } $success = $self->_engines[$config]->read($settings['prefix'] . $key); if ($config !== null && $config !== $self->__name) { $self->set(); } return $success; }
Read a key from the cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config() ### Usage: Reading from the active cache configuration. `Cache::read('my_data');` Reading from a specific cache configuration. `Cache::read('my_data', 'long_term');` @param string $key Identifier for the data @param string $config optional name of the configuration to use. @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it @access public @static
read
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function increment($key, $offset = 1, $config = null) { $self =& Cache::getInstance(); if (!$config) { $config = $self->__name; } $settings = $self->settings($config); if (empty($settings)) { return null; } if (!$self->isInitialized($config)) { return false; } $key = $self->_engines[$config]->key($key); if (!$key || !is_integer($offset) || $offset < 0) { return false; } $success = $self->_engines[$config]->increment($settings['prefix'] . $key, $offset); $self->set(); return $success; }
Increment a number under the key and return incremented value. @param string $key Identifier for the data @param integer $offset How much to add @param string $config Optional string configuration name. If not specified the current default config will be used. @return mixed new value, or false if the data doesn't exist, is not integer, or if there was an error fetching it. @access public
increment
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function decrement($key, $offset = 1, $config = null) { $self =& Cache::getInstance(); if (!$config) { $config = $self->__name; } $settings = $self->settings($config); if (empty($settings)) { return null; } if (!$self->isInitialized($config)) { return false; } $key = $self->_engines[$config]->key($key); if (!$key || !is_integer($offset) || $offset < 0) { return false; } $success = $self->_engines[$config]->decrement($settings['prefix'] . $key, $offset); $self->set(); return $success; }
Decrement a number under the key and return decremented value. @param string $key Identifier for the data @param integer $offset How much to substract @param string $config Optional string configuration name, if not specified the current default config will be used. @return mixed new value, or false if the data doesn't exist, is not integer, or if there was an error fetching it @access public
decrement
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function delete($key, $config = null) { $self =& Cache::getInstance(); if (!$config) { $config = $self->__name; } $settings = $self->settings($config); if (empty($settings)) { return null; } if (!$self->isInitialized($config)) { return false; } $key = $self->_engines[$config]->key($key); if (!$key) { return false; } $success = $self->_engines[$config]->delete($settings['prefix'] . $key); $self->set(); return $success; }
Delete a key from the cache. Will automatically use the currently active cache configuration. To set the currently active configuration use Cache::config() ### Usage: Deleting from the active cache configuration. `Cache::delete('my_data');` Deleting from a specific cache configuration. `Cache::delete('my_data', 'long_term');` @param string $key Identifier for the data @param string $config name of the configuration to use @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed @access public @static
delete
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function clear($check = false, $config = null) { $self =& Cache::getInstance(); if (!$config) { $config = $self->__name; } $settings = $self->settings($config); if (empty($settings)) { return null; } if (!$self->isInitialized($config)) { return false; } $success = $self->_engines[$config]->clear($check); $self->set(); return $success; }
Delete all keys from the cache. @param boolean $check if true will check expiration, otherwise delete all @param string $config name of the configuration to use @return boolean True if the cache was succesfully cleared, false otherwise @access public @static
clear
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function isInitialized($name = null) { if (Configure::read('Cache.disable')) { return false; } $self =& Cache::getInstance(); if (!$name && isset($self->__config[$self->__name])) { $name = $self->__name; } return isset($self->_engines[$name]); }
Check if Cache has initialized a working config for the given name. @param string $engine Name of the engine @param string $config Name of the configuration setting @return bool Whether or not the config name has been initialized. @access public @static
isInitialized
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function settings($name = null) { $self =& Cache::getInstance(); if (!$name && isset($self->__config[$self->__name])) { $name = $self->__name; } if (!empty($self->_engines[$name])) { return $self->_engines[$name]->settings(); } return array(); }
Return the settings for current cache engine. If no name is supplied the settings for the 'active default' configuration will be returned. To set the 'active default' configuration use `Cache::config()` @param string $engine Name of the configuration to get settings for. @return array list of settings for this engine @see Cache::config() @access public @static
settings
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function __destruct() { if (Configure::read('Session.save') == 'cache' && function_exists('session_write_close')) { session_write_close(); } }
Write the session when session data is persisted with cache. @return void @access public
__destruct
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function init($settings = array()) { $this->settings = array_merge( array('prefix' => 'cake_', 'duration'=> 3600, 'probability'=> 100), $this->settings, $settings ); if (!is_numeric($this->settings['duration'])) { $this->settings['duration'] = strtotime($this->settings['duration']) - time(); } return true; }
Initialize the cache engine Called automatically by the cache frontend @param array $params Associative array of parameters for the engine @return boolean True if the engine has been succesfully initialized, false if not @access public
init
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function write($key, &$value, $duration) { trigger_error(sprintf(__('Method write() not implemented in %s', true), get_class($this)), E_USER_ERROR); }
Write value for a key into cache @param string $key Identifier for the data @param mixed $value Data to be cached @param mixed $duration How long to cache the data, in seconds @return boolean True if the data was succesfully cached, false on failure @access public
write
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function read($key) { trigger_error(sprintf(__('Method read() not implemented in %s', true), get_class($this)), E_USER_ERROR); }
Read a key from the cache @param string $key Identifier for the data @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it @access public
read
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function increment($key, $offset = 1) { trigger_error(sprintf(__('Method increment() not implemented in %s', true), get_class($this)), E_USER_ERROR); }
Increment a number under the key and return incremented value @param string $key Identifier for the data @param integer $offset How much to add @return New incremented value, false otherwise @access public
increment
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function decrement($key, $offset = 1) { trigger_error(sprintf(__('Method decrement() not implemented in %s', true), get_class($this)), E_USER_ERROR); }
Decrement a number under the key and return decremented value @param string $key Identifier for the data @param integer $value How much to substract @return New incremented value, false otherwise @access public
decrement
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function settings() { return $this->settings; }
Cache Engine settings @return array settings @access public
settings
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function key($key) { if (empty($key)) { return false; } $key = Inflector::underscore(str_replace(array(DS, '/', '.'), '_', strval($key))); return $key; }
Generates a safe key for use with cache engine storage engines. @param string $key the key passed over @return mixed string $key or false @access public
key
php
Datawalke/Coordino
cake/libs/cache.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cache.php
MIT
function &getInstance() { static $instance = array(); if (!isset($instance[0])) { $instance[0] =& new CakeLog(); } return $instance[0]; }
Get an instance @return void @static
getInstance
php
Datawalke/Coordino
cake/libs/cake_log.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_log.php
MIT
function config($key, $config) { if (empty($config['engine'])) { trigger_error(__('Missing logger classname', true), E_USER_WARNING); return false; } $self =& CakeLog::getInstance(); $className = $self->_getLogger($config['engine']); if (!$className) { return false; } unset($config['engine']); $self->_streams[$key] = new $className($config); return true; }
Configure and add a new logging stream to CakeLog You can use add loggers from app/libs use app.loggername, or any plugin/libs using plugin.loggername. ### Usage: {{{ CakeLog::config('second_file', array( 'engine' => 'FileLog', 'path' => '/var/logs/my_app/' )); }}} Will configure a FileLog instance to use the specified path. All options that are not `engine` are passed onto the logging adapter, and handled there. Any class can be configured as a logging adapter as long as it implements a `write` method with the following signature. `write($type, $message)` For an explaination of these parameters, see CakeLog::write() @param string $key The keyname for this logger, used to remove the logger later. @param array $config Array of configuration information for the logger @return boolean success of configuration. @static
config
php
Datawalke/Coordino
cake/libs/cake_log.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_log.php
MIT
function _getLogger($loggerName) { list($plugin, $loggerName) = pluginSplit($loggerName); if ($plugin) { App::import('Lib', $plugin . '.log/' . $loggerName); } else { if (!App::import('Lib', 'log/' . $loggerName)) { App::import('Core', 'log/' . $loggerName); } } if (!class_exists($loggerName)) { trigger_error(sprintf(__('Could not load logger class %s', true), $loggerName), E_USER_WARNING); return false; } if (!is_callable(array($loggerName, 'write'))) { trigger_error( sprintf(__('logger class %s does not implement a write method.', true), $loggerName), E_USER_WARNING ); return false; } return $loggerName; }
Attempts to import a logger class from the various paths it could be on. Checks that the logger class implements a write method as well. @param string $loggerName the plugin.className of the logger class you want to build. @return mixed boolean false on any failures, string of classname to use if search was successful. @access protected
_getLogger
php
Datawalke/Coordino
cake/libs/cake_log.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_log.php
MIT
function configured() { $self =& CakeLog::getInstance(); return array_keys($self->_streams); }
Returns the keynames of the currently active streams @return array Array of configured log streams. @access public @static
configured
php
Datawalke/Coordino
cake/libs/cake_log.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_log.php
MIT
function drop($streamName) { $self =& CakeLog::getInstance(); unset($self->_streams[$streamName]); }
Removes a stream from the active streams. Once a stream has been removed it will no longer have messages sent to it. @param string $keyname Key name of a configured stream to remove. @return void @access public @static
drop
php
Datawalke/Coordino
cake/libs/cake_log.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_log.php
MIT
function _autoConfig() { if (!class_exists('FileLog')) { App::import('Core', 'log/FileLog'); } $this->_streams['default'] =& new FileLog(array('path' => LOGS)); }
Configures the automatic/default stream a FileLog. @return void @access protected
_autoConfig
php
Datawalke/Coordino
cake/libs/cake_log.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_log.php
MIT
function write($type, $message) { if (!defined('LOG_ERROR')) { define('LOG_ERROR', 2); } if (!defined('LOG_ERR')) { define('LOG_ERR', LOG_ERROR); } $levels = array( LOG_WARNING => 'warning', LOG_NOTICE => 'notice', LOG_INFO => 'info', LOG_DEBUG => 'debug', LOG_ERR => 'error', LOG_ERROR => 'error' ); if (is_int($type) && isset($levels[$type])) { $type = $levels[$type]; } $self =& CakeLog::getInstance(); if (empty($self->_streams)) { $self->_autoConfig(); } $keys = array_keys($self->_streams); foreach ($keys as $key) { $logger =& $self->_streams[$key]; $logger->write($type, $message); } return true; }
Writes the given message and type to all of the configured log adapters. Configured adapters are passed both the $type and $message variables. $type is one of the following strings/values. ### Types: - `LOG_WARNING` => 'warning', - `LOG_NOTICE` => 'notice', - `LOG_INFO` => 'info', - `LOG_DEBUG` => 'debug', - `LOG_ERR` => 'error', - `LOG_ERROR` => 'error' ### Usage: Write a message to the 'warning' log: `CakeLog::write('warning', 'Stuff is broken here');` @param string $type Type of message being written @param string $message Message content to log @return boolean Success @access public @static
write
php
Datawalke/Coordino
cake/libs/cake_log.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_log.php
MIT
function handleError($code, $description, $file = null, $line = null, $context = null) { if ($code === 2048 || $code === 8192 || error_reporting() === 0) { return; } switch ($code) { case E_PARSE: case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: $error = 'Fatal Error'; $level = LOG_ERROR; break; case E_WARNING: case E_USER_WARNING: case E_COMPILE_WARNING: case E_RECOVERABLE_ERROR: $error = 'Warning'; $level = LOG_WARNING; break; case E_NOTICE: case E_USER_NOTICE: $error = 'Notice'; $level = LOG_NOTICE; break; default: return; break; } $message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']'; CakeLog::write($level, $message); }
An error_handler that will log errors to file using CakeLog::write(); You can control how verbose and what type of errors this error_handler will catch using `Configure::write('log', $value)`. See core.php for more information. @param integer $code Code of error @param string $description Error description @param string $file File on which error occurred @param integer $line Line that triggered the error @param array $context Context @return void
handleError
php
Datawalke/Coordino
cake/libs/cake_log.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_log.php
MIT
function __construct($base = null, $start = true) { App::import('Core', array('Set', 'Security')); $this->time = time(); if (Configure::read('Session.checkAgent') === true || Configure::read('Session.checkAgent') === null) { if (env('HTTP_USER_AGENT') != null) { $this->_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt')); } } if (Configure::read('Session.save') === 'database') { $modelName = Configure::read('Session.model'); $database = Configure::read('Session.database'); $table = Configure::read('Session.table'); if (empty($database)) { $database = 'default'; } $settings = array( 'class' => 'Session', 'alias' => 'Session', 'table' => 'cake_sessions', 'ds' => $database ); if (!empty($modelName)) { $settings['class'] = $modelName; } if (!empty($table)) { $settings['table'] = $table; } ClassRegistry::init($settings); } if ($start === true) { if (!empty($base)) { $this->path = $base; if (strpos($base, 'index.php') !== false) { $this->path = str_replace('index.php', '', $base); } if (strpos($base, '?') !== false) { $this->path = str_replace('?', '', $base); } } $this->host = env('HTTP_HOST'); if (strpos($this->host, ':') !== false) { $this->host = substr($this->host, 0, strpos($this->host, ':')); } } if (isset($_SESSION) || $start === true) { $this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout')); $this->security = Configure::read('Security.level'); } parent::__construct(); }
Constructor. @param string $base The base path for the Session @param boolean $start Should session be started right now @access public
__construct
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function start() { if ($this->started()) { return true; } if (function_exists('session_write_close')) { session_write_close(); } $this->__initSession(); $this->__startSession(); return $this->started(); }
Starts the Session. @return boolean True if session was started @access public
start
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function started() { if (isset($_SESSION) && session_id()) { return true; } return false; }
Determine if Session has been started. @access public @return boolean True if session has been started.
started
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function check($name) { if (empty($name)) { return false; } $result = Set::classicExtract($_SESSION, $name); return isset($result); }
Returns true if given variable is set in session. @param string $name Variable name to check for @return boolean True if variable is there @access public
check
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function id($id = null) { if ($id) { $this->id = $id; session_id($this->id); } if ($this->started()) { return session_id(); } else { return $this->id; } }
Returns the Session id @param id $name string @return string Session id @access public
id
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function delete($name) { if ($this->check($name)) { if (in_array($name, $this->watchKeys)) { trigger_error(sprintf(__('Deleting session key {%s}', true), $name), E_USER_NOTICE); } $this->__overwrite($_SESSION, Set::remove($_SESSION, $name)); return ($this->check($name) == false); } $this->__setError(2, sprintf(__("%s doesn't exist", true), $name)); return false; }
Removes a variable from session. @param string $name Session variable to remove @return boolean Success @access public
delete
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function __overwrite(&$old, $new) { if (!empty($old)) { foreach ($old as $key => $var) { if (!isset($new[$key])) { unset($old[$key]); } } } foreach ($new as $key => $var) { $old[$key] = $var; } }
Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself @param array $old Set of old variables => values @param array $new New set of variable => value @access private
__overwrite
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function __error($errorNumber) { if (!is_array($this->error) || !array_key_exists($errorNumber, $this->error)) { return false; } else { return $this->error[$errorNumber]; } }
Return error description for given error number. @param integer $errorNumber Error to set @return string Error as string @access private
__error
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function error() { if ($this->lastError) { return $this->__error($this->lastError); } else { return false; } }
Returns last occurred error as a string, if any. @return mixed Error description as a string, or false. @access public
error
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function valid() { if ($this->read('Config')) { if ((Configure::read('Session.checkAgent') === false || $this->_userAgent == $this->read('Config.userAgent')) && $this->time <= $this->read('Config.time')) { if ($this->error === false) { $this->valid = true; } } else { $this->valid = false; $this->__setError(1, 'Session Highjacking Attempted !!!'); } } return $this->valid; }
Returns true if session is valid. @return boolean Success @access public
valid
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT
function read($name = null) { if (is_null($name)) { return $this->__returnSessionVars(); } if (empty($name)) { return false; } $result = Set::classicExtract($_SESSION, $name); if (!is_null($result)) { return $result; } $this->__setError(2, "$name doesn't exist"); return null; }
Returns given session variable, or all of them, if no parameters given. @param mixed $name The name of the session variable (or a path as sent to Set.extract) @return mixed The value of the session variable @access public
read
php
Datawalke/Coordino
cake/libs/cake_session.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/cake_session.php
MIT