a grand renaming so that the most significant portion of the name comes first
This commit is contained in:
26
php-practice/web-cake/html/cake/console/cake
Executable file
26
php-practice/web-cake/html/cake/console/cake
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
################################################################################
|
||||
#
|
||||
# Bake is a shell script for running CakePHP bake script
|
||||
# PHP versions 4 and 5
|
||||
#
|
||||
# CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
# Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
#
|
||||
# Licensed under The MIT License
|
||||
# Redistributions of files must retain the above copyright notice.
|
||||
#
|
||||
# @copyright Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
# @link http://cakephp.org CakePHP(tm) Project
|
||||
# @package cake
|
||||
# @subpackage cake.cake.console
|
||||
# @since CakePHP(tm) v 1.2.0.5012
|
||||
# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
#
|
||||
################################################################################
|
||||
LIB=${0/%cake/}
|
||||
APP=`pwd`
|
||||
|
||||
exec php -q ${LIB}cake.php -working "${APP}" "$@"
|
||||
|
||||
exit;
|
33
php-practice/web-cake/html/cake/console/cake.bat
Normal file
33
php-practice/web-cake/html/cake/console/cake.bat
Normal file
@@ -0,0 +1,33 @@
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::
|
||||
:: Bake is a shell script for running CakePHP bake script
|
||||
:: PHP versions 4 and 5
|
||||
::
|
||||
:: CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
:: Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
::
|
||||
:: Licensed under The MIT License
|
||||
:: Redistributions of files must retain the above copyright notice.
|
||||
::
|
||||
:: @copyright Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
:: @link http://cakephp.org CakePHP(tm) Project
|
||||
:: @package cake
|
||||
:: @subpackage cake.cake.console
|
||||
:: @since CakePHP(tm) v 1.2.0.5012
|
||||
:: @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
:: In order for this script to work as intended, the cake\console\ folder must be in your PATH
|
||||
|
||||
@echo.
|
||||
@echo off
|
||||
|
||||
SET app=%0
|
||||
SET lib=%~dp0
|
||||
|
||||
php -q "%lib%cake.php" -working "%CD%" %*
|
||||
|
||||
echo.
|
||||
|
||||
exit /B %ERRORLEVEL%
|
661
php-practice/web-cake/html/cake/console/cake.php
Normal file
661
php-practice/web-cake/html/cake/console/cake.php
Normal file
@@ -0,0 +1,661 @@
|
||||
#!/usr/bin/php -q
|
||||
<?php
|
||||
/**
|
||||
* Command-line code generation utility to automate programmer chores.
|
||||
*
|
||||
* Shell dispatcher class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
if (!defined('E_DEPRECATED')) {
|
||||
define('E_DEPRECATED', 8192);
|
||||
}
|
||||
/**
|
||||
* Shell dispatcher
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console
|
||||
*/
|
||||
class ShellDispatcher {
|
||||
|
||||
/**
|
||||
* Standard input stream.
|
||||
*
|
||||
* @var filehandle
|
||||
* @access public
|
||||
*/
|
||||
var $stdin;
|
||||
|
||||
/**
|
||||
* Standard output stream.
|
||||
*
|
||||
* @var filehandle
|
||||
* @access public
|
||||
*/
|
||||
var $stdout;
|
||||
|
||||
/**
|
||||
* Standard error stream.
|
||||
*
|
||||
* @var filehandle
|
||||
* @access public
|
||||
*/
|
||||
var $stderr;
|
||||
|
||||
/**
|
||||
* Contains command switches parsed from the command line.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $params = array();
|
||||
|
||||
/**
|
||||
* Contains arguments parsed from the command line.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $args = array();
|
||||
|
||||
/**
|
||||
* The file name of the shell that was invoked.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $shell = null;
|
||||
|
||||
/**
|
||||
* The class name of the shell that was invoked.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $shellClass = null;
|
||||
|
||||
/**
|
||||
* The command called if public methods are available.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $shellCommand = null;
|
||||
|
||||
/**
|
||||
* The path locations of shells.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $shellPaths = array();
|
||||
|
||||
/**
|
||||
* The path to the current shell location.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $shellPath = null;
|
||||
|
||||
/**
|
||||
* The name of the shell in camelized.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $shellName = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* The execution of the script is stopped after dispatching the request with
|
||||
* a status code of either 0 or 1 according to the result of the dispatch.
|
||||
*
|
||||
* @param array $args the argv
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function ShellDispatcher($args = array()) {
|
||||
set_time_limit(0);
|
||||
|
||||
$this->__initConstants();
|
||||
$this->parseParams($args);
|
||||
$this->_initEnvironment();
|
||||
$this->__buildPaths();
|
||||
$this->_stop($this->dispatch() === false ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines core configuration.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __initConstants() {
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
|
||||
ini_set('html_errors', false);
|
||||
ini_set('implicit_flush', true);
|
||||
ini_set('max_execution_time', 0);
|
||||
}
|
||||
|
||||
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
||||
define('PHP5', (PHP_VERSION >= 5));
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))));
|
||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
||||
define('DISABLE_DEFAULT_ERROR_HANDLING', false);
|
||||
define('CAKEPHP_SHELL', true);
|
||||
}
|
||||
require_once(CORE_PATH . 'cake' . DS . 'basics.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines current working environment.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function _initEnvironment() {
|
||||
$this->stdin = fopen('php://stdin', 'r');
|
||||
$this->stdout = fopen('php://stdout', 'w');
|
||||
$this->stderr = fopen('php://stderr', 'w');
|
||||
|
||||
if (!$this->__bootstrap()) {
|
||||
$this->stderr("\nCakePHP Console: ");
|
||||
$this->stderr("\nUnable to load Cake core:");
|
||||
$this->stderr("\tMake sure " . DS . 'cake' . DS . 'libs exists in ' . CAKE_CORE_INCLUDE_PATH);
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
if (!isset($this->args[0]) || !isset($this->params['working'])) {
|
||||
$this->stderr("\nCakePHP Console: ");
|
||||
$this->stderr('This file has been loaded incorrectly and cannot continue.');
|
||||
$this->stderr('Please make sure that ' . DIRECTORY_SEPARATOR . 'cake' . DIRECTORY_SEPARATOR . 'console is in your system path,');
|
||||
$this->stderr('and check the manual for the correct usage of this command.');
|
||||
$this->stderr('(http://manual.cakephp.org/)');
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
if (basename(__FILE__) != basename($this->args[0])) {
|
||||
$this->stderr("\nCakePHP Console: ");
|
||||
$this->stderr('Warning: the dispatcher may have been loaded incorrectly, which could lead to unexpected results...');
|
||||
if ($this->getInput('Continue anyway?', array('y', 'n'), 'y') == 'n') {
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
||||
$this->shiftArgs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the shell paths.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function __buildPaths() {
|
||||
$paths = array();
|
||||
if (!class_exists('Folder')) {
|
||||
require LIBS . 'folder.php';
|
||||
}
|
||||
$plugins = App::objects('plugin', null, false);
|
||||
foreach ((array)$plugins as $plugin) {
|
||||
$pluginPath = App::pluginPath($plugin);
|
||||
$path = $pluginPath . 'vendors' . DS . 'shells' . DS;
|
||||
if (file_exists($path)) {
|
||||
$paths[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
$vendorPaths = array_values(App::path('vendors'));
|
||||
foreach ($vendorPaths as $vendorPath) {
|
||||
$path = rtrim($vendorPath, DS) . DS . 'shells' . DS;
|
||||
if (file_exists($path)) {
|
||||
$paths[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
$this->shellPaths = array_values(array_unique(array_merge($paths, App::path('shells'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the environment and loads the Cake core.
|
||||
*
|
||||
* @return boolean Success.
|
||||
* @access private
|
||||
*/
|
||||
function __bootstrap() {
|
||||
|
||||
define('ROOT', $this->params['root']);
|
||||
define('APP_DIR', $this->params['app']);
|
||||
define('APP_PATH', $this->params['working'] . DS);
|
||||
define('WWW_ROOT', APP_PATH . $this->params['webroot'] . DS);
|
||||
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
|
||||
define('TMP', CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'tmp' . DS);
|
||||
}
|
||||
|
||||
$includes = array(
|
||||
CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'object.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'inflector.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'configure.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'file.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'cache.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'string.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'class_registry.php',
|
||||
CORE_PATH . 'cake' . DS . 'console' . DS . 'error.php'
|
||||
);
|
||||
|
||||
foreach ($includes as $inc) {
|
||||
if (!require($inc)) {
|
||||
$this->stderr("Failed to load Cake core file {$inc}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php'));
|
||||
|
||||
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
|
||||
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
|
||||
App::build();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the console
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function clear() {
|
||||
if (empty($this->params['noclear'])) {
|
||||
if ( DS === '/') {
|
||||
passthru('clear');
|
||||
} else {
|
||||
passthru('cls');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a CLI request
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function dispatch() {
|
||||
$arg = $this->shiftArgs();
|
||||
|
||||
if (!$arg) {
|
||||
$this->help();
|
||||
return false;
|
||||
}
|
||||
if ($arg == 'help') {
|
||||
$this->help();
|
||||
return true;
|
||||
}
|
||||
|
||||
list($plugin, $shell) = pluginSplit($arg);
|
||||
$this->shell = $shell;
|
||||
$this->shellName = Inflector::camelize($shell);
|
||||
$this->shellClass = $this->shellName . 'Shell';
|
||||
|
||||
$arg = null;
|
||||
|
||||
if (isset($this->args[0])) {
|
||||
$arg = $this->args[0];
|
||||
$this->shellCommand = Inflector::variable($arg);
|
||||
}
|
||||
|
||||
$Shell = $this->_getShell($plugin);
|
||||
|
||||
if (!$Shell) {
|
||||
$title = sprintf(__('Error: Class %s could not be loaded.', true), $this->shellClass);
|
||||
$this->stderr($title . "\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
$methods = array();
|
||||
|
||||
if (is_a($Shell, 'Shell')) {
|
||||
$Shell->initialize();
|
||||
$Shell->loadTasks();
|
||||
|
||||
foreach ($Shell->taskNames as $task) {
|
||||
if (is_a($Shell->{$task}, 'Shell')) {
|
||||
$Shell->{$task}->initialize();
|
||||
$Shell->{$task}->loadTasks();
|
||||
}
|
||||
}
|
||||
|
||||
$task = Inflector::camelize($arg);
|
||||
|
||||
if (in_array($task, $Shell->taskNames)) {
|
||||
$this->shiftArgs();
|
||||
$Shell->{$task}->startup();
|
||||
|
||||
if (isset($this->args[0]) && $this->args[0] == 'help') {
|
||||
if (method_exists($Shell->{$task}, 'help')) {
|
||||
$Shell->{$task}->help();
|
||||
} else {
|
||||
$this->help();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return $Shell->{$task}->execute();
|
||||
}
|
||||
$methods = array_diff(get_class_methods('Shell'), array('help'));
|
||||
}
|
||||
$methods = array_diff(get_class_methods($Shell), $methods);
|
||||
$added = in_array(strtolower($arg), array_map('strtolower', $methods));
|
||||
$private = $arg[0] == '_' && method_exists($Shell, $arg);
|
||||
|
||||
if (!$private) {
|
||||
if ($added) {
|
||||
$this->shiftArgs();
|
||||
$Shell->startup();
|
||||
return $Shell->{$arg}();
|
||||
}
|
||||
if (method_exists($Shell, 'main')) {
|
||||
$Shell->startup();
|
||||
return $Shell->main();
|
||||
}
|
||||
}
|
||||
|
||||
$title = sprintf(__('Error: Unknown %1$s command %2$s.', true), $this->shellName, $arg);
|
||||
$message = sprintf(__('For usage try `cake %s help`', true), $this->shell);
|
||||
$this->stderr($title . "\n" . $message . "\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shell to use, either plugin shell or application shell
|
||||
*
|
||||
* All paths in the shellPaths property are searched.
|
||||
* shell, shellPath and shellClass properties are taken into account.
|
||||
*
|
||||
* @param string $plugin Optionally the name of a plugin
|
||||
* @return mixed False if no shell could be found or an object on success
|
||||
* @access protected
|
||||
*/
|
||||
function _getShell($plugin = null) {
|
||||
foreach ($this->shellPaths as $path) {
|
||||
$this->shellPath = $path . $this->shell . '.php';
|
||||
$pluginShellPath = DS . $plugin . DS . 'vendors' . DS . 'shells' . DS;
|
||||
|
||||
if ((strpos($path, $pluginShellPath) !== false || !$plugin) && file_exists($this->shellPath)) {
|
||||
$loaded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isset($loaded)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!class_exists('Shell')) {
|
||||
require CONSOLE_LIBS . 'shell.php';
|
||||
}
|
||||
|
||||
if (!class_exists($this->shellClass)) {
|
||||
require $this->shellPath;
|
||||
}
|
||||
if (!class_exists($this->shellClass)) {
|
||||
return false;
|
||||
}
|
||||
$Shell = new $this->shellClass($this);
|
||||
return $Shell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompts the user for input, and returns it.
|
||||
*
|
||||
* @param string $prompt Prompt text.
|
||||
* @param mixed $options Array or string of options.
|
||||
* @param string $default Default input value.
|
||||
* @return Either the default value, or the user-provided input.
|
||||
* @access public
|
||||
*/
|
||||
function getInput($prompt, $options = null, $default = null) {
|
||||
if (!is_array($options)) {
|
||||
$printOptions = '';
|
||||
} else {
|
||||
$printOptions = '(' . implode('/', $options) . ')';
|
||||
}
|
||||
|
||||
if ($default === null) {
|
||||
$this->stdout($prompt . " $printOptions \n" . '> ', false);
|
||||
} else {
|
||||
$this->stdout($prompt . " $printOptions \n" . "[$default] > ", false);
|
||||
}
|
||||
$result = fgets($this->stdin);
|
||||
|
||||
if ($result === false) {
|
||||
exit;
|
||||
}
|
||||
$result = trim($result);
|
||||
|
||||
if ($default != null && empty($result)) {
|
||||
return $default;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs to the stdout filehandle.
|
||||
*
|
||||
* @param string $string String to output.
|
||||
* @param boolean $newline If true, the outputs gets an added newline.
|
||||
* @return integer Returns the number of bytes output to stdout.
|
||||
* @access public
|
||||
*/
|
||||
function stdout($string, $newline = true) {
|
||||
if ($newline) {
|
||||
return fwrite($this->stdout, $string . "\n");
|
||||
} else {
|
||||
return fwrite($this->stdout, $string);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs to the stderr filehandle.
|
||||
*
|
||||
* @param string $string Error text to output.
|
||||
* @access public
|
||||
*/
|
||||
function stderr($string) {
|
||||
fwrite($this->stderr, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses command line options
|
||||
*
|
||||
* @param array $params Parameters to parse
|
||||
* @access public
|
||||
*/
|
||||
function parseParams($params) {
|
||||
$this->__parseParams($params);
|
||||
$defaults = array('app' => 'app', 'root' => dirname(dirname(dirname(__FILE__))), 'working' => null, 'webroot' => 'webroot');
|
||||
$params = array_merge($defaults, array_intersect_key($this->params, $defaults));
|
||||
$isWin = false;
|
||||
foreach ($defaults as $default => $value) {
|
||||
if (strpos($params[$default], '\\') !== false) {
|
||||
$isWin = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$params = str_replace('\\', '/', $params);
|
||||
|
||||
if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0]{0} !== '.')) {
|
||||
if (empty($this->params['app']) && $params['working'] != $params['root']) {
|
||||
$params['root'] = dirname($params['working']);
|
||||
$params['app'] = basename($params['working']);
|
||||
} else {
|
||||
$params['root'] = $params['working'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['app'][0] == '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) {
|
||||
$params['root'] = dirname($params['app']);
|
||||
} elseif (strpos($params['app'], '/')) {
|
||||
$params['root'] .= '/' . dirname($params['app']);
|
||||
}
|
||||
|
||||
$params['app'] = basename($params['app']);
|
||||
$params['working'] = rtrim($params['root'], '/') . '/' . $params['app'];
|
||||
|
||||
if (!empty($matches[0]) || !empty($isWin)) {
|
||||
$params = str_replace('/', '\\', $params);
|
||||
}
|
||||
|
||||
$this->params = array_merge($this->params, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for recursively parsing params
|
||||
*
|
||||
* @return array params
|
||||
* @access private
|
||||
*/
|
||||
function __parseParams($params) {
|
||||
$count = count($params);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if (isset($params[$i])) {
|
||||
if ($params[$i]{0} === '-') {
|
||||
$key = substr($params[$i], 1);
|
||||
$this->params[$key] = true;
|
||||
unset($params[$i]);
|
||||
if (isset($params[++$i])) {
|
||||
if ($params[$i]{0} !== '-') {
|
||||
$this->params[$key] = str_replace('"', '', $params[$i]);
|
||||
unset($params[$i]);
|
||||
} else {
|
||||
$i--;
|
||||
$this->__parseParams($params);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->args[] = $params[$i];
|
||||
unset($params[$i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes first argument and shifts other arguments up
|
||||
*
|
||||
* @return mixed Null if there are no arguments otherwise the shifted argument
|
||||
* @access public
|
||||
*/
|
||||
function shiftArgs() {
|
||||
return array_shift($this->args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows console help
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->clear();
|
||||
$this->stdout("\nWelcome to CakePHP v" . Configure::version() . " Console");
|
||||
$this->stdout("---------------------------------------------------------------");
|
||||
$this->stdout("Current Paths:");
|
||||
$this->stdout(" -app: ". $this->params['app']);
|
||||
$this->stdout(" -working: " . rtrim($this->params['working'], DS));
|
||||
$this->stdout(" -root: " . rtrim($this->params['root'], DS));
|
||||
$this->stdout(" -core: " . rtrim(CORE_PATH, DS));
|
||||
$this->stdout("");
|
||||
$this->stdout("Changing Paths:");
|
||||
$this->stdout("your working path should be the same as your application path");
|
||||
$this->stdout("to change your path use the '-app' param.");
|
||||
$this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp");
|
||||
|
||||
$this->stdout("\nAvailable Shells:");
|
||||
$shellList = array();
|
||||
foreach ($this->shellPaths as $path) {
|
||||
if (!is_dir($path)) {
|
||||
continue;
|
||||
}
|
||||
$shells = App::objects('file', $path);
|
||||
if (empty($shells)) {
|
||||
continue;
|
||||
}
|
||||
if (preg_match('@plugins[\\\/]([^\\\/]*)@', $path, $matches)) {
|
||||
$type = Inflector::camelize($matches[1]);
|
||||
} elseif (preg_match('@([^\\\/]*)[\\\/]vendors[\\\/]@', $path, $matches)) {
|
||||
$type = $matches[1];
|
||||
} elseif (strpos($path, CAKE_CORE_INCLUDE_PATH . DS . 'cake') === 0) {
|
||||
$type = 'CORE';
|
||||
} else {
|
||||
$type = 'app';
|
||||
}
|
||||
foreach ($shells as $shell) {
|
||||
if ($shell !== 'shell.php') {
|
||||
$shell = str_replace('.php', '', $shell);
|
||||
$shellList[$shell][$type] = $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($shellList) {
|
||||
ksort($shellList);
|
||||
if (DS === '/') {
|
||||
$width = exec('tput cols') - 2;
|
||||
}
|
||||
if (empty($width)) {
|
||||
$width = 80;
|
||||
}
|
||||
$columns = max(1, floor($width / 30));
|
||||
$rows = ceil(count($shellList) / $columns);
|
||||
|
||||
foreach ($shellList as $shell => $types) {
|
||||
sort($types);
|
||||
$shellList[$shell] = str_pad($shell . ' [' . implode ($types, ', ') . ']', $width / $columns);
|
||||
}
|
||||
$out = array_chunk($shellList, $rows);
|
||||
for ($i = 0; $i < $rows; $i++) {
|
||||
$row = '';
|
||||
for ($j = 0; $j < $columns; $j++) {
|
||||
if (!isset($out[$j][$i])) {
|
||||
continue;
|
||||
}
|
||||
$row .= $out[$j][$i];
|
||||
}
|
||||
$this->stdout(" " . $row);
|
||||
}
|
||||
}
|
||||
$this->stdout("\nTo run a command, type 'cake shell_name [args]'");
|
||||
$this->stdout("To get help on a specific command, type 'cake shell_name help'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop execution of the current script
|
||||
*
|
||||
* @param $status see http://php.net/exit for values
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function _stop($status = 0) {
|
||||
exit($status);
|
||||
}
|
||||
}
|
||||
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
||||
$dispatcher = new ShellDispatcher($argv);
|
||||
}
|
265
php-practice/web-cake/html/cake/console/error.php
Normal file
265
php-practice/web-cake/html/cake/console/error.php
Normal file
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* ErrorHandler for Console Shells
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console
|
||||
* @since CakePHP(tm) v 1.2.0.5074
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Error Handler for Cake console.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console
|
||||
*/
|
||||
class ErrorHandler extends Object {
|
||||
|
||||
/**
|
||||
* Standard output stream.
|
||||
*
|
||||
* @var filehandle
|
||||
* @access public
|
||||
*/
|
||||
var $stdout;
|
||||
|
||||
/**
|
||||
* Standard error stream.
|
||||
*
|
||||
* @var filehandle
|
||||
* @access public
|
||||
*/
|
||||
var $stderr;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $method Method dispatching an error
|
||||
* @param array $messages Error messages
|
||||
*/
|
||||
function __construct($method, $messages) {
|
||||
$this->stdout = fopen('php://stdout', 'w');
|
||||
$this->stderr = fopen('php://stderr', 'w');
|
||||
call_user_func_array(array(&$this, $method), $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error page (e.g. 404 Not found).
|
||||
*
|
||||
* @param array $params Parameters (code, name, and message)
|
||||
* @access public
|
||||
*/
|
||||
function error($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr($code . $name . $message."\n");
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to display a 404 page.
|
||||
*
|
||||
* @param array $params Parameters (url, message)
|
||||
* @access public
|
||||
*/
|
||||
function error404($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->error(array(
|
||||
'code' => '404',
|
||||
'name' => 'Not found',
|
||||
'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)
|
||||
));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Controller web page.
|
||||
*
|
||||
* @param array $params Parameters (className)
|
||||
* @access public
|
||||
*/
|
||||
function missingController($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$controllerName = str_replace('Controller', '', $className);
|
||||
$this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Action web page.
|
||||
*
|
||||
* @param array $params Parameters (action, className)
|
||||
* @access public
|
||||
*/
|
||||
function missingAction($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Private Action web page.
|
||||
*
|
||||
* @param array $params Parameters (action, className)
|
||||
* @access public
|
||||
*/
|
||||
function privateAction($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Table web page.
|
||||
*
|
||||
* @param array $params Parameters (table, className)
|
||||
* @access public
|
||||
*/
|
||||
function missingTable($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Database web page.
|
||||
*
|
||||
* @param array $params Parameters
|
||||
* @access public
|
||||
*/
|
||||
function missingDatabase($params = array()) {
|
||||
$this->stderr(__("Missing Database", true));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing View web page.
|
||||
*
|
||||
* @param array $params Parameters (file, action, className)
|
||||
* @access public
|
||||
*/
|
||||
function missingView($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Layout web page.
|
||||
*
|
||||
* @param array $params Parameters (file)
|
||||
* @access public
|
||||
*/
|
||||
function missingLayout($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Database Connection web page.
|
||||
*
|
||||
* @param array $params Parameters
|
||||
* @access public
|
||||
*/
|
||||
function missingConnection($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Helper file web page.
|
||||
*
|
||||
* @param array $params Parameters (file, helper)
|
||||
* @access public
|
||||
*/
|
||||
function missingHelperFile($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper)));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Helper class web page.
|
||||
*
|
||||
* @param array $params Parameters (file, helper)
|
||||
* @access public
|
||||
*/
|
||||
function missingHelperClass($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Component file web page.
|
||||
*
|
||||
* @param array $params Parameters (file, component)
|
||||
* @access public
|
||||
*/
|
||||
function missingComponentFile($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component)));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Component class web page.
|
||||
*
|
||||
* @param array $params Parameters (file, component)
|
||||
* @access public
|
||||
*/
|
||||
function missingComponentClass($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Model class web page.
|
||||
*
|
||||
* @param array $params Parameters (className)
|
||||
* @access public
|
||||
*/
|
||||
function missingModel($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing model '%s'", true), $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs to the stdout filehandle.
|
||||
*
|
||||
* @param string $string String to output.
|
||||
* @param boolean $newline If true, the outputs gets an added newline.
|
||||
* @access public
|
||||
*/
|
||||
function stdout($string, $newline = true) {
|
||||
if ($newline) {
|
||||
fwrite($this->stdout, $string . "\n");
|
||||
} else {
|
||||
fwrite($this->stdout, $string);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs to the stderr filehandle.
|
||||
*
|
||||
* @param string $string Error text to output.
|
||||
* @access public
|
||||
*/
|
||||
function stderr($string) {
|
||||
fwrite($this->stderr, "Error: ". $string . "\n");
|
||||
}
|
||||
}
|
602
php-practice/web-cake/html/cake/console/libs/acl.php
Normal file
602
php-practice/web-cake/html/cake/console/libs/acl.php
Normal file
@@ -0,0 +1,602 @@
|
||||
<?php
|
||||
/**
|
||||
* Acl Shell provides Acl access in the CLI environment
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Component', 'Acl');
|
||||
App::import('Model', 'DbAcl');
|
||||
|
||||
/**
|
||||
* Shell for ACL management. This console is known to have issues with zend.ze1_compatibility_mode
|
||||
* being enabled. Be sure to turn it off when using this shell.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
*/
|
||||
class AclShell extends Shell {
|
||||
|
||||
/**
|
||||
* Contains instance of AclComponent
|
||||
*
|
||||
* @var AclComponent
|
||||
* @access public
|
||||
*/
|
||||
var $Acl;
|
||||
|
||||
/**
|
||||
* Contains arguments parsed from the command line.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $args;
|
||||
|
||||
/**
|
||||
* Contains database source to use
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $connection = 'default';
|
||||
|
||||
/**
|
||||
* Contains tasks to load and instantiate
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('DbConfig');
|
||||
|
||||
/**
|
||||
* Override startup of the Shell
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function startup() {
|
||||
if (isset($this->params['connection'])) {
|
||||
$this->connection = $this->params['connection'];
|
||||
}
|
||||
|
||||
if (!in_array(Configure::read('Acl.classname'), array('DbAcl', 'DB_ACL'))) {
|
||||
$out = "--------------------------------------------------\n";
|
||||
$out .= __("Error: Your current Cake configuration is set to", true) . "\n";
|
||||
$out .= __("an ACL implementation other than DB. Please change", true) . "\n";
|
||||
$out .= __("your core config to reflect your decision to use", true) . "\n";
|
||||
$out .= __("DbAcl before attempting to use this script", true) . ".\n";
|
||||
$out .= "--------------------------------------------------\n";
|
||||
$out .= sprintf(__("Current ACL Classname: %s", true), Configure::read('Acl.classname')) . "\n";
|
||||
$out .= "--------------------------------------------------\n";
|
||||
$this->err($out);
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
if ($this->command && !in_array($this->command, array('help'))) {
|
||||
if (!config('database')) {
|
||||
$this->out(__("Your database configuration was not found. Take a moment to create one.", true), true);
|
||||
$this->args = null;
|
||||
return $this->DbConfig->execute();
|
||||
}
|
||||
require_once (CONFIGS.'database.php');
|
||||
|
||||
if (!in_array($this->command, array('initdb'))) {
|
||||
$this->Acl =& new AclComponent();
|
||||
$controller = null;
|
||||
$this->Acl->startup($controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override main() for help message hook
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function main() {
|
||||
$out = __("Available ACL commands:", true) . "\n";
|
||||
$out .= "\t - create\n";
|
||||
$out .= "\t - delete\n";
|
||||
$out .= "\t - setParent\n";
|
||||
$out .= "\t - getPath\n";
|
||||
$out .= "\t - check\n";
|
||||
$out .= "\t - grant\n";
|
||||
$out .= "\t - deny\n";
|
||||
$out .= "\t - inherit\n";
|
||||
$out .= "\t - view\n";
|
||||
$out .= "\t - initdb\n";
|
||||
$out .= "\t - help\n\n";
|
||||
$out .= __("For help, run the 'help' command. For help on a specific command, run 'help <command>'", true);
|
||||
$this->out($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ARO/ACO node
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function create() {
|
||||
$this->_checkArgs(3, 'create');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
|
||||
$class = ucfirst($this->args[0]);
|
||||
$parent = $this->parseIdentifier($this->args[1]);
|
||||
|
||||
if (!empty($parent) && $parent != '/' && $parent != 'root') {
|
||||
$parent = $this->_getNodeId($class, $parent);
|
||||
} else {
|
||||
$parent = null;
|
||||
}
|
||||
|
||||
$data = $this->parseIdentifier($this->args[2]);
|
||||
if (is_string($data) && $data != '/') {
|
||||
$data = array('alias' => $data);
|
||||
} elseif (is_string($data)) {
|
||||
$this->error(__('/ can not be used as an alias!', true), __("\t/ is the root, please supply a sub alias", true));
|
||||
}
|
||||
|
||||
$data['parent_id'] = $parent;
|
||||
$this->Acl->{$class}->create();
|
||||
if ($this->Acl->{$class}->save($data)) {
|
||||
$this->out(sprintf(__("New %s '%s' created.\n", true), $class, $this->args[2]), true);
|
||||
} else {
|
||||
$this->err(sprintf(__("There was a problem creating a new %s '%s'.", true), $class, $this->args[2]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an ARO/ACO node.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function delete() {
|
||||
$this->_checkArgs(2, 'delete');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
|
||||
$identifier = $this->parseIdentifier($this->args[1]);
|
||||
$nodeId = $this->_getNodeId($class, $identifier);
|
||||
|
||||
if (!$this->Acl->{$class}->delete($nodeId)) {
|
||||
$this->error(__("Node Not Deleted", true), sprintf(__("There was an error deleting the %s. Check that the node exists", true), $class) . ".\n");
|
||||
}
|
||||
$this->out(sprintf(__("%s deleted", true), $class) . ".\n", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent for an ARO/ACO node.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function setParent() {
|
||||
$this->_checkArgs(3, 'setParent');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
$target = $this->parseIdentifier($this->args[1]);
|
||||
$parent = $this->parseIdentifier($this->args[2]);
|
||||
|
||||
$data = array(
|
||||
$class => array(
|
||||
'id' => $this->_getNodeId($class, $target),
|
||||
'parent_id' => $this->_getNodeId($class, $parent)
|
||||
)
|
||||
);
|
||||
$this->Acl->{$class}->create();
|
||||
if (!$this->Acl->{$class}->save($data)) {
|
||||
$this->out(__("Error in setting new parent. Please make sure the parent node exists, and is not a descendant of the node specified.", true), true);
|
||||
} else {
|
||||
$this->out(sprintf(__("Node parent set to %s", true), $this->args[2]) . "\n", true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path to specified ARO/ACO node.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function getPath() {
|
||||
$this->_checkArgs(2, 'getPath');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
$identifier = $this->parseIdentifier($this->args[1]);
|
||||
|
||||
$id = $this->_getNodeId($class, $identifier);
|
||||
$nodes = $this->Acl->{$class}->getPath($id);
|
||||
|
||||
if (empty($nodes)) {
|
||||
$this->error(
|
||||
sprintf(__("Supplied Node '%s' not found", true), $this->args[1]),
|
||||
__("No tree returned.", true)
|
||||
);
|
||||
}
|
||||
$this->out(__('Path:', true));
|
||||
$this->hr();
|
||||
for ($i = 0; $i < count($nodes); $i++) {
|
||||
$this->_outputNode($class, $nodes[$i], $i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a single node, Either using the alias or Model.key
|
||||
*
|
||||
* @param string $class Class name that is being used.
|
||||
* @param array $node Array of node information.
|
||||
* @param integer $indent indent level.
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function _outputNode($class, $node, $indent) {
|
||||
$indent = str_repeat(' ', $indent);
|
||||
$data = $node[$class];
|
||||
if ($data['alias']) {
|
||||
$this->out($indent . "[" . $data['id'] . "] " . $data['alias']);
|
||||
} else {
|
||||
$this->out($indent . "[" . $data['id'] . "] " . $data['model'] . '.' . $data['foreign_key']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check permission for a given ARO to a given ACO.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function check() {
|
||||
$this->_checkArgs(3, 'check');
|
||||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->check($aro, $aco, $action)) {
|
||||
$this->out(sprintf(__("%s is allowed.", true), $aroName), true);
|
||||
} else {
|
||||
$this->out(sprintf(__("%s is not allowed.", true), $aroName), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant permission for a given ARO to a given ACO.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function grant() {
|
||||
$this->_checkArgs(3, 'grant');
|
||||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->allow($aro, $aco, $action)) {
|
||||
$this->out(__("Permission granted.", true), true);
|
||||
} else {
|
||||
$this->out(__("Permission was not granted.", true), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deny access for an ARO to an ACO.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function deny() {
|
||||
$this->_checkArgs(3, 'deny');
|
||||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->deny($aro, $aco, $action)) {
|
||||
$this->out(__("Permission denied.", true), true);
|
||||
} else {
|
||||
$this->out(__("Permission was not denied.", true), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an ARO to inhermit permission to an ACO.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function inherit() {
|
||||
$this->_checkArgs(3, 'inherit');
|
||||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->inherit($aro, $aco, $action)) {
|
||||
$this->out(__("Permission inherited.", true), true);
|
||||
} else {
|
||||
$this->out(__("Permission was not inherited.", true), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a specific ARO/ACO node.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function view() {
|
||||
$this->_checkArgs(1, 'view');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
|
||||
if (isset($this->args[1])) {
|
||||
$identity = $this->parseIdentifier($this->args[1]);
|
||||
|
||||
$topNode = $this->Acl->{$class}->find('first', array(
|
||||
'conditions' => array($class . '.id' => $this->_getNodeId($class, $identity))
|
||||
));
|
||||
|
||||
$nodes = $this->Acl->{$class}->find('all', array(
|
||||
'conditions' => array(
|
||||
$class . '.lft >=' => $topNode[$class]['lft'],
|
||||
$class . '.lft <=' => $topNode[$class]['rght']
|
||||
),
|
||||
'order' => $class . '.lft ASC'
|
||||
));
|
||||
} else {
|
||||
$nodes = $this->Acl->{$class}->find('all', array('order' => $class . '.lft ASC'));
|
||||
}
|
||||
|
||||
if (empty($nodes)) {
|
||||
if (isset($this->args[1])) {
|
||||
$this->error(sprintf(__("%s not found", true), $this->args[1]), __("No tree returned.", true));
|
||||
} elseif (isset($this->args[0])) {
|
||||
$this->error(sprintf(__("%s not found", true), $this->args[0]), __("No tree returned.", true));
|
||||
}
|
||||
}
|
||||
$this->out($class . " tree:");
|
||||
$this->hr();
|
||||
|
||||
$stack = array();
|
||||
$last = null;
|
||||
|
||||
foreach ($nodes as $n) {
|
||||
$stack[] = $n;
|
||||
if (!empty($last)) {
|
||||
$end = end($stack);
|
||||
if ($end[$class]['rght'] > $last) {
|
||||
foreach ($stack as $k => $v) {
|
||||
$end = end($stack);
|
||||
if ($v[$class]['rght'] < $end[$class]['rght']) {
|
||||
unset($stack[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$last = $n[$class]['rght'];
|
||||
$count = count($stack);
|
||||
|
||||
$this->_outputNode($class, $n, $count);
|
||||
}
|
||||
$this->hr();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize ACL database.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initdb() {
|
||||
$this->Dispatch->args = array('schema', 'create', 'DbAcl');
|
||||
$this->Dispatch->dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help screen.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$head = "-----------------------------------------------\n";
|
||||
$head .= __("Usage: cake acl <command> <arg1> <arg2>...", true) . "\n";
|
||||
$head .= "-----------------------------------------------\n";
|
||||
$head .= __("Commands:", true) . "\n";
|
||||
|
||||
$commands = array(
|
||||
'create' => "create aro|aco <parent> <node>\n" .
|
||||
"\t" . __("Creates a new ACL object <node> under the parent", true) . "\n" .
|
||||
"\t" . __("specified by <parent>, an id/alias.", true) . "\n" .
|
||||
"\t" . __("The <parent> and <node> references can be", true) . "\n" .
|
||||
"\t" . __("in one of the following formats:", true) . "\n\n" .
|
||||
"\t\t- " . __("<model>.<id> - The node will be bound to a", true) . "\n" .
|
||||
"\t\t" . __("specific record of the given model.", true) . "\n\n" .
|
||||
"\t\t- " . __("<alias> - The node will be given a string alias,", true) . "\n" .
|
||||
"\t\t" . __(" (or path, in the case of <parent>)", true) . "\n" .
|
||||
"\t\t " . __("i.e. 'John'. When used with <parent>,", true) . "\n" .
|
||||
"\t\t" . __("this takes the form of an alias path,", true) . "\n" .
|
||||
"\t\t " . __("i.e. <group>/<subgroup>/<parent>.", true) . "\n\n" .
|
||||
"\t" . __("To add a node at the root level,", true) . "\n" .
|
||||
"\t" . __("enter 'root' or '/' as the <parent> parameter.", true) . "\n",
|
||||
|
||||
'delete' => "delete aro|aco <node>\n" .
|
||||
"\t" . __("Deletes the ACL object with the given <node> reference", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'setparent' => "setParent aro|aco <node> <parent node>\n" .
|
||||
"\t" . __("Moves the ACL object specified by <node> beneath", true) . "\n" .
|
||||
"\t" . __("the parent ACL object specified by <parent>.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'getpath' => "getPath aro|aco <node>\n" .
|
||||
"\t" . __("Returns the path to the ACL object specified by <node>. This command", true) . "\n" .
|
||||
"\t" . __("is useful in determining the inhertiance of permissions for a certain", true) . "\n" .
|
||||
"\t" . __("object in the tree.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'check' => "check <node> <node> [<aco_action>] " . __("or", true) . " all\n" .
|
||||
"\t" . __("Use this command to check ACL permissions.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'grant' => "grant <aronode> <aconode> [<aco_action>] " . __("or", true) . " all\n" .
|
||||
"\t" . __("Use this command to grant ACL permissions. Once executed, the ARO", true) . "\n" .
|
||||
"\t" . __("specified (and its children, if any) will have ALLOW access to the", true) . "\n" .
|
||||
"\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'deny' => "deny <aronode> <aconode> [<aco_action>]" . __("or", true) . " all\n" .
|
||||
"\t" . __("Use this command to deny ACL permissions. Once executed, the ARO", true) . "\n" .
|
||||
"\t" . __("specified (and its children, if any) will have DENY access to the", true) . "\n" .
|
||||
"\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'inherit' => "inherit <aronode> <aconode> [<aco_action>]" . __("or", true) . " all\n" .
|
||||
"\t" . __("Use this command to force a child ARO object to inherit its", true) . "\n" .
|
||||
"\t" . __("permissions settings from its parent.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'view' => "view aro|aco [<node>]\n" .
|
||||
"\t" . __("The view command will return the ARO or ACO tree.", true) . "\n" .
|
||||
"\t" . __("The optional node parameter allows you to return", true) . "\n" .
|
||||
"\t" . __("only a portion of the requested tree.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'initdb' => "initdb\n".
|
||||
"\t" . __("Uses this command : cake schema run create DbAcl", true),
|
||||
|
||||
'help' => "help [<command>]\n" .
|
||||
"\t" . __("Displays this help message, or a message on a specific command.", true)
|
||||
);
|
||||
|
||||
$this->out($head);
|
||||
if (!isset($this->args[0])) {
|
||||
foreach ($commands as $cmd) {
|
||||
$this->out("{$cmd}\n\n");
|
||||
}
|
||||
} elseif (isset($commands[strtolower($this->args[0])])) {
|
||||
$this->out($commands[strtolower($this->args[0])] . "\n\n");
|
||||
} else {
|
||||
$this->out(sprintf(__("Command '%s' not found", true), $this->args[0]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that first argument specifies a valid Node type (ARO/ACO)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function checkNodeType() {
|
||||
if (!isset($this->args[0])) {
|
||||
return false;
|
||||
}
|
||||
if ($this->args[0] != 'aco' && $this->args[0] != 'aro') {
|
||||
$this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[0]), __('Please specify which ACL object type you wish to create. Either "aro" or "aco"', true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that given node exists
|
||||
*
|
||||
* @param string $type Node type (ARO/ACO)
|
||||
* @param integer $id Node id
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
function nodeExists() {
|
||||
if (!$this->checkNodeType() && !isset($this->args[1])) {
|
||||
return false;
|
||||
}
|
||||
extract($this->__dataVars($this->args[0]));
|
||||
$key = is_numeric($this->args[1]) ? $secondary_id : 'alias';
|
||||
$conditions = array($class . '.' . $key => $this->args[1]);
|
||||
$possibility = $this->Acl->{$class}->find('all', compact('conditions'));
|
||||
if (empty($possibility)) {
|
||||
$this->error(sprintf(__("%s not found", true), $this->args[1]), __("No tree returned.", true));
|
||||
}
|
||||
return $possibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an identifier into Model.foriegnKey or an alias.
|
||||
* Takes an identifier determines its type and returns the result as used by other methods.
|
||||
*
|
||||
* @param string $identifier Identifier to parse
|
||||
* @return mixed a string for aliases, and an array for model.foreignKey
|
||||
*/
|
||||
function parseIdentifier($identifier) {
|
||||
if (preg_match('/^([\w]+)\.(.*)$/', $identifier, $matches)) {
|
||||
return array(
|
||||
'model' => $matches[1],
|
||||
'foreign_key' => $matches[2],
|
||||
);
|
||||
}
|
||||
return $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the node for a given identifier. $identifier can either be a string alias
|
||||
* or an array of properties to use in AcoNode::node()
|
||||
*
|
||||
* @param string $class Class type you want (Aro/Aco)
|
||||
* @param mixed $identifier A mixed identifier for finding the node.
|
||||
* @return int Integer of NodeId. Will trigger an error if nothing is found.
|
||||
*/
|
||||
function _getNodeId($class, $identifier) {
|
||||
$node = $this->Acl->{$class}->node($identifier);
|
||||
if (empty($node)) {
|
||||
if (is_array($identifier)) {
|
||||
$identifier = var_export($identifier, true);
|
||||
}
|
||||
$this->error(sprintf(__('Could not find node using reference "%s"', true), $identifier));
|
||||
}
|
||||
return Set::extract($node, "0.{$class}.id");
|
||||
}
|
||||
|
||||
/**
|
||||
* get params for standard Acl methods
|
||||
*
|
||||
* @return array aro, aco, action
|
||||
* @access private
|
||||
*/
|
||||
function __getParams() {
|
||||
$aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0];
|
||||
$aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1];
|
||||
$aroName = $aro;
|
||||
$acoName = $aco;
|
||||
|
||||
if (is_string($aro)) {
|
||||
$aro = $this->parseIdentifier($aro);
|
||||
}
|
||||
if (is_string($aco)) {
|
||||
$aco = $this->parseIdentifier($aco);
|
||||
}
|
||||
$action = null;
|
||||
if (isset($this->args[2])) {
|
||||
$action = $this->args[2];
|
||||
if ($action == '' || $action == 'all') {
|
||||
$action = '*';
|
||||
}
|
||||
}
|
||||
return compact('aro', 'aco', 'action', 'aroName', 'acoName');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build data parameters based on node type
|
||||
*
|
||||
* @param string $type Node type (ARO/ACO)
|
||||
* @return array Variables
|
||||
* @access private
|
||||
*/
|
||||
function __dataVars($type = null) {
|
||||
if ($type == null) {
|
||||
$type = $this->args[0];
|
||||
}
|
||||
$vars = array();
|
||||
$class = ucwords($type);
|
||||
$vars['secondary_id'] = (strtolower($class) == 'aro') ? 'foreign_key' : 'object_id';
|
||||
$vars['data_name'] = $type;
|
||||
$vars['table_name'] = $type . 's';
|
||||
$vars['class'] = $class;
|
||||
return $vars;
|
||||
}
|
||||
}
|
213
php-practice/web-cake/html/cake/console/libs/api.php
Normal file
213
php-practice/web-cake/html/cake/console/libs/api.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
/**
|
||||
* API shell to get CakePHP core method signatures.
|
||||
*
|
||||
* Implementation of a Cake Shell to show CakePHP core method signatures.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* API shell to show method signatures of CakePHP core classes.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
*/
|
||||
class ApiShell extends Shell {
|
||||
|
||||
/**
|
||||
* Map between short name for paths and real paths.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $paths = array();
|
||||
|
||||
/**
|
||||
* Override intialize of the Shell
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {
|
||||
$this->paths = array_merge($this->paths, array(
|
||||
'behavior' => LIBS . 'model' . DS . 'behaviors' . DS,
|
||||
'cache' => LIBS . 'cache' . DS,
|
||||
'controller' => LIBS . 'controller' . DS,
|
||||
'component' => LIBS . 'controller' . DS . 'components' . DS,
|
||||
'helper' => LIBS . 'view' . DS . 'helpers' . DS,
|
||||
'model' => LIBS . 'model' . DS,
|
||||
'view' => LIBS . 'view' . DS,
|
||||
'core' => LIBS
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Override main() to handle action
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function main() {
|
||||
if (empty($this->args)) {
|
||||
return $this->help();
|
||||
}
|
||||
|
||||
$type = strtolower($this->args[0]);
|
||||
|
||||
if (isset($this->paths[$type])) {
|
||||
$path = $this->paths[$type];
|
||||
} else {
|
||||
$path = $this->paths['core'];
|
||||
}
|
||||
|
||||
if (count($this->args) == 1) {
|
||||
$file = $type;
|
||||
$class = Inflector::camelize($type);
|
||||
} elseif (count($this->args) > 1) {
|
||||
$file = Inflector::underscore($this->args[1]);
|
||||
$class = Inflector::camelize($file);
|
||||
}
|
||||
|
||||
$objects = App::objects('class', $path);
|
||||
if (in_array($class, $objects)) {
|
||||
if (in_array($type, array('behavior', 'component', 'helper')) && $type !== $file) {
|
||||
if (!preg_match('/' . Inflector::camelize($type) . '$/', $class)) {
|
||||
$class .= Inflector::camelize($type);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->err(sprintf(__("%s not found", true), $class));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$parsed = $this->__parseClass($path . $file .'.php');
|
||||
|
||||
if (!empty($parsed)) {
|
||||
if (isset($this->params['m'])) {
|
||||
if (!isset($parsed[$this->params['m']])) {
|
||||
$this->err(sprintf(__("%s::%s() could not be found", true), $class, $this->params['m']));
|
||||
$this->_stop();
|
||||
}
|
||||
$method = $parsed[$this->params['m']];
|
||||
$this->out($class .'::'.$method['method'] . $method['parameters']);
|
||||
$this->hr();
|
||||
$this->out($method['comment'], true);
|
||||
} else {
|
||||
$this->out(ucwords($class));
|
||||
$this->hr();
|
||||
$i = 0;
|
||||
foreach ($parsed as $method) {
|
||||
$list[] = ++$i . ". " . $method['method'] . $method['parameters'];
|
||||
}
|
||||
$this->out($list);
|
||||
|
||||
$methods = array_keys($parsed);
|
||||
while ($number = strtolower($this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.', true), null, 'q'))) {
|
||||
if ($number === 'q') {
|
||||
$this->out(__('Done', true));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
if ($number === 'l') {
|
||||
$this->out($list);
|
||||
}
|
||||
|
||||
if (isset($methods[--$number])) {
|
||||
$method = $parsed[$methods[$number]];
|
||||
$this->hr();
|
||||
$this->out($class .'::'.$method['method'] . $method['parameters']);
|
||||
$this->hr();
|
||||
$this->out($method['comment'], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help for this shell.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$head = "Usage: cake api [<type>] <className> [-m <method>]\n";
|
||||
$head .= "-----------------------------------------------\n";
|
||||
$head .= "Parameters:\n\n";
|
||||
|
||||
$commands = array(
|
||||
'path' => "\t<type>\n" .
|
||||
"\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
|
||||
"\t\tAvailable values:\n\n".
|
||||
"\t\tbehavior\tLook for class in CakePHP behavior path\n".
|
||||
"\t\tcache\tLook for class in CakePHP cache path\n".
|
||||
"\t\tcontroller\tLook for class in CakePHP controller path\n".
|
||||
"\t\tcomponent\tLook for class in CakePHP component path\n".
|
||||
"\t\thelper\tLook for class in CakePHP helper path\n".
|
||||
"\t\tmodel\tLook for class in CakePHP model path\n".
|
||||
"\t\tview\tLook for class in CakePHP view path\n",
|
||||
'className' => "\t<className>\n" .
|
||||
"\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
|
||||
);
|
||||
|
||||
$this->out($head);
|
||||
if (!isset($this->args[1])) {
|
||||
foreach ($commands as $cmd) {
|
||||
$this->out("{$cmd}\n\n");
|
||||
}
|
||||
} elseif (isset($commands[strtolower($this->args[1])])) {
|
||||
$this->out($commands[strtolower($this->args[1])] . "\n\n");
|
||||
} else {
|
||||
$this->out("Command '" . $this->args[1] . "' not found");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a given class (located on given file) and get public methods and their
|
||||
* signatures.
|
||||
*
|
||||
* @param object $File File object
|
||||
* @param string $class Class name
|
||||
* @return array Methods and signatures indexed by method name
|
||||
* @access private
|
||||
*/
|
||||
function __parseClass($path) {
|
||||
$parsed = array();
|
||||
|
||||
$File = new File($path);
|
||||
if (!$File->exists()) {
|
||||
$this->err(sprintf(__("%s could not be found", true), $File->name));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$contents = $File->read();
|
||||
|
||||
if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.*\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
|
||||
foreach ($result[2] as $key => $method) {
|
||||
$method = str_replace('function ', '', trim($method));
|
||||
|
||||
if (strpos($method, '__') === false && $method[0] != '_') {
|
||||
$parsed[$method] = array(
|
||||
'comment' => str_replace(array('/*', '*/', '*'), '', trim($result[1][$key])),
|
||||
'method' => $method,
|
||||
'parameters' => trim($result[3][$key])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ksort($parsed);
|
||||
return $parsed;
|
||||
}
|
||||
}
|
230
php-practice/web-cake/html/cake/console/libs/bake.php
Normal file
230
php-practice/web-cake/html/cake/console/libs/bake.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* Command-line code generation utility to automate programmer chores.
|
||||
*
|
||||
* Bake is CakePHP's code generation script, which can help you kickstart
|
||||
* application development by writing fully functional skeleton controllers,
|
||||
* models, and views. Going further, Bake can also write Unit Tests for you.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Bake is a command-line code generation utility for automating programmer chores.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @link http://book.cakephp.org/view/1522/Code-Generation-with-Bake
|
||||
*/
|
||||
class BakeShell extends Shell {
|
||||
|
||||
/**
|
||||
* Contains tasks to load and instantiate
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin', 'Fixture', 'Test');
|
||||
|
||||
/**
|
||||
* Override loadTasks() to handle paths
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function loadTasks() {
|
||||
parent::loadTasks();
|
||||
$task = Inflector::classify($this->command);
|
||||
if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
|
||||
if (isset($this->params['connection'])) {
|
||||
$this->{$task}->connection = $this->params['connection'];
|
||||
}
|
||||
foreach($this->args as $i => $arg) {
|
||||
if (strpos($arg, '.')) {
|
||||
list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isset($this->params['plugin'])) {
|
||||
$this->{$task}->plugin = $this->params['plugin'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override main() to handle action
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function main() {
|
||||
if (!is_dir($this->DbConfig->path)) {
|
||||
if ($this->Project->execute()) {
|
||||
$this->DbConfig->path = $this->params['working'] . DS . 'config' . DS;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!config('database')) {
|
||||
$this->out(__("Your database configuration was not found. Take a moment to create one.", true));
|
||||
$this->args = null;
|
||||
return $this->DbConfig->execute();
|
||||
}
|
||||
$this->out('Interactive Bake Shell');
|
||||
$this->hr();
|
||||
$this->out('[D]atabase Configuration');
|
||||
$this->out('[M]odel');
|
||||
$this->out('[V]iew');
|
||||
$this->out('[C]ontroller');
|
||||
$this->out('[P]roject');
|
||||
$this->out('[F]ixture');
|
||||
$this->out('[T]est case');
|
||||
$this->out('[Q]uit');
|
||||
|
||||
$classToBake = strtoupper($this->in(__('What would you like to Bake?', true), array('D', 'M', 'V', 'C', 'P', 'F', 'T', 'Q')));
|
||||
switch ($classToBake) {
|
||||
case 'D':
|
||||
$this->DbConfig->execute();
|
||||
break;
|
||||
case 'M':
|
||||
$this->Model->execute();
|
||||
break;
|
||||
case 'V':
|
||||
$this->View->execute();
|
||||
break;
|
||||
case 'C':
|
||||
$this->Controller->execute();
|
||||
break;
|
||||
case 'P':
|
||||
$this->Project->execute();
|
||||
break;
|
||||
case 'F':
|
||||
$this->Fixture->execute();
|
||||
break;
|
||||
case 'T':
|
||||
$this->Test->execute();
|
||||
break;
|
||||
case 'Q':
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
$this->out(__('You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, F, T, or C.', true));
|
||||
}
|
||||
$this->hr();
|
||||
$this->main();
|
||||
}
|
||||
|
||||
/**
|
||||
* Quickly bake the MVC
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function all() {
|
||||
$this->hr();
|
||||
$this->out('Bake All');
|
||||
$this->hr();
|
||||
|
||||
if (!isset($this->params['connection']) && empty($this->connection)) {
|
||||
$this->connection = $this->DbConfig->getConfig();
|
||||
}
|
||||
|
||||
if (empty($this->args)) {
|
||||
$this->Model->interactive = true;
|
||||
$name = $this->Model->getName($this->connection);
|
||||
}
|
||||
|
||||
foreach (array('Model', 'Controller', 'View') as $task) {
|
||||
$this->{$task}->connection = $this->connection;
|
||||
$this->{$task}->interactive = false;
|
||||
}
|
||||
|
||||
if (!empty($this->args[0])) {
|
||||
$name = $this->args[0];
|
||||
}
|
||||
|
||||
$modelExists = false;
|
||||
$model = $this->_modelName($name);
|
||||
if (App::import('Model', $model)) {
|
||||
$object = new $model();
|
||||
$modelExists = true;
|
||||
} else {
|
||||
App::import('Model', 'Model', false);
|
||||
$object = new Model(array('name' => $name, 'ds' => $this->connection));
|
||||
}
|
||||
|
||||
$modelBaked = $this->Model->bake($object, false);
|
||||
|
||||
if ($modelBaked && $modelExists === false) {
|
||||
$this->out(sprintf(__('%s Model was baked.', true), $model));
|
||||
if ($this->_checkUnitTest()) {
|
||||
$this->Model->bakeFixture($model);
|
||||
$this->Model->bakeTest($model);
|
||||
}
|
||||
$modelExists = true;
|
||||
}
|
||||
|
||||
if ($modelExists === true) {
|
||||
$controller = $this->_controllerName($name);
|
||||
if ($this->Controller->bake($controller, $this->Controller->bakeActions($controller))) {
|
||||
$this->out(sprintf(__('%s Controller was baked.', true), $name));
|
||||
if ($this->_checkUnitTest()) {
|
||||
$this->Controller->bakeTest($controller);
|
||||
}
|
||||
}
|
||||
if (App::import('Controller', $controller)) {
|
||||
$this->View->args = array($controller);
|
||||
$this->View->execute();
|
||||
$this->out(sprintf(__('%s Views were baked.', true), $name));
|
||||
}
|
||||
$this->out(__('Bake All complete', true));
|
||||
array_shift($this->args);
|
||||
} else {
|
||||
$this->err(__('Bake All could not continue without a valid model', true));
|
||||
}
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays help contents
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->out('CakePHP Bake:');
|
||||
$this->hr();
|
||||
$this->out('The Bake script generates controllers, views and models for your application.');
|
||||
$this->out('If run with no command line arguments, Bake guides the user through the class');
|
||||
$this->out('creation process. You can customize the generation process by telling Bake');
|
||||
$this->out('where different parts of your application are using command line arguments.');
|
||||
$this->hr();
|
||||
$this->out("Usage: cake bake <command> <arg1> <arg2>...");
|
||||
$this->hr();
|
||||
$this->out('Params:');
|
||||
$this->out("\t-app <path> Absolute/Relative path to your app folder.\n");
|
||||
$this->out('Commands:');
|
||||
$this->out("\n\tbake help\n\t\tshows this help message.");
|
||||
$this->out("\n\tbake all <name>\n\t\tbakes complete MVC. optional <name> of a Model");
|
||||
$this->out("\n\tbake project <path>\n\t\tbakes a new app folder in the path supplied\n\t\tor in current directory if no path is specified");
|
||||
$this->out("\n\tbake plugin <name>\n\t\tbakes a new plugin folder in the path supplied\n\t\tor in current directory if no path is specified.");
|
||||
$this->out("\n\tbake db_config\n\t\tbakes a database.php file in config directory.");
|
||||
$this->out("\n\tbake model\n\t\tbakes a model. run 'bake model help' for more info");
|
||||
$this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info");
|
||||
$this->out("\n\tbake controller\n\t\tbakes a controller. run 'bake controller help' for more info");
|
||||
$this->out("\n\tbake fixture\n\t\tbakes fixtures. run 'bake fixture help' for more info.");
|
||||
$this->out("\n\tbake test\n\t\tbakes unit tests. run 'bake test help' for more info.");
|
||||
$this->out();
|
||||
|
||||
}
|
||||
}
|
361
php-practice/web-cake/html/cake/console/libs/console.php
Normal file
361
php-practice/web-cake/html/cake/console/libs/console.php
Normal file
@@ -0,0 +1,361 @@
|
||||
<?php
|
||||
/**
|
||||
* CakePHP Console Shell
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
*/
|
||||
class ConsoleShell extends Shell {
|
||||
|
||||
/**
|
||||
* Available binding types
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $associations = array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany');
|
||||
|
||||
/**
|
||||
* Chars that describe invalid commands
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $badCommandChars = array('$', ';');
|
||||
|
||||
/**
|
||||
* Available models
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $models = array();
|
||||
|
||||
/**
|
||||
* Override intialize of the Shell
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {
|
||||
require_once CAKE . 'dispatcher.php';
|
||||
$this->Dispatcher = new Dispatcher();
|
||||
$this->models = App::objects('model');
|
||||
App::import('Model', $this->models);
|
||||
|
||||
foreach ($this->models as $model) {
|
||||
$class = Inflector::camelize(str_replace('.php', '', $model));
|
||||
$this->models[$model] = $class;
|
||||
$this->{$class} =& new $class();
|
||||
}
|
||||
$this->out('Model classes:');
|
||||
$this->out('--------------');
|
||||
|
||||
foreach ($this->models as $model) {
|
||||
$this->out(" - {$model}");
|
||||
}
|
||||
$this->_loadRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the help message
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$out = 'Console help:';
|
||||
$out .= '-------------';
|
||||
$out .= 'The interactive console is a tool for testing parts of your app before you';
|
||||
$out .= 'write code.';
|
||||
$out .= "\n";
|
||||
$out .= 'Model testing:';
|
||||
$out .= 'To test model results, use the name of your model without a leading $';
|
||||
$out .= 'e.g. Foo->find("all")';
|
||||
$out .= "\n";
|
||||
$out .= 'To dynamically set associations, you can do the following:';
|
||||
$out .= "\tModelA bind <association> ModelB";
|
||||
$out .= "where the supported assocations are hasOne, hasMany, belongsTo, hasAndBelongsToMany";
|
||||
$out .= "\n";
|
||||
$out .= 'To dynamically remove associations, you can do the following:';
|
||||
$out .= "\t ModelA unbind <association> ModelB";
|
||||
$out .= "where the supported associations are the same as above";
|
||||
$out .= "\n";
|
||||
$out .= "To save a new field in a model, you can do the following:";
|
||||
$out .= "\tModelA->save(array('foo' => 'bar', 'baz' => 0))";
|
||||
$out .= "where you are passing a hash of data to be saved in the format";
|
||||
$out .= "of field => value pairs";
|
||||
$out .= "\n";
|
||||
$out .= "To get column information for a model, use the following:";
|
||||
$out .= "\tModelA columns";
|
||||
$out .= "which returns a list of columns and their type";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= 'Route testing:';
|
||||
$out .= "\n";
|
||||
$out .= 'To test URLs against your app\'s route configuration, type:';
|
||||
$out .= "\n";
|
||||
$out .= "\tRoute <url>";
|
||||
$out .= "\n";
|
||||
$out .= "where url is the path to your your action plus any query parameters,";
|
||||
$out .= "minus the application's base path. For example:";
|
||||
$out .= "\n";
|
||||
$out .= "\tRoute /posts/view/1";
|
||||
$out .= "\n";
|
||||
$out .= "will return something like the following:";
|
||||
$out .= "\n";
|
||||
$out .= "\tarray (";
|
||||
$out .= "\t [...]";
|
||||
$out .= "\t 'controller' => 'posts',";
|
||||
$out .= "\t 'action' => 'view',";
|
||||
$out .= "\t [...]";
|
||||
$out .= "\t)";
|
||||
$out .= "\n";
|
||||
$out .= 'Alternatively, you can use simple array syntax to test reverse';
|
||||
$out .= 'To reload your routes config (config/routes.php), do the following:';
|
||||
$out .= "\n";
|
||||
$out .= "\tRoutes reload";
|
||||
$out .= "\n";
|
||||
$out .= 'To show all connected routes, do the following:';
|
||||
$out .= "\tRoutes show";
|
||||
$this->out($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override main() to handle action
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function main($command = null) {
|
||||
while (true) {
|
||||
if (empty($command)) {
|
||||
$command = trim($this->in(''));
|
||||
}
|
||||
|
||||
switch ($command) {
|
||||
case 'help':
|
||||
$this->help();
|
||||
break;
|
||||
case 'quit':
|
||||
case 'exit':
|
||||
return true;
|
||||
break;
|
||||
case 'models':
|
||||
$this->out('Model classes:');
|
||||
$this->hr();
|
||||
foreach ($this->models as $model) {
|
||||
$this->out(" - {$model}");
|
||||
}
|
||||
break;
|
||||
case (preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp) == true):
|
||||
foreach ($tmp as $data) {
|
||||
$data = strip_tags($data);
|
||||
$data = str_replace($this->badCommandChars, "", $data);
|
||||
}
|
||||
|
||||
$modelA = $tmp[1];
|
||||
$association = $tmp[2];
|
||||
$modelB = $tmp[3];
|
||||
|
||||
if ($this->_isValidModel($modelA) && $this->_isValidModel($modelB) && in_array($association, $this->associations)) {
|
||||
$this->{$modelA}->bindModel(array($association => array($modelB => array('className' => $modelB))), false);
|
||||
$this->out("Created $association association between $modelA and $modelB");
|
||||
} else {
|
||||
$this->out("Please verify you are using valid models and association types");
|
||||
}
|
||||
break;
|
||||
case (preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp) == true):
|
||||
foreach ($tmp as $data) {
|
||||
$data = strip_tags($data);
|
||||
$data = str_replace($this->badCommandChars, "", $data);
|
||||
}
|
||||
|
||||
$modelA = $tmp[1];
|
||||
$association = $tmp[2];
|
||||
$modelB = $tmp[3];
|
||||
|
||||
// Verify that there is actually an association to unbind
|
||||
$currentAssociations = $this->{$modelA}->getAssociated();
|
||||
$validCurrentAssociation = false;
|
||||
|
||||
foreach ($currentAssociations as $model => $currentAssociation) {
|
||||
if ($model == $modelB && $association == $currentAssociation) {
|
||||
$validCurrentAssociation = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_isValidModel($modelA) && $this->_isValidModel($modelB) && in_array($association, $this->associations) && $validCurrentAssociation) {
|
||||
$this->{$modelA}->unbindModel(array($association => array($modelB)));
|
||||
$this->out("Removed $association association between $modelA and $modelB");
|
||||
} else {
|
||||
$this->out("Please verify you are using valid models, valid current association, and valid association types");
|
||||
}
|
||||
break;
|
||||
case (strpos($command, "->find") > 0):
|
||||
// Remove any bad info
|
||||
$command = strip_tags($command);
|
||||
$command = str_replace($this->badCommandChars, "", $command);
|
||||
|
||||
// Do we have a valid model?
|
||||
list($modelToCheck, $tmp) = explode('->', $command);
|
||||
|
||||
if ($this->_isValidModel($modelToCheck)) {
|
||||
$findCommand = "\$data = \$this->$command;";
|
||||
@eval($findCommand);
|
||||
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $idx => $results) {
|
||||
if (is_numeric($idx)) { // findAll() output
|
||||
foreach ($results as $modelName => $result) {
|
||||
$this->out("$modelName");
|
||||
|
||||
foreach ($result as $field => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $field2 => $value2) {
|
||||
$this->out("\t$field2: $value2");
|
||||
}
|
||||
|
||||
$this->out();
|
||||
} else {
|
||||
$this->out("\t$field: $value");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // find() output
|
||||
$this->out($idx);
|
||||
|
||||
foreach ($results as $field => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $field2 => $value2) {
|
||||
$this->out("\t$field2: $value2");
|
||||
}
|
||||
|
||||
$this->out();
|
||||
} else {
|
||||
$this->out("\t$field: $value");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->out("\nNo result set found");
|
||||
}
|
||||
} else {
|
||||
$this->out("$modelToCheck is not a valid model");
|
||||
}
|
||||
|
||||
break;
|
||||
case (strpos($command, '->save') > 0):
|
||||
// Validate the model we're trying to save here
|
||||
$command = strip_tags($command);
|
||||
$command = str_replace($this->badCommandChars, "", $command);
|
||||
list($modelToSave, $tmp) = explode("->", $command);
|
||||
|
||||
if ($this->_isValidModel($modelToSave)) {
|
||||
// Extract the array of data we are trying to build
|
||||
list($foo, $data) = explode("->save", $command);
|
||||
$data = preg_replace('/^\(*(array)?\(*(.+?)\)*$/i', '\\2', $data);
|
||||
$saveCommand = "\$this->{$modelToSave}->save(array('{$modelToSave}' => array({$data})));";
|
||||
@eval($saveCommand);
|
||||
$this->out('Saved record for ' . $modelToSave);
|
||||
}
|
||||
break;
|
||||
case (preg_match("/^(\w+) columns/", $command, $tmp) == true):
|
||||
$modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1]));
|
||||
|
||||
if ($this->_isValidModel($modelToCheck)) {
|
||||
// Get the column info for this model
|
||||
$fieldsCommand = "\$data = \$this->{$modelToCheck}->getColumnTypes();";
|
||||
@eval($fieldsCommand);
|
||||
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $field => $type) {
|
||||
$this->out("\t{$field}: {$type}");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->out("Please verify that you selected a valid model");
|
||||
}
|
||||
break;
|
||||
case (preg_match("/^routes\s+reload/i", $command, $tmp) == true):
|
||||
$router =& Router::getInstance();
|
||||
if (!$this->_loadRoutes()) {
|
||||
$this->out("There was an error loading the routes config. Please check that the file");
|
||||
$this->out("exists and is free of parse errors.");
|
||||
break;
|
||||
}
|
||||
$this->out("Routes configuration reloaded, " . count($router->routes) . " routes connected");
|
||||
break;
|
||||
case (preg_match("/^routes\s+show/i", $command, $tmp) == true):
|
||||
$router =& Router::getInstance();
|
||||
$this->out(implode("\n", Set::extract($router->routes, '{n}.0')));
|
||||
break;
|
||||
case (preg_match("/^route\s+(\(.*\))$/i", $command, $tmp) == true):
|
||||
if ($url = eval('return array' . $tmp[1] . ';')) {
|
||||
$this->out(Router::url($url));
|
||||
}
|
||||
break;
|
||||
case (preg_match("/^route\s+(.*)/i", $command, $tmp) == true):
|
||||
$this->out(var_export(Router::parse($tmp[1]), true));
|
||||
break;
|
||||
default:
|
||||
$this->out("Invalid command\n");
|
||||
break;
|
||||
}
|
||||
$command = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the specified model is included in the list of available models
|
||||
*
|
||||
* @param string $modelToCheck
|
||||
* @return boolean true if is an available model, false otherwise
|
||||
* @access protected
|
||||
*/
|
||||
function _isValidModel($modelToCheck) {
|
||||
return in_array($modelToCheck, $this->models);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the routes configuration from config/routes.php, and compiles
|
||||
* all routes found
|
||||
*
|
||||
* @return boolean True if config reload was a success, otherwise false
|
||||
* @access protected
|
||||
*/
|
||||
function _loadRoutes() {
|
||||
$router =& Router::getInstance();
|
||||
|
||||
$router->reload();
|
||||
extract($router->getNamedExpressions());
|
||||
|
||||
if (!@include(CONFIGS . 'routes.php')) {
|
||||
return false;
|
||||
}
|
||||
$router->parse('/');
|
||||
|
||||
foreach (array_keys($router->getNamedExpressions()) as $var) {
|
||||
unset(${$var});
|
||||
}
|
||||
for ($i = 0, $len = count($router->routes); $i < $len; $i++) {
|
||||
$router->routes[$i]->compile();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
128
php-practice/web-cake/html/cake/console/libs/i18n.php
Normal file
128
php-practice/web-cake/html/cake/console/libs/i18n.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Internationalization Management Shell
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5669
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Shell for I18N management.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
*/
|
||||
class I18nShell extends Shell {
|
||||
|
||||
/**
|
||||
* Contains database source to use
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $dataSource = 'default';
|
||||
|
||||
/**
|
||||
* Contains tasks to load and instantiate
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('DbConfig', 'Extract');
|
||||
|
||||
/**
|
||||
* Override startup of the Shell
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function startup() {
|
||||
$this->_welcome();
|
||||
if (isset($this->params['datasource'])) {
|
||||
$this->dataSource = $this->params['datasource'];
|
||||
}
|
||||
|
||||
if ($this->command && !in_array($this->command, array('help'))) {
|
||||
if (!config('database')) {
|
||||
$this->out(__('Your database configuration was not found. Take a moment to create one.', true), true);
|
||||
return $this->DbConfig->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override main() for help message hook
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function main() {
|
||||
$this->out(__('I18n Shell', true));
|
||||
$this->hr();
|
||||
$this->out(__('[E]xtract POT file from sources', true));
|
||||
$this->out(__('[I]nitialize i18n database table', true));
|
||||
$this->out(__('[H]elp', true));
|
||||
$this->out(__('[Q]uit', true));
|
||||
|
||||
$choice = strtolower($this->in(__('What would you like to do?', true), array('E', 'I', 'H', 'Q')));
|
||||
switch ($choice) {
|
||||
case 'e':
|
||||
$this->Extract->execute();
|
||||
break;
|
||||
case 'i':
|
||||
$this->initdb();
|
||||
break;
|
||||
case 'h':
|
||||
$this->help();
|
||||
break;
|
||||
case 'q':
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
$this->out(__('You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.', true));
|
||||
}
|
||||
$this->hr();
|
||||
$this->main();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize I18N database.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initdb() {
|
||||
$this->Dispatch->args = array('schema', 'create', 'i18n');
|
||||
$this->Dispatch->dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help screen.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->hr();
|
||||
$this->out(__('I18n Shell:', true));
|
||||
$this->hr();
|
||||
$this->out(__('I18n Shell initializes i18n database table for your application', true));
|
||||
$this->out(__('and generates .pot file(s) with translations.', true));
|
||||
$this->hr();
|
||||
$this->out(__('usage:', true));
|
||||
$this->out(' cake i18n help');
|
||||
$this->out(' cake i18n initdb [-datasource custom]');
|
||||
$this->out();
|
||||
$this->hr();
|
||||
|
||||
$this->Extract->help();
|
||||
}
|
||||
}
|
506
php-practice/web-cake/html/cake/console/libs/schema.php
Normal file
506
php-practice/web-cake/html/cake/console/libs/schema.php
Normal file
@@ -0,0 +1,506 @@
|
||||
<?php
|
||||
/**
|
||||
* Command-line database management utility to automate programmer chores.
|
||||
*
|
||||
* Schema is CakePHP's database management utility. This helps you maintain versions of
|
||||
* of your database.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5550
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'File', false);
|
||||
App::import('Model', 'CakeSchema', false);
|
||||
|
||||
/**
|
||||
* Schema is a command-line database management utility for automating programmer chores.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @link http://book.cakephp.org/view/1523/Schema-management-and-migrations
|
||||
*/
|
||||
class SchemaShell extends Shell {
|
||||
|
||||
/**
|
||||
* is this a dry run?
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $__dry = null;
|
||||
|
||||
/**
|
||||
* Override initialize
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {
|
||||
$this->_welcome();
|
||||
$this->out('Cake Schema Shell');
|
||||
$this->hr();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override startup
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function startup() {
|
||||
$name = $file = $path = $connection = $plugin = null;
|
||||
if (!empty($this->params['name'])) {
|
||||
$name = $this->params['name'];
|
||||
} elseif (!empty($this->args[0])) {
|
||||
$name = $this->params['name'] = $this->args[0];
|
||||
}
|
||||
|
||||
if (strpos($name, '.')) {
|
||||
list($this->params['plugin'], $splitName) = pluginSplit($name);
|
||||
$name = $this->params['name'] = $splitName;
|
||||
}
|
||||
|
||||
if ($name) {
|
||||
$this->params['file'] = Inflector::underscore($name);
|
||||
}
|
||||
|
||||
if (empty($this->params['file'])) {
|
||||
$this->params['file'] = 'schema.php';
|
||||
}
|
||||
if (strpos($this->params['file'], '.php') === false) {
|
||||
$this->params['file'] .= '.php';
|
||||
}
|
||||
$file = $this->params['file'];
|
||||
|
||||
if (!empty($this->params['path'])) {
|
||||
$path = $this->params['path'];
|
||||
}
|
||||
|
||||
if (!empty($this->params['connection'])) {
|
||||
$connection = $this->params['connection'];
|
||||
}
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$plugin = $this->params['plugin'];
|
||||
if (empty($name)) {
|
||||
$name = $plugin;
|
||||
}
|
||||
}
|
||||
$this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection', 'plugin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Override main
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function main() {
|
||||
$this->help();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and output contents of schema object
|
||||
* path to read as second arg
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function view() {
|
||||
$File = new File($this->Schema->path . DS . $this->params['file']);
|
||||
if ($File->exists()) {
|
||||
$this->out($File->read());
|
||||
$this->_stop();
|
||||
} else {
|
||||
$file = $this->Schema->path . DS . $this->params['file'];
|
||||
$this->err(sprintf(__('Schema file (%s) could not be found.', true), $file));
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read database and Write schema object
|
||||
* accepts a connection as first arg or path to save as second arg
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function generate() {
|
||||
$this->out(__('Generating Schema...', true));
|
||||
$options = array();
|
||||
if (isset($this->params['f'])) {
|
||||
$options = array('models' => false);
|
||||
}
|
||||
|
||||
$snapshot = false;
|
||||
if (isset($this->args[0]) && $this->args[0] === 'snapshot') {
|
||||
$snapshot = true;
|
||||
}
|
||||
|
||||
if (!$snapshot && file_exists($this->Schema->path . DS . $this->params['file'])) {
|
||||
$snapshot = true;
|
||||
$result = strtolower($this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's'));
|
||||
if ($result === 'q') {
|
||||
return $this->_stop();
|
||||
}
|
||||
if ($result === 'o') {
|
||||
$snapshot = false;
|
||||
}
|
||||
}
|
||||
|
||||
$content = $this->Schema->read($options);
|
||||
$content['file'] = $this->params['file'];
|
||||
|
||||
if ($snapshot === true) {
|
||||
$Folder =& new Folder($this->Schema->path);
|
||||
$result = $Folder->read();
|
||||
|
||||
$numToUse = false;
|
||||
if (isset($this->params['s'])) {
|
||||
$numToUse = $this->params['s'];
|
||||
}
|
||||
|
||||
$count = 1;
|
||||
if (!empty($result[1])) {
|
||||
foreach ($result[1] as $file) {
|
||||
if (preg_match('/schema(?:[_\d]*)?\.php$/', $file)) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($numToUse !== false) {
|
||||
if ($numToUse > $count) {
|
||||
$count = $numToUse;
|
||||
}
|
||||
}
|
||||
|
||||
$fileName = rtrim($this->params['file'], '.php');
|
||||
$content['file'] = $fileName . '_' . $count . '.php';
|
||||
}
|
||||
|
||||
if ($this->Schema->write($content)) {
|
||||
$this->out(sprintf(__('Schema file: %s generated', true), $content['file']));
|
||||
$this->_stop();
|
||||
} else {
|
||||
$this->err(__('Schema file: %s generated', true));
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump Schema object to sql file
|
||||
* Use the `write` param to enable and control SQL file output location.
|
||||
* Simply using -write will write the sql file to the same dir as the schema file.
|
||||
* If -write contains a full path name the file will be saved there. If -write only
|
||||
* contains no DS, that will be used as the file name, in the same dir as the schema file.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function dump() {
|
||||
$write = false;
|
||||
$Schema = $this->Schema->load();
|
||||
if (!$Schema) {
|
||||
$this->err(__('Schema could not be loaded', true));
|
||||
$this->_stop();
|
||||
}
|
||||
if (isset($this->params['write'])) {
|
||||
if ($this->params['write'] == 1) {
|
||||
$write = Inflector::underscore($this->Schema->name);
|
||||
} else {
|
||||
$write = $this->params['write'];
|
||||
}
|
||||
}
|
||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||
$contents = "#" . $Schema->name . " sql generated on: " . date('Y-m-d H:i:s') . " : " . time() . "\n\n";
|
||||
$contents .= $db->dropSchema($Schema) . "\n\n". $db->createSchema($Schema);
|
||||
|
||||
if ($write) {
|
||||
if (strpos($write, '.sql') === false) {
|
||||
$write .= '.sql';
|
||||
}
|
||||
if (strpos($write, DS) !== false) {
|
||||
$File =& new File($write, true);
|
||||
} else {
|
||||
$File =& new File($this->Schema->path . DS . $write, true);
|
||||
}
|
||||
|
||||
if ($File->write($contents)) {
|
||||
$this->out(sprintf(__('SQL dump file created in %s', true), $File->pwd()));
|
||||
$this->_stop();
|
||||
} else {
|
||||
$this->err(__('SQL dump could not be created', true));
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
$this->out($contents);
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run database create commands. Alias for run create.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function create() {
|
||||
list($Schema, $table) = $this->_loadSchema();
|
||||
$this->__create($Schema, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run database create commands. Alias for run create.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function update() {
|
||||
list($Schema, $table) = $this->_loadSchema();
|
||||
$this->__update($Schema, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the Schema objects for database operations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function _loadSchema() {
|
||||
$name = $plugin = null;
|
||||
if (isset($this->params['name'])) {
|
||||
$name = $this->params['name'];
|
||||
}
|
||||
if (isset($this->params['plugin'])) {
|
||||
$plugin = $this->params['plugin'];
|
||||
}
|
||||
|
||||
if (isset($this->params['dry'])) {
|
||||
$this->__dry = true;
|
||||
$this->out(__('Performing a dry run.', true));
|
||||
}
|
||||
|
||||
$options = array('name' => $name, 'plugin' => $plugin);
|
||||
if (isset($this->params['s'])) {
|
||||
$fileName = rtrim($this->Schema->file, '.php');
|
||||
$options['file'] = $fileName . '_' . $this->params['s'] . '.php';
|
||||
}
|
||||
|
||||
$Schema =& $this->Schema->load($options);
|
||||
|
||||
if (!$Schema) {
|
||||
$this->err(sprintf(__('%s could not be loaded', true), $this->Schema->path . DS . $this->Schema->file));
|
||||
$this->_stop();
|
||||
}
|
||||
$table = null;
|
||||
if (isset($this->args[1])) {
|
||||
$table = $this->args[1];
|
||||
}
|
||||
return array(&$Schema, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create database from Schema object
|
||||
* Should be called via the run method
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __create(&$Schema, $table = null) {
|
||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||
|
||||
$drop = $create = array();
|
||||
|
||||
if (!$table) {
|
||||
foreach ($Schema->tables as $table => $fields) {
|
||||
$drop[$table] = $db->dropSchema($Schema, $table);
|
||||
$create[$table] = $db->createSchema($Schema, $table);
|
||||
}
|
||||
} elseif (isset($Schema->tables[$table])) {
|
||||
$drop[$table] = $db->dropSchema($Schema, $table);
|
||||
$create[$table] = $db->createSchema($Schema, $table);
|
||||
}
|
||||
if (empty($drop) || empty($create)) {
|
||||
$this->out(__('Schema is up to date.', true));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$this->out("\n" . __('The following table(s) will be dropped.', true));
|
||||
$this->out(array_keys($drop));
|
||||
|
||||
if ('y' == $this->in(__('Are you sure you want to drop the table(s)?', true), array('y', 'n'), 'n')) {
|
||||
$this->out(__('Dropping table(s).', true));
|
||||
$this->__run($drop, 'drop', $Schema);
|
||||
}
|
||||
|
||||
$this->out("\n" . __('The following table(s) will be created.', true));
|
||||
$this->out(array_keys($create));
|
||||
|
||||
if ('y' == $this->in(__('Are you sure you want to create the table(s)?', true), array('y', 'n'), 'y')) {
|
||||
$this->out(__('Creating table(s).', true));
|
||||
$this->__run($create, 'create', $Schema);
|
||||
}
|
||||
$this->out(__('End create.', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update database with Schema object
|
||||
* Should be called via the run method
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __update(&$Schema, $table = null) {
|
||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||
|
||||
$this->out(__('Comparing Database to Schema...', true));
|
||||
$options = array();
|
||||
if (isset($this->params['f'])) {
|
||||
$options['models'] = false;
|
||||
}
|
||||
$Old = $this->Schema->read($options);
|
||||
$compare = $this->Schema->compare($Old, $Schema);
|
||||
|
||||
$contents = array();
|
||||
|
||||
if (empty($table)) {
|
||||
foreach ($compare as $table => $changes) {
|
||||
$contents[$table] = $db->alterSchema(array($table => $changes), $table);
|
||||
}
|
||||
} elseif (isset($compare[$table])) {
|
||||
$contents[$table] = $db->alterSchema(array($table => $compare[$table]), $table);
|
||||
}
|
||||
|
||||
if (empty($contents)) {
|
||||
$this->out(__('Schema is up to date.', true));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$this->out("\n" . __('The following statements will run.', true));
|
||||
$this->out(array_map('trim', $contents));
|
||||
if ('y' == $this->in(__('Are you sure you want to alter the tables?', true), array('y', 'n'), 'n')) {
|
||||
$this->out();
|
||||
$this->out(__('Updating Database...', true));
|
||||
$this->__run($contents, 'update', $Schema);
|
||||
}
|
||||
|
||||
$this->out(__('End update.', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs sql from __create() or __update()
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __run($contents, $event, &$Schema) {
|
||||
if (empty($contents)) {
|
||||
$this->err(__('Sql could not be run', true));
|
||||
return;
|
||||
}
|
||||
Configure::write('debug', 2);
|
||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||
|
||||
foreach ($contents as $table => $sql) {
|
||||
if (empty($sql)) {
|
||||
$this->out(sprintf(__('%s is up to date.', true), $table));
|
||||
} else {
|
||||
if ($this->__dry === true) {
|
||||
$this->out(sprintf(__('Dry run for %s :', true), $table));
|
||||
$this->out($sql);
|
||||
} else {
|
||||
if (!$Schema->before(array($event => $table))) {
|
||||
return false;
|
||||
}
|
||||
$error = null;
|
||||
if (!$db->execute($sql)) {
|
||||
$error = $table . ': ' . $db->lastError();
|
||||
}
|
||||
|
||||
$Schema->after(array($event => $table, 'errors' => $error));
|
||||
|
||||
if (!empty($error)) {
|
||||
$this->out($error);
|
||||
} else {
|
||||
$this->out(sprintf(__('%s updated.', true), $table));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays help contents
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$help = <<<TEXT
|
||||
The Schema Shell generates a schema object from
|
||||
the database and updates the database from the schema.
|
||||
---------------------------------------------------------------
|
||||
Usage: cake schema <command> <arg1> <arg2>...
|
||||
---------------------------------------------------------------
|
||||
Params:
|
||||
-connection <config>
|
||||
set db config <config>. uses 'default' if none is specified
|
||||
|
||||
-path <dir>
|
||||
path <dir> to read and write schema.php.
|
||||
default path: {$this->Schema->path}
|
||||
|
||||
-name <name>
|
||||
Classname to use. If <name> is Plugin.className, it will
|
||||
set the plugin and name params.
|
||||
|
||||
-file <name>
|
||||
file <name> to read and write.
|
||||
default file: {$this->Schema->file}
|
||||
|
||||
-s <number>
|
||||
snapshot <number> to use for run.
|
||||
|
||||
-dry
|
||||
Perform a dry run on create + update commands.
|
||||
Queries will be output to window instead of executed.
|
||||
|
||||
-f
|
||||
force 'generate' to create a new schema.
|
||||
|
||||
-plugin
|
||||
Indicate the plugin to use.
|
||||
|
||||
Commands:
|
||||
|
||||
schema help
|
||||
shows this help message.
|
||||
|
||||
schema view <name>
|
||||
read and output contents of schema file.
|
||||
|
||||
schema generate
|
||||
reads from 'connection' writes to 'path'
|
||||
To force generation of all tables into the schema, use the -f param.
|
||||
Use 'schema generate snapshot <number>' to generate snapshots
|
||||
which you can use with the -s parameter in the other operations.
|
||||
|
||||
schema dump <name>
|
||||
Dump database sql based on schema file to stdout.
|
||||
If you use the `-write` param is used a .sql will be generated.
|
||||
If `-write` is a filename, then that file name will be generate.
|
||||
If `-write` is a full path, the schema will be written there.
|
||||
|
||||
schema create <name> <table>
|
||||
Drop and create tables based on schema file
|
||||
optional <table> argument can be used to create only a single
|
||||
table in the schema. Pass the -s param with a number to use a snapshot.
|
||||
Use the `-dry` param to preview the changes.
|
||||
|
||||
schema update <name> <table>
|
||||
Alter the tables based on schema file. Optional <table>
|
||||
parameter will only update one table.
|
||||
To use a snapshot pass the `-s` param with the snapshot number.
|
||||
To preview the changes that will be done use `-dry`.
|
||||
TEXT;
|
||||
$this->out($help);
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
647
php-practice/web-cake/html/cake/console/libs/shell.php
Normal file
647
php-practice/web-cake/html/cake/console/libs/shell.php
Normal file
@@ -0,0 +1,647 @@
|
||||
<?php
|
||||
/**
|
||||
* Base class for Shells
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for command-line utilities for automating programmer chores.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
*/
|
||||
class Shell extends Object {
|
||||
|
||||
/**
|
||||
* An instance of the ShellDispatcher object that loaded this script
|
||||
*
|
||||
* @var ShellDispatcher
|
||||
* @access public
|
||||
*/
|
||||
var $Dispatch = null;
|
||||
|
||||
/**
|
||||
* If true, the script will ask for permission to perform actions.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $interactive = true;
|
||||
|
||||
/**
|
||||
* Holds the DATABASE_CONFIG object for the app. Null if database.php could not be found,
|
||||
* or the app does not exist.
|
||||
*
|
||||
* @var DATABASE_CONFIG
|
||||
* @access public
|
||||
*/
|
||||
var $DbConfig = null;
|
||||
|
||||
/**
|
||||
* Contains command switches parsed from the command line.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $params = array();
|
||||
|
||||
/**
|
||||
* Contains arguments parsed from the command line.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $args = array();
|
||||
|
||||
/**
|
||||
* The file name of the shell that was invoked.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $shell = null;
|
||||
|
||||
/**
|
||||
* The class name of the shell that was invoked.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $className = null;
|
||||
|
||||
/**
|
||||
* The command called if public methods are available.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $command = null;
|
||||
|
||||
/**
|
||||
* The name of the shell in camelized.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = null;
|
||||
|
||||
/**
|
||||
* An alias for the shell
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $alias = null;
|
||||
|
||||
/**
|
||||
* Contains tasks to load and instantiate
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array();
|
||||
|
||||
/**
|
||||
* Contains the loaded tasks
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $taskNames = array();
|
||||
|
||||
/**
|
||||
* Contains models to load and instantiate
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array();
|
||||
|
||||
/**
|
||||
* Constructs this Shell instance.
|
||||
*
|
||||
*/
|
||||
function __construct(&$dispatch) {
|
||||
$vars = array('params', 'args', 'shell', 'shellCommand' => 'command');
|
||||
|
||||
foreach ($vars as $key => $var) {
|
||||
if (is_string($key)) {
|
||||
$this->{$var} =& $dispatch->{$key};
|
||||
} else {
|
||||
$this->{$var} =& $dispatch->{$var};
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->name == null) {
|
||||
$this->name = get_class($this);
|
||||
}
|
||||
|
||||
if ($this->alias == null) {
|
||||
$this->alias = $this->name;
|
||||
}
|
||||
|
||||
ClassRegistry::addObject($this->name, $this);
|
||||
ClassRegistry::map($this->name, $this->alias);
|
||||
|
||||
if (!PHP5 && isset($this->args[0])) {
|
||||
if (strpos($this->name, strtolower(Inflector::camelize($this->args[0]))) !== false) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
if (strtolower($this->command) == strtolower(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
}
|
||||
|
||||
$this->Dispatch =& $dispatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Shell
|
||||
* acts as constructor for subclasses
|
||||
* allows configuration of tasks prior to shell execution
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {
|
||||
$this->_loadModels();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts up the Shell
|
||||
* allows for checking and configuring prior to command or main execution
|
||||
* can be overriden in subclasses
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function startup() {
|
||||
$this->_welcome();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a header for the shell
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function _welcome() {
|
||||
$this->Dispatch->clear();
|
||||
$this->out();
|
||||
$this->out('Welcome to CakePHP v' . Configure::version() . ' Console');
|
||||
$this->hr();
|
||||
$this->out('App : '. $this->params['app']);
|
||||
$this->out('Path: '. $this->params['working']);
|
||||
$this->hr();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads database file and constructs DATABASE_CONFIG class
|
||||
* makes $this->DbConfig available to subclasses
|
||||
*
|
||||
* @return bool
|
||||
* @access protected
|
||||
*/
|
||||
function _loadDbConfig() {
|
||||
if (config('database') && class_exists('DATABASE_CONFIG')) {
|
||||
$this->DbConfig =& new DATABASE_CONFIG();
|
||||
return true;
|
||||
}
|
||||
$this->err('Database config could not be loaded.');
|
||||
$this->out('Run `bake` to create the database configuration.');
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* if var $uses = true
|
||||
* Loads AppModel file and constructs AppModel class
|
||||
* makes $this->AppModel available to subclasses
|
||||
* if var $uses is an array of models will load those models
|
||||
*
|
||||
* @return bool
|
||||
* @access protected
|
||||
*/
|
||||
function _loadModels() {
|
||||
if ($this->uses === null || $this->uses === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->uses === true && App::import('Model', 'AppModel')) {
|
||||
$this->AppModel =& new AppModel(false, false, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->uses !== true && !empty($this->uses)) {
|
||||
$uses = is_array($this->uses) ? $this->uses : array($this->uses);
|
||||
|
||||
$modelClassName = $uses[0];
|
||||
if (strpos($uses[0], '.') !== false) {
|
||||
list($plugin, $modelClassName) = explode('.', $uses[0]);
|
||||
}
|
||||
$this->modelClass = $modelClassName;
|
||||
|
||||
foreach ($uses as $modelClass) {
|
||||
list($plugin, $modelClass) = pluginSplit($modelClass, true);
|
||||
if (PHP5) {
|
||||
$this->{$modelClass} = ClassRegistry::init($plugin . $modelClass);
|
||||
} else {
|
||||
$this->{$modelClass} =& ClassRegistry::init($plugin . $modelClass);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads tasks defined in var $tasks
|
||||
*
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function loadTasks() {
|
||||
if ($this->tasks === null || $this->tasks === false || $this->tasks === true || empty($this->tasks)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$tasks = $this->tasks;
|
||||
if (!is_array($tasks)) {
|
||||
$tasks = array($tasks);
|
||||
}
|
||||
|
||||
foreach ($tasks as $taskName) {
|
||||
$task = Inflector::underscore($taskName);
|
||||
$taskClass = Inflector::camelize($taskName . 'Task');
|
||||
|
||||
if (!class_exists($taskClass)) {
|
||||
foreach ($this->Dispatch->shellPaths as $path) {
|
||||
$taskPath = $path . 'tasks' . DS . $task . '.php';
|
||||
if (file_exists($taskPath)) {
|
||||
require_once $taskPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$taskClassCheck = $taskClass;
|
||||
if (!PHP5) {
|
||||
$taskClassCheck = strtolower($taskClass);
|
||||
}
|
||||
if (ClassRegistry::isKeySet($taskClassCheck)) {
|
||||
$this->taskNames[] = $taskName;
|
||||
if (!PHP5) {
|
||||
$this->{$taskName} =& ClassRegistry::getObject($taskClassCheck);
|
||||
} else {
|
||||
$this->{$taskName} = ClassRegistry::getObject($taskClassCheck);
|
||||
}
|
||||
} else {
|
||||
$this->taskNames[] = $taskName;
|
||||
if (!PHP5) {
|
||||
$this->{$taskName} =& new $taskClass($this->Dispatch);
|
||||
} else {
|
||||
$this->{$taskName} = new $taskClass($this->Dispatch);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->{$taskName})) {
|
||||
$this->err("Task `{$taskName}` could not be loaded");
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompts the user for input, and returns it.
|
||||
*
|
||||
* @param string $prompt Prompt text.
|
||||
* @param mixed $options Array or string of options.
|
||||
* @param string $default Default input value.
|
||||
* @return Either the default value, or the user-provided input.
|
||||
* @access public
|
||||
*/
|
||||
function in($prompt, $options = null, $default = null) {
|
||||
if (!$this->interactive) {
|
||||
return $default;
|
||||
}
|
||||
$in = $this->Dispatch->getInput($prompt, $options, $default);
|
||||
|
||||
if ($options && is_string($options)) {
|
||||
if (strpos($options, ',')) {
|
||||
$options = explode(',', $options);
|
||||
} elseif (strpos($options, '/')) {
|
||||
$options = explode('/', $options);
|
||||
} else {
|
||||
$options = array($options);
|
||||
}
|
||||
}
|
||||
if (is_array($options)) {
|
||||
while ($in == '' || ($in && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
|
||||
$in = $this->Dispatch->getInput($prompt, $options, $default);
|
||||
}
|
||||
}
|
||||
if ($in) {
|
||||
return $in;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a single or multiple messages to stdout. If no parameters
|
||||
* are passed outputs just a newline.
|
||||
*
|
||||
* @param mixed $message A string or a an array of strings to output
|
||||
* @param integer $newlines Number of newlines to append
|
||||
* @return integer Returns the number of bytes returned from writing to stdout.
|
||||
* @access public
|
||||
*/
|
||||
function out($message = null, $newlines = 1) {
|
||||
if (is_array($message)) {
|
||||
$message = implode($this->nl(), $message);
|
||||
}
|
||||
return $this->Dispatch->stdout($message . $this->nl($newlines), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a single or multiple error messages to stderr. If no parameters
|
||||
* are passed outputs just a newline.
|
||||
*
|
||||
* @param mixed $message A string or a an array of strings to output
|
||||
* @param integer $newlines Number of newlines to append
|
||||
* @access public
|
||||
*/
|
||||
function err($message = null, $newlines = 1) {
|
||||
if (is_array($message)) {
|
||||
$message = implode($this->nl(), $message);
|
||||
}
|
||||
$this->Dispatch->stderr($message . $this->nl($newlines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single or multiple linefeeds sequences.
|
||||
*
|
||||
* @param integer $multiplier Number of times the linefeed sequence should be repeated
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function nl($multiplier = 1) {
|
||||
return str_repeat("\n", $multiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a series of minus characters to the standard output, acts as a visual separator.
|
||||
*
|
||||
* @param integer $newlines Number of newlines to pre- and append
|
||||
* @access public
|
||||
*/
|
||||
function hr($newlines = 0) {
|
||||
$this->out(null, $newlines);
|
||||
$this->out('---------------------------------------------------------------');
|
||||
$this->out(null, $newlines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a formatted error message
|
||||
* and exits the application with status code 1
|
||||
*
|
||||
* @param string $title Title of the error
|
||||
* @param string $message An optional error message
|
||||
* @access public
|
||||
*/
|
||||
function error($title, $message = null) {
|
||||
$this->err(sprintf(__('Error: %s', true), $title));
|
||||
|
||||
if (!empty($message)) {
|
||||
$this->err($message);
|
||||
}
|
||||
$this->_stop(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will check the number args matches otherwise throw an error
|
||||
*
|
||||
* @param integer $expectedNum Expected number of paramters
|
||||
* @param string $command Command
|
||||
* @access protected
|
||||
*/
|
||||
function _checkArgs($expectedNum, $command = null) {
|
||||
if (!$command) {
|
||||
$command = $this->command;
|
||||
}
|
||||
if (count($this->args) < $expectedNum) {
|
||||
$message[] = "Got: " . count($this->args);
|
||||
$message[] = "Expected: {$expectedNum}";
|
||||
$message[] = "Please type `cake {$this->shell} help` for help";
|
||||
$message[] = "on usage of the {$this->name} {$command}.";
|
||||
$this->error('Wrong number of parameters', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file at given path
|
||||
*
|
||||
* @param string $path Where to put the file.
|
||||
* @param string $contents Content to put in the file.
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
function createFile($path, $contents) {
|
||||
$path = str_replace(DS . DS, DS, $path);
|
||||
|
||||
$this->out();
|
||||
$this->out(sprintf(__("Creating file %s", true), $path));
|
||||
|
||||
if (is_file($path) && $this->interactive === true) {
|
||||
$prompt = sprintf(__('File `%s` exists, overwrite?', true), $path);
|
||||
$key = $this->in($prompt, array('y', 'n', 'q'), 'n');
|
||||
|
||||
if (strtolower($key) == 'q') {
|
||||
$this->out(__('Quitting.', true), 2);
|
||||
$this->_stop();
|
||||
} elseif (strtolower($key) != 'y') {
|
||||
$this->out(sprintf(__('Skip `%s`', true), $path), 2);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!class_exists('File')) {
|
||||
require LIBS . 'file.php';
|
||||
}
|
||||
|
||||
if ($File = new File($path, true)) {
|
||||
$data = $File->prepare($contents);
|
||||
$File->write($data);
|
||||
$this->out(sprintf(__('Wrote `%s`', true), $path));
|
||||
return true;
|
||||
} else {
|
||||
$this->err(sprintf(__('Could not write to `%s`.', true), $path), 2);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs usage text on the standard output. Implement it in subclasses.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
if ($this->command != null) {
|
||||
$this->err("Unknown {$this->name} command `{$this->command}`.");
|
||||
$this->err("For usage, try `cake {$this->shell} help`.", 2);
|
||||
} else {
|
||||
$this->Dispatch->help();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to create a Unit Test
|
||||
*
|
||||
* @return boolean Success
|
||||
* @access protected
|
||||
*/
|
||||
function _checkUnitTest() {
|
||||
if (App::import('vendor', 'simpletest' . DS . 'simpletest')) {
|
||||
return true;
|
||||
}
|
||||
$prompt = 'SimpleTest is not installed. Do you want to bake unit test files anyway?';
|
||||
$unitTest = $this->in($prompt, array('y','n'), 'y');
|
||||
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes';
|
||||
|
||||
if ($result) {
|
||||
$this->out();
|
||||
$this->out('You can download SimpleTest from http://simpletest.org');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes absolute file path easier to read
|
||||
*
|
||||
* @param string $file Absolute file path
|
||||
* @return sting short path
|
||||
* @access public
|
||||
*/
|
||||
function shortPath($file) {
|
||||
$shortPath = str_replace(ROOT, null, $file);
|
||||
$shortPath = str_replace('..' . DS, '', $shortPath);
|
||||
return str_replace(DS . DS, DS, $shortPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the proper controller path for the specified controller class name
|
||||
*
|
||||
* @param string $name Controller class name
|
||||
* @return string Path to controller
|
||||
* @access protected
|
||||
*/
|
||||
function _controllerPath($name) {
|
||||
return strtolower(Inflector::underscore($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the proper controller plural name for the specified controller class name
|
||||
*
|
||||
* @param string $name Controller class name
|
||||
* @return string Controller plural name
|
||||
* @access protected
|
||||
*/
|
||||
function _controllerName($name) {
|
||||
return Inflector::pluralize(Inflector::camelize($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the proper controller camelized name (singularized) for the specified name
|
||||
*
|
||||
* @param string $name Name
|
||||
* @return string Camelized and singularized controller name
|
||||
* @access protected
|
||||
*/
|
||||
function _modelName($name) {
|
||||
return Inflector::camelize(Inflector::singularize($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the proper underscored model key for associations
|
||||
*
|
||||
* @param string $name Model class name
|
||||
* @return string Singular model key
|
||||
* @access protected
|
||||
*/
|
||||
function _modelKey($name) {
|
||||
return Inflector::underscore($name) . '_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the proper model name from a foreign key
|
||||
*
|
||||
* @param string $key Foreign key
|
||||
* @return string Model name
|
||||
* @access protected
|
||||
*/
|
||||
function _modelNameFromKey($key) {
|
||||
return Inflector::camelize(str_replace('_id', '', $key));
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the singular name for use in views.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string $name
|
||||
* @access protected
|
||||
*/
|
||||
function _singularName($name) {
|
||||
return Inflector::variable(Inflector::singularize($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the plural name for views
|
||||
*
|
||||
* @param string $name Name to use
|
||||
* @return string Plural name for views
|
||||
* @access protected
|
||||
*/
|
||||
function _pluralName($name) {
|
||||
return Inflector::variable(Inflector::pluralize($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the singular human name used in views
|
||||
*
|
||||
* @param string $name Controller name
|
||||
* @return string Singular human name
|
||||
* @access protected
|
||||
*/
|
||||
function _singularHumanName($name) {
|
||||
return Inflector::humanize(Inflector::underscore(Inflector::singularize($name)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the plural human name used in views
|
||||
*
|
||||
* @param string $name Controller name
|
||||
* @return string Plural human name
|
||||
* @access protected
|
||||
*/
|
||||
function _pluralHumanName($name) {
|
||||
return Inflector::humanize(Inflector::underscore($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
|
||||
*
|
||||
* @param string $pluginName Name of the plugin you want ie. DebugKit
|
||||
* @return string $path path to the correct plugin.
|
||||
*/
|
||||
function _pluginPath($pluginName) {
|
||||
return App::pluginPath($pluginName);
|
||||
}
|
||||
}
|
60
php-practice/web-cake/html/cake/console/libs/tasks/bake.php
Normal file
60
php-practice/web-cake/html/cake/console/libs/tasks/bake.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Base class for Bake Tasks.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
class BakeTask extends Shell {
|
||||
|
||||
/**
|
||||
* Name of plugin
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $plugin = null;
|
||||
|
||||
/**
|
||||
* The db connection being used for baking
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $connection = null;
|
||||
|
||||
/**
|
||||
* Flag for interactive mode
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $interactive = false;
|
||||
|
||||
/**
|
||||
* Gets the path for output. Checks the plugin property
|
||||
* and returns the correct path.
|
||||
*
|
||||
* @return string Path to output.
|
||||
* @access public
|
||||
*/
|
||||
function getPath() {
|
||||
$path = $this->path;
|
||||
if (isset($this->plugin)) {
|
||||
$name = substr($this->name, 0, strlen($this->name) - 4);
|
||||
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($name)) . DS;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
}
|
@@ -0,0 +1,481 @@
|
||||
<?php
|
||||
/**
|
||||
* The ControllerTask handles creating and updating controller files.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
||||
|
||||
/**
|
||||
* Task class for creating and updating controller files.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class ControllerTask extends BakeTask {
|
||||
|
||||
/**
|
||||
* Tasks to be loaded by this Task
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('Model', 'Test', 'Template', 'DbConfig', 'Project');
|
||||
|
||||
/**
|
||||
* path to CONTROLLERS directory
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $path = CONTROLLERS;
|
||||
|
||||
/**
|
||||
* Override initialize
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function execute() {
|
||||
if (empty($this->args)) {
|
||||
return $this->__interactive();
|
||||
}
|
||||
|
||||
if (isset($this->args[0])) {
|
||||
if (!isset($this->connection)) {
|
||||
$this->connection = 'default';
|
||||
}
|
||||
if (strtolower($this->args[0]) == 'all') {
|
||||
return $this->all();
|
||||
}
|
||||
|
||||
$controller = $this->_controllerName($this->args[0]);
|
||||
$actions = 'scaffold';
|
||||
|
||||
if (!empty($this->args[1]) && ($this->args[1] == 'public' || $this->args[1] == 'scaffold')) {
|
||||
$this->out(__('Baking basic crud methods for ', true) . $controller);
|
||||
$actions = $this->bakeActions($controller);
|
||||
} elseif (!empty($this->args[1]) && $this->args[1] == 'admin') {
|
||||
$admin = $this->Project->getPrefix();
|
||||
if ($admin) {
|
||||
$this->out(sprintf(__('Adding %s methods', true), $admin));
|
||||
$actions = $this->bakeActions($controller, $admin);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->args[2]) && $this->args[2] == 'admin') {
|
||||
$admin = $this->Project->getPrefix();
|
||||
if ($admin) {
|
||||
$this->out(sprintf(__('Adding %s methods', true), $admin));
|
||||
$actions .= "\n" . $this->bakeActions($controller, $admin);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->bake($controller, $actions)) {
|
||||
if ($this->_checkUnitTest()) {
|
||||
$this->bakeTest($controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake All the controllers at once. Will only bake controllers for models that exist.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function all() {
|
||||
$this->interactive = false;
|
||||
$this->listAll($this->connection, false);
|
||||
ClassRegistry::config('Model', array('ds' => $this->connection));
|
||||
$unitTestExists = $this->_checkUnitTest();
|
||||
foreach ($this->__tables as $table) {
|
||||
$model = $this->_modelName($table);
|
||||
$controller = $this->_controllerName($model);
|
||||
if (App::import('Model', $model)) {
|
||||
$actions = $this->bakeActions($controller);
|
||||
if ($this->bake($controller, $actions) && $unitTestExists) {
|
||||
$this->bakeTest($controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactive
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __interactive() {
|
||||
$this->interactive = true;
|
||||
$this->hr();
|
||||
$this->out(sprintf(__("Bake Controller\nPath: %s", true), $this->path));
|
||||
$this->hr();
|
||||
|
||||
if (empty($this->connection)) {
|
||||
$this->connection = $this->DbConfig->getConfig();
|
||||
}
|
||||
|
||||
$controllerName = $this->getName();
|
||||
$this->hr();
|
||||
$this->out(sprintf(__('Baking %sController', true), $controllerName));
|
||||
$this->hr();
|
||||
|
||||
$helpers = $components = array();
|
||||
$actions = '';
|
||||
$wannaUseSession = 'y';
|
||||
$wannaBakeAdminCrud = 'n';
|
||||
$useDynamicScaffold = 'n';
|
||||
$wannaBakeCrud = 'y';
|
||||
|
||||
$controllerFile = strtolower(Inflector::underscore($controllerName));
|
||||
|
||||
$question[] = __("Would you like to build your controller interactively?", true);
|
||||
if (file_exists($this->path . $controllerFile .'_controller.php')) {
|
||||
$question[] = sprintf(__("Warning: Choosing no will overwrite the %sController.", true), $controllerName);
|
||||
}
|
||||
$doItInteractive = $this->in(implode("\n", $question), array('y','n'), 'y');
|
||||
|
||||
if (strtolower($doItInteractive) == 'y') {
|
||||
$this->interactive = true;
|
||||
$useDynamicScaffold = $this->in(
|
||||
__("Would you like to use dynamic scaffolding?", true), array('y','n'), 'n'
|
||||
);
|
||||
|
||||
if (strtolower($useDynamicScaffold) == 'y') {
|
||||
$wannaBakeCrud = 'n';
|
||||
$actions = 'scaffold';
|
||||
} else {
|
||||
list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
|
||||
|
||||
$helpers = $this->doHelpers();
|
||||
$components = $this->doComponents();
|
||||
|
||||
$wannaUseSession = $this->in(
|
||||
__("Would you like to use Session flash messages?", true), array('y','n'), 'y'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
|
||||
}
|
||||
|
||||
if (strtolower($wannaBakeCrud) == 'y') {
|
||||
$actions = $this->bakeActions($controllerName, null, strtolower($wannaUseSession) == 'y');
|
||||
}
|
||||
if (strtolower($wannaBakeAdminCrud) == 'y') {
|
||||
$admin = $this->Project->getPrefix();
|
||||
$actions .= $this->bakeActions($controllerName, $admin, strtolower($wannaUseSession) == 'y');
|
||||
}
|
||||
|
||||
$baked = false;
|
||||
if ($this->interactive === true) {
|
||||
$this->confirmController($controllerName, $useDynamicScaffold, $helpers, $components);
|
||||
$looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');
|
||||
|
||||
if (strtolower($looksGood) == 'y') {
|
||||
$baked = $this->bake($controllerName, $actions, $helpers, $components);
|
||||
if ($baked && $this->_checkUnitTest()) {
|
||||
$this->bakeTest($controllerName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$baked = $this->bake($controllerName, $actions, $helpers, $components);
|
||||
if ($baked && $this->_checkUnitTest()) {
|
||||
$this->bakeTest($controllerName);
|
||||
}
|
||||
}
|
||||
return $baked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm a to be baked controller with the user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) {
|
||||
$this->out();
|
||||
$this->hr();
|
||||
$this->out(__('The following controller will be created:', true));
|
||||
$this->hr();
|
||||
$this->out(sprintf(__("Controller Name:\n\t%s", true), $controllerName));
|
||||
|
||||
if (strtolower($useDynamicScaffold) == 'y') {
|
||||
$this->out("var \$scaffold;");
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'helpers' => __("Helpers:", true),
|
||||
'components' => __('Components:', true),
|
||||
);
|
||||
|
||||
foreach ($properties as $var => $title) {
|
||||
if (count($$var)) {
|
||||
$output = '';
|
||||
$length = count($$var);
|
||||
foreach ($$var as $i => $propElement) {
|
||||
if ($i != $length -1) {
|
||||
$output .= ucfirst($propElement) . ', ';
|
||||
} else {
|
||||
$output .= ucfirst($propElement);
|
||||
}
|
||||
}
|
||||
$this->out($title . "\n\t" . $output);
|
||||
}
|
||||
}
|
||||
$this->hr();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact with the user and ask about which methods (admin or regular they want to bake)
|
||||
*
|
||||
* @return array Array containing (bakeRegular, bakeAdmin) answers
|
||||
*/
|
||||
function _askAboutMethods() {
|
||||
$wannaBakeCrud = $this->in(
|
||||
__("Would you like to create some basic class methods \n(index(), add(), view(), edit())?", true),
|
||||
array('y','n'), 'n'
|
||||
);
|
||||
$wannaBakeAdminCrud = $this->in(
|
||||
__("Would you like to create the basic class methods for admin routing?", true),
|
||||
array('y','n'), 'n'
|
||||
);
|
||||
return array($wannaBakeCrud, $wannaBakeAdminCrud);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake scaffold actions
|
||||
*
|
||||
* @param string $controllerName Controller name
|
||||
* @param string $admin Admin route to use
|
||||
* @param boolean $wannaUseSession Set to true to use sessions, false otherwise
|
||||
* @return string Baked actions
|
||||
* @access private
|
||||
*/
|
||||
function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
|
||||
$currentModelName = $modelImport = $this->_modelName($controllerName);
|
||||
$plugin = $this->plugin;
|
||||
if ($plugin) {
|
||||
$modelImport = $plugin . '.' . $modelImport;
|
||||
}
|
||||
if (!App::import('Model', $modelImport)) {
|
||||
$this->err(__('You must have a model for this class to build basic methods. Please try again.', true));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$modelObj =& ClassRegistry::init($currentModelName);
|
||||
$controllerPath = $this->_controllerPath($controllerName);
|
||||
$pluralName = $this->_pluralName($currentModelName);
|
||||
$singularName = Inflector::variable($currentModelName);
|
||||
$singularHumanName = $this->_singularHumanName($controllerName);
|
||||
$pluralHumanName = $this->_pluralName($controllerName);
|
||||
|
||||
$this->Template->set(compact('plugin', 'admin', 'controllerPath', 'pluralName', 'singularName', 'singularHumanName',
|
||||
'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName'));
|
||||
$actions = $this->Template->generate('actions', 'controller_actions');
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles and writes a Controller file
|
||||
*
|
||||
* @param string $controllerName Controller name
|
||||
* @param string $actions Actions to add, or set the whole controller to use $scaffold (set $actions to 'scaffold')
|
||||
* @param array $helpers Helpers to use in controller
|
||||
* @param array $components Components to use in controller
|
||||
* @param array $uses Models to use in controller
|
||||
* @return string Baked controller
|
||||
* @access private
|
||||
*/
|
||||
function bake($controllerName, $actions = '', $helpers = null, $components = null) {
|
||||
$isScaffold = ($actions === 'scaffold') ? true : false;
|
||||
|
||||
$this->Template->set('plugin', Inflector::camelize($this->plugin));
|
||||
$this->Template->set(compact('controllerName', 'actions', 'helpers', 'components', 'isScaffold'));
|
||||
$contents = $this->Template->generate('classes', 'controller');
|
||||
|
||||
$path = $this->getPath();
|
||||
$filename = $path . $this->_controllerPath($controllerName) . '_controller.php';
|
||||
if ($this->createFile($filename, $contents)) {
|
||||
return $contents;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles and writes a unit test file
|
||||
*
|
||||
* @param string $className Controller class name
|
||||
* @return string Baked test
|
||||
* @access private
|
||||
*/
|
||||
function bakeTest($className) {
|
||||
$this->Test->plugin = $this->plugin;
|
||||
$this->Test->connection = $this->connection;
|
||||
$this->Test->interactive = $this->interactive;
|
||||
return $this->Test->bake('Controller', $className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact with the user and get a list of additional helpers
|
||||
*
|
||||
* @return array Helpers that the user wants to use.
|
||||
*/
|
||||
function doHelpers() {
|
||||
return $this->_doPropertyChoices(
|
||||
__("Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?", true),
|
||||
__("Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'", true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact with the user and get a list of additional components
|
||||
*
|
||||
* @return array Components the user wants to use.
|
||||
*/
|
||||
function doComponents() {
|
||||
return $this->_doPropertyChoices(
|
||||
__("Would you like this controller to use any components?", true),
|
||||
__("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'", true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common code for property choice handling.
|
||||
*
|
||||
* @param string $prompt A yes/no question to precede the list
|
||||
* @param sting $example A question for a comma separated list, with examples.
|
||||
* @return array Array of values for property.
|
||||
*/
|
||||
function _doPropertyChoices($prompt, $example) {
|
||||
$proceed = $this->in($prompt, array('y','n'), 'n');
|
||||
$property = array();
|
||||
if (strtolower($proceed) == 'y') {
|
||||
$propertyList = $this->in($example);
|
||||
$propertyListTrimmed = str_replace(' ', '', $propertyList);
|
||||
$property = explode(',', $propertyListTrimmed);
|
||||
}
|
||||
return array_filter($property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs and gets the list of possible controllers from database
|
||||
*
|
||||
* @param string $useDbConfig Database configuration name
|
||||
* @param boolean $interactive Whether you are using listAll interactively and want options output.
|
||||
* @return array Set of controllers
|
||||
* @access public
|
||||
*/
|
||||
function listAll($useDbConfig = null) {
|
||||
if (is_null($useDbConfig)) {
|
||||
$useDbConfig = $this->connection;
|
||||
}
|
||||
$this->__tables = $this->Model->getAllTables($useDbConfig);
|
||||
|
||||
if ($this->interactive == true) {
|
||||
$this->out(__('Possible Controllers based on your current database:', true));
|
||||
$this->_controllerNames = array();
|
||||
$count = count($this->__tables);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->_controllerNames[] = $this->_controllerName($this->_modelName($this->__tables[$i]));
|
||||
$this->out($i + 1 . ". " . $this->_controllerNames[$i]);
|
||||
}
|
||||
return $this->_controllerNames;
|
||||
}
|
||||
return $this->__tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the user to specify the controller he wants to bake, and returns the selected controller name.
|
||||
*
|
||||
* @param string $useDbConfig Connection name to get a controller name for.
|
||||
* @return string Controller name
|
||||
* @access public
|
||||
*/
|
||||
function getName($useDbConfig = null) {
|
||||
$controllers = $this->listAll($useDbConfig);
|
||||
$enteredController = '';
|
||||
|
||||
while ($enteredController == '') {
|
||||
$enteredController = $this->in(__("Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit", true), null, 'q');
|
||||
|
||||
if ($enteredController === 'q') {
|
||||
$this->out(__("Exit", true));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
|
||||
$this->err(__("The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again.", true));
|
||||
$enteredController = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers) ) {
|
||||
$controllerName = $controllers[intval($enteredController) - 1];
|
||||
} else {
|
||||
$controllerName = Inflector::camelize($enteredController);
|
||||
}
|
||||
return $controllerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays help contents
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->hr();
|
||||
$this->out("Usage: cake bake controller <arg1> <arg2>...");
|
||||
$this->hr();
|
||||
$this->out('Arguments:');
|
||||
$this->out();
|
||||
$this->out("<name>");
|
||||
$this->out("\tName of the controller to bake. Can use Plugin.name");
|
||||
$this->out("\tas a shortcut for plugin baking.");
|
||||
$this->out();
|
||||
$this->out('Commands:');
|
||||
$this->out();
|
||||
$this->out("controller <name>");
|
||||
$this->out("\tbakes controller with var \$scaffold");
|
||||
$this->out();
|
||||
$this->out("controller <name> public");
|
||||
$this->out("\tbakes controller with basic crud actions");
|
||||
$this->out("\t(index, view, add, edit, delete)");
|
||||
$this->out();
|
||||
$this->out("controller <name> admin");
|
||||
$this->out("\tbakes a controller with basic crud actions for one of the");
|
||||
$this->out("\tConfigure::read('Routing.prefixes') methods.");
|
||||
$this->out();
|
||||
$this->out("controller <name> public admin");
|
||||
$this->out("\tbakes a controller with basic crud actions for one");
|
||||
$this->out("\tConfigure::read('Routing.prefixes') and non admin methods.");
|
||||
$this->out("\t(index, view, add, edit, delete,");
|
||||
$this->out("\tadmin_index, admin_view, admin_edit, admin_add, admin_delete)");
|
||||
$this->out();
|
||||
$this->out("controller all");
|
||||
$this->out("\tbakes all controllers with CRUD methods.");
|
||||
$this->out();
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
368
php-practice/web-cake/html/cake/console/libs/tasks/db_config.php
Normal file
368
php-practice/web-cake/html/cake/console/libs/tasks/db_config.php
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
/**
|
||||
* The DbConfig Task handles creating and updating the database.php
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Task class for creating and updating the database configuration file.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class DbConfigTask extends Shell {
|
||||
|
||||
/**
|
||||
* path to CONFIG directory
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $path = null;
|
||||
|
||||
/**
|
||||
* Default configuration settings to use
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__defaultConfig = array(
|
||||
'name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
|
||||
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
|
||||
'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* String name of the database config class name.
|
||||
* Used for testing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $databaseClassName = 'DATABASE_CONFIG';
|
||||
|
||||
/**
|
||||
* initialization callback
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {
|
||||
$this->path = $this->params['working'] . DS . 'config' . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function execute() {
|
||||
if (empty($this->args)) {
|
||||
$this->__interactive();
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactive interface
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __interactive() {
|
||||
$this->hr();
|
||||
$this->out('Database Configuration:');
|
||||
$this->hr();
|
||||
$done = false;
|
||||
$dbConfigs = array();
|
||||
|
||||
while ($done == false) {
|
||||
$name = '';
|
||||
|
||||
while ($name == '') {
|
||||
$name = $this->in("Name:", null, 'default');
|
||||
if (preg_match('/[^a-z0-9_]/i', $name)) {
|
||||
$name = '';
|
||||
$this->out('The name may only contain unaccented latin characters, numbers or underscores');
|
||||
} else if (preg_match('/^[^a-z_]/i', $name)) {
|
||||
$name = '';
|
||||
$this->out('The name must start with an unaccented latin character or an underscore');
|
||||
}
|
||||
}
|
||||
|
||||
$driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'mysqli', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql');
|
||||
|
||||
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
|
||||
if (strtolower($persistent) == 'n') {
|
||||
$persistent = 'false';
|
||||
} else {
|
||||
$persistent = 'true';
|
||||
}
|
||||
|
||||
$host = '';
|
||||
while ($host == '') {
|
||||
$host = $this->in('Database Host:', null, 'localhost');
|
||||
}
|
||||
|
||||
$port = '';
|
||||
while ($port == '') {
|
||||
$port = $this->in('Port?', null, 'n');
|
||||
}
|
||||
|
||||
if (strtolower($port) == 'n') {
|
||||
$port = null;
|
||||
}
|
||||
|
||||
$login = '';
|
||||
while ($login == '') {
|
||||
$login = $this->in('User:', null, 'root');
|
||||
}
|
||||
$password = '';
|
||||
$blankPassword = false;
|
||||
|
||||
while ($password == '' && $blankPassword == false) {
|
||||
$password = $this->in('Password:');
|
||||
|
||||
if ($password == '') {
|
||||
$blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
|
||||
if ($blank == 'y') {
|
||||
$blankPassword = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$database = '';
|
||||
while ($database == '') {
|
||||
$database = $this->in('Database Name:', null, 'cake');
|
||||
}
|
||||
|
||||
$prefix = '';
|
||||
while ($prefix == '') {
|
||||
$prefix = $this->in('Table Prefix?', null, 'n');
|
||||
}
|
||||
if (strtolower($prefix) == 'n') {
|
||||
$prefix = null;
|
||||
}
|
||||
|
||||
$encoding = '';
|
||||
while ($encoding == '') {
|
||||
$encoding = $this->in('Table encoding?', null, 'n');
|
||||
}
|
||||
if (strtolower($encoding) == 'n') {
|
||||
$encoding = null;
|
||||
}
|
||||
|
||||
$schema = '';
|
||||
if ($driver == 'postgres') {
|
||||
while ($schema == '') {
|
||||
$schema = $this->in('Table schema?', null, 'n');
|
||||
}
|
||||
}
|
||||
if (strtolower($schema) == 'n') {
|
||||
$schema = null;
|
||||
}
|
||||
|
||||
$config = compact('name', 'driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema');
|
||||
|
||||
while ($this->__verify($config) == false) {
|
||||
$this->__interactive();
|
||||
}
|
||||
$dbConfigs[] = $config;
|
||||
$doneYet = $this->in('Do you wish to add another database configuration?', null, 'n');
|
||||
|
||||
if (strtolower($doneYet == 'n')) {
|
||||
$done = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->bake($dbConfigs);
|
||||
config('database');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output verification message and bake if it looks good
|
||||
*
|
||||
* @return boolean True if user says it looks good, false otherwise
|
||||
* @access private
|
||||
*/
|
||||
function __verify($config) {
|
||||
$config = array_merge($this->__defaultConfig, $config);
|
||||
extract($config);
|
||||
$this->out();
|
||||
$this->hr();
|
||||
$this->out('The following database configuration will be created:');
|
||||
$this->hr();
|
||||
$this->out("Name: $name");
|
||||
$this->out("Driver: $driver");
|
||||
$this->out("Persistent: $persistent");
|
||||
$this->out("Host: $host");
|
||||
|
||||
if ($port) {
|
||||
$this->out("Port: $port");
|
||||
}
|
||||
|
||||
$this->out("User: $login");
|
||||
$this->out("Pass: " . str_repeat('*', strlen($password)));
|
||||
$this->out("Database: $database");
|
||||
|
||||
if ($prefix) {
|
||||
$this->out("Table prefix: $prefix");
|
||||
}
|
||||
|
||||
if ($schema) {
|
||||
$this->out("Schema: $schema");
|
||||
}
|
||||
|
||||
if ($encoding) {
|
||||
$this->out("Encoding: $encoding");
|
||||
}
|
||||
|
||||
$this->hr();
|
||||
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
|
||||
|
||||
if (strtolower($looksGood) == 'y') {
|
||||
return $config;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles and writes database.php
|
||||
*
|
||||
* @param array $configs Configuration settings to use
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
function bake($configs) {
|
||||
if (!is_dir($this->path)) {
|
||||
$this->err($this->path . ' not found');
|
||||
return false;
|
||||
}
|
||||
|
||||
$filename = $this->path . 'database.php';
|
||||
$oldConfigs = array();
|
||||
|
||||
if (file_exists($filename)) {
|
||||
config('database');
|
||||
$db = new $this->databaseClassName;
|
||||
$temp = get_class_vars(get_class($db));
|
||||
|
||||
foreach ($temp as $configName => $info) {
|
||||
$info = array_merge($this->__defaultConfig, $info);
|
||||
|
||||
if (!isset($info['schema'])) {
|
||||
$info['schema'] = null;
|
||||
}
|
||||
if (!isset($info['encoding'])) {
|
||||
$info['encoding'] = null;
|
||||
}
|
||||
if (!isset($info['port'])) {
|
||||
$info['port'] = null;
|
||||
}
|
||||
|
||||
if ($info['persistent'] === false) {
|
||||
$info['persistent'] = 'false';
|
||||
} else {
|
||||
$info['persistent'] = ($info['persistent'] == true) ? 'true' : 'false';
|
||||
}
|
||||
|
||||
$oldConfigs[] = array(
|
||||
'name' => $configName,
|
||||
'driver' => $info['driver'],
|
||||
'persistent' => $info['persistent'],
|
||||
'host' => $info['host'],
|
||||
'port' => $info['port'],
|
||||
'login' => $info['login'],
|
||||
'password' => $info['password'],
|
||||
'database' => $info['database'],
|
||||
'prefix' => $info['prefix'],
|
||||
'schema' => $info['schema'],
|
||||
'encoding' => $info['encoding']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($oldConfigs as $key => $oldConfig) {
|
||||
foreach ($configs as $key1 => $config) {
|
||||
if ($oldConfig['name'] == $config['name']) {
|
||||
unset($oldConfigs[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$configs = array_merge($oldConfigs, $configs);
|
||||
$out = "<?php\n";
|
||||
$out .= "class DATABASE_CONFIG {\n\n";
|
||||
|
||||
foreach ($configs as $config) {
|
||||
$config = array_merge($this->__defaultConfig, $config);
|
||||
extract($config);
|
||||
|
||||
$out .= "\tvar \${$name} = array(\n";
|
||||
$out .= "\t\t'driver' => '{$driver}',\n";
|
||||
$out .= "\t\t'persistent' => {$persistent},\n";
|
||||
$out .= "\t\t'host' => '{$host}',\n";
|
||||
|
||||
if ($port) {
|
||||
$out .= "\t\t'port' => {$port},\n";
|
||||
}
|
||||
|
||||
$out .= "\t\t'login' => '{$login}',\n";
|
||||
$out .= "\t\t'password' => '{$password}',\n";
|
||||
$out .= "\t\t'database' => '{$database}',\n";
|
||||
|
||||
if ($schema) {
|
||||
$out .= "\t\t'schema' => '{$schema}',\n";
|
||||
}
|
||||
|
||||
if ($prefix) {
|
||||
$out .= "\t\t'prefix' => '{$prefix}',\n";
|
||||
}
|
||||
|
||||
if ($encoding) {
|
||||
$out .= "\t\t'encoding' => '{$encoding}'\n";
|
||||
}
|
||||
|
||||
$out .= "\t);\n";
|
||||
}
|
||||
|
||||
$out .= "}\n";
|
||||
$out .= "?>";
|
||||
$filename = $this->path . 'database.php';
|
||||
return $this->createFile($filename, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user specified Connection name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function getConfig() {
|
||||
App::import('Model', 'ConnectionManager', false);
|
||||
|
||||
$useDbConfig = 'default';
|
||||
$configs = get_class_vars($this->databaseClassName);
|
||||
if (!is_array($configs)) {
|
||||
return $this->execute();
|
||||
}
|
||||
|
||||
$connections = array_keys($configs);
|
||||
if (count($connections) > 1) {
|
||||
$useDbConfig = $this->in(__('Use Database Config', true) .':', $connections, 'default');
|
||||
}
|
||||
return $useDbConfig;
|
||||
}
|
||||
}
|
494
php-practice/web-cake/html/cake/console/libs/tasks/extract.php
Normal file
494
php-practice/web-cake/html/cake/console/libs/tasks/extract.php
Normal file
@@ -0,0 +1,494 @@
|
||||
<?php
|
||||
/**
|
||||
* Language string extractor
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Language string extractor
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class ExtractTask extends Shell {
|
||||
|
||||
/**
|
||||
* Paths to use when looking for strings
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $__paths = array();
|
||||
|
||||
/**
|
||||
* Files from where to extract
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__files = array();
|
||||
|
||||
/**
|
||||
* Merge all domains string into the default.pot file
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $__merge = false;
|
||||
|
||||
/**
|
||||
* Current file being processed
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $__file = null;
|
||||
|
||||
/**
|
||||
* Contains all content waiting to be write
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $__storage = array();
|
||||
|
||||
/**
|
||||
* Extracted tokens
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__tokens = array();
|
||||
|
||||
/**
|
||||
* Extracted strings
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__strings = array();
|
||||
|
||||
/**
|
||||
* Destination path
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $__output = null;
|
||||
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function execute() {
|
||||
if (isset($this->params['files']) && !is_array($this->params['files'])) {
|
||||
$this->__files = explode(',', $this->params['files']);
|
||||
}
|
||||
if (isset($this->params['paths'])) {
|
||||
$this->__paths = explode(',', $this->params['paths']);
|
||||
} else {
|
||||
$defaultPath = $this->params['working'];
|
||||
$message = sprintf(__("What is the full path you would like to extract?\nExample: %s\n[Q]uit [D]one", true), $this->params['root'] . DS . 'myapp');
|
||||
while (true) {
|
||||
$response = $this->in($message, null, $defaultPath);
|
||||
if (strtoupper($response) === 'Q') {
|
||||
$this->out(__('Extract Aborted', true));
|
||||
$this->_stop();
|
||||
} elseif (strtoupper($response) === 'D') {
|
||||
$this->out();
|
||||
break;
|
||||
} elseif (is_dir($response)) {
|
||||
$this->__paths[] = $response;
|
||||
$defaultPath = 'D';
|
||||
} else {
|
||||
$this->err(__('The directory path you supplied was not found. Please try again.', true));
|
||||
}
|
||||
$this->out();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->params['output'])) {
|
||||
$this->__output = $this->params['output'];
|
||||
} else {
|
||||
$message = sprintf(__("What is the full path you would like to output?\nExample: %s\n[Q]uit", true), $this->__paths[0] . DS . 'locale');
|
||||
while (true) {
|
||||
$response = $this->in($message, null, $this->__paths[0] . DS . 'locale');
|
||||
if (strtoupper($response) === 'Q') {
|
||||
$this->out(__('Extract Aborted', true));
|
||||
$this->_stop();
|
||||
} elseif (is_dir($response)) {
|
||||
$this->__output = $response . DS;
|
||||
break;
|
||||
} else {
|
||||
$this->err(__('The directory path you supplied was not found. Please try again.', true));
|
||||
}
|
||||
$this->out();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->params['merge'])) {
|
||||
$this->__merge = !(strtolower($this->params['merge']) === 'no');
|
||||
} else {
|
||||
$this->out();
|
||||
$response = $this->in(sprintf(__('Would you like to merge all domains strings into the default.pot file?', true)), array('y', 'n'), 'n');
|
||||
$this->__merge = strtolower($response) === 'y';
|
||||
}
|
||||
|
||||
if (empty($this->__files)) {
|
||||
$this->__searchFiles();
|
||||
}
|
||||
$this->__extract();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract text
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __extract() {
|
||||
$this->out();
|
||||
$this->out();
|
||||
$this->out(__('Extracting...', true));
|
||||
$this->hr();
|
||||
$this->out(__('Paths:', true));
|
||||
foreach ($this->__paths as $path) {
|
||||
$this->out(' ' . $path);
|
||||
}
|
||||
$this->out(__('Output Directory: ', true) . $this->__output);
|
||||
$this->hr();
|
||||
$this->__extractTokens();
|
||||
$this->__buildFiles();
|
||||
$this->__writeFiles();
|
||||
$this->__paths = $this->__files = $this->__storage = array();
|
||||
$this->__strings = $this->__tokens = array();
|
||||
$this->out();
|
||||
$this->out(__('Done.', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help options
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->out(__('CakePHP Language String Extraction:', true));
|
||||
$this->hr();
|
||||
$this->out(__('The Extract script generates .pot file(s) with translations', true));
|
||||
$this->out(__('By default the .pot file(s) will be place in the locale directory of -app', true));
|
||||
$this->out(__('By default -app is ROOT/app', true));
|
||||
$this->hr();
|
||||
$this->out(__('Usage: cake i18n extract <command> <param1> <param2>...', true));
|
||||
$this->out();
|
||||
$this->out(__('Params:', true));
|
||||
$this->out(__(' -app [path...]: directory where your application is located', true));
|
||||
$this->out(__(' -root [path...]: path to install', true));
|
||||
$this->out(__(' -core [path...]: path to cake directory', true));
|
||||
$this->out(__(' -paths [comma separated list of paths, full path is needed]', true));
|
||||
$this->out(__(' -merge [yes|no]: Merge all domains strings into the default.pot file', true));
|
||||
$this->out(__(' -output [path...]: Full path to output directory', true));
|
||||
$this->out(__(' -files: [comma separated list of files, full path to file is needed]', true));
|
||||
$this->out();
|
||||
$this->out(__('Commands:', true));
|
||||
$this->out(__(' cake i18n extract help: Shows this help message.', true));
|
||||
$this->out();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract tokens out of all files to be processed
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __extractTokens() {
|
||||
foreach ($this->__files as $file) {
|
||||
$this->__file = $file;
|
||||
$this->out(sprintf(__('Processing %s...', true), $file));
|
||||
|
||||
$code = file_get_contents($file);
|
||||
$allTokens = token_get_all($code);
|
||||
$this->__tokens = array();
|
||||
$lineNumber = 1;
|
||||
|
||||
foreach ($allTokens as $token) {
|
||||
if ((!is_array($token)) || (($token[0] != T_WHITESPACE) && ($token[0] != T_INLINE_HTML))) {
|
||||
if (is_array($token)) {
|
||||
$token[] = $lineNumber;
|
||||
}
|
||||
$this->__tokens[] = $token;
|
||||
}
|
||||
|
||||
if (is_array($token)) {
|
||||
$lineNumber += count(explode("\n", $token[1])) - 1;
|
||||
} else {
|
||||
$lineNumber += count(explode("\n", $token)) - 1;
|
||||
}
|
||||
}
|
||||
unset($allTokens);
|
||||
$this->__parse('__', array('singular'));
|
||||
$this->__parse('__n', array('singular', 'plural'));
|
||||
$this->__parse('__d', array('domain', 'singular'));
|
||||
$this->__parse('__c', array('singular'));
|
||||
$this->__parse('__dc', array('domain', 'singular'));
|
||||
$this->__parse('__dn', array('domain', 'singular', 'plural'));
|
||||
$this->__parse('__dcn', array('domain', 'singular', 'plural'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse tokens
|
||||
*
|
||||
* @param string $functionName Function name that indicates translatable string (e.g: '__')
|
||||
* @param array $map Array containing what variables it will find (e.g: domain, singular, plural)
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __parse($functionName, $map) {
|
||||
$count = 0;
|
||||
$tokenCount = count($this->__tokens);
|
||||
|
||||
while (($tokenCount - $count) > 1) {
|
||||
list($countToken, $firstParenthesis) = array($this->__tokens[$count], $this->__tokens[$count + 1]);
|
||||
if (!is_array($countToken)) {
|
||||
$count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
list($type, $string, $line) = $countToken;
|
||||
if (($type == T_STRING) && ($string == $functionName) && ($firstParenthesis == '(')) {
|
||||
$position = $count;
|
||||
$depth = 0;
|
||||
|
||||
while ($depth == 0) {
|
||||
if ($this->__tokens[$position] == '(') {
|
||||
$depth++;
|
||||
} elseif ($this->__tokens[$position] == ')') {
|
||||
$depth--;
|
||||
}
|
||||
$position++;
|
||||
}
|
||||
|
||||
$mapCount = count($map);
|
||||
$strings = array();
|
||||
while (count($strings) < $mapCount && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
|
||||
if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
|
||||
$strings[] = $this->__tokens[$position][1];
|
||||
}
|
||||
$position++;
|
||||
}
|
||||
|
||||
if ($mapCount == count($strings)) {
|
||||
extract(array_combine($map, $strings));
|
||||
if (!isset($domain)) {
|
||||
$domain = '\'default\'';
|
||||
}
|
||||
$string = $this->__formatString($singular);
|
||||
if (isset($plural)) {
|
||||
$string .= "\0" . $this->__formatString($plural);
|
||||
}
|
||||
$this->__strings[$this->__formatString($domain)][$string][$this->__file][] = $line;
|
||||
} else {
|
||||
$this->__markerError($this->__file, $line, $functionName, $count);
|
||||
}
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the translate template file contents out of obtained strings
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __buildFiles() {
|
||||
foreach ($this->__strings as $domain => $strings) {
|
||||
foreach ($strings as $string => $files) {
|
||||
$occurrences = array();
|
||||
foreach ($files as $file => $lines) {
|
||||
$occurrences[] = $file . ':' . implode(';', $lines);
|
||||
}
|
||||
$occurrences = implode("\n#: ", $occurrences);
|
||||
$header = '#: ' . str_replace($this->__paths, '', $occurrences) . "\n";
|
||||
|
||||
if (strpos($string, "\0") === false) {
|
||||
$sentence = "msgid \"{$string}\"\n";
|
||||
$sentence .= "msgstr \"\"\n\n";
|
||||
} else {
|
||||
list($singular, $plural) = explode("\0", $string);
|
||||
$sentence = "msgid \"{$singular}\"\n";
|
||||
$sentence .= "msgid_plural \"{$plural}\"\n";
|
||||
$sentence .= "msgstr[0] \"\"\n";
|
||||
$sentence .= "msgstr[1] \"\"\n\n";
|
||||
}
|
||||
|
||||
$this->__store($domain, $header, $sentence);
|
||||
if ($domain != 'default' && $this->__merge) {
|
||||
$this->__store('default', $header, $sentence);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a file to be stored
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __store($domain, $header, $sentence) {
|
||||
if (!isset($this->__storage[$domain])) {
|
||||
$this->__storage[$domain] = array();
|
||||
}
|
||||
if (!isset($this->__storage[$domain][$sentence])) {
|
||||
$this->__storage[$domain][$sentence] = $header;
|
||||
} else {
|
||||
$this->__storage[$domain][$sentence] .= $header;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the files that need to be stored
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __writeFiles() {
|
||||
$overwriteAll = false;
|
||||
foreach ($this->__storage as $domain => $sentences) {
|
||||
$output = $this->__writeHeader();
|
||||
foreach ($sentences as $sentence => $header) {
|
||||
$output .= $header . $sentence;
|
||||
}
|
||||
|
||||
$filename = $domain . '.pot';
|
||||
$File = new File($this->__output . $filename);
|
||||
$response = '';
|
||||
while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
|
||||
$this->out();
|
||||
$response = $this->in(sprintf(__('Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', true), $filename), array('y', 'n', 'a'), 'y');
|
||||
if (strtoupper($response) === 'N') {
|
||||
$response = '';
|
||||
while ($response == '') {
|
||||
$response = $this->in(sprintf(__("What would you like to name this file?\nExample: %s", true), 'new_' . $filename), null, 'new_' . $filename);
|
||||
$File = new File($this->__output . $response);
|
||||
$filename = $response;
|
||||
}
|
||||
} elseif (strtoupper($response) === 'A') {
|
||||
$overwriteAll = true;
|
||||
}
|
||||
}
|
||||
$File->write($output);
|
||||
$File->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the translation template header
|
||||
*
|
||||
* @return string Translation template header
|
||||
* @access private
|
||||
*/
|
||||
function __writeHeader() {
|
||||
$output = "# LANGUAGE translation of CakePHP Application\n";
|
||||
$output .= "# Copyright YEAR NAME <EMAIL@ADDRESS>\n";
|
||||
$output .= "#\n";
|
||||
$output .= "#, fuzzy\n";
|
||||
$output .= "msgid \"\"\n";
|
||||
$output .= "msgstr \"\"\n";
|
||||
$output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
|
||||
$output .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
|
||||
$output .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n";
|
||||
$output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
|
||||
$output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
|
||||
$output .= "\"MIME-Version: 1.0\\n\"\n";
|
||||
$output .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
|
||||
$output .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
|
||||
$output .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string to be added as a translateable string
|
||||
*
|
||||
* @param string $string String to format
|
||||
* @return string Formatted string
|
||||
* @access private
|
||||
*/
|
||||
function __formatString($string) {
|
||||
$quote = substr($string, 0, 1);
|
||||
$string = substr($string, 1, -1);
|
||||
if ($quote == '"') {
|
||||
$string = stripcslashes($string);
|
||||
} else {
|
||||
$string = strtr($string, array("\\'" => "'", "\\\\" => "\\"));
|
||||
}
|
||||
$string = str_replace("\r\n", "\n", $string);
|
||||
return addcslashes($string, "\0..\37\\\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate an invalid marker on a processed file
|
||||
*
|
||||
* @param string $file File where invalid marker resides
|
||||
* @param integer $line Line number
|
||||
* @param string $marker Marker found
|
||||
* @param integer $count Count
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __markerError($file, $line, $marker, $count) {
|
||||
$this->out(sprintf(__("Invalid marker content in %s:%s\n* %s(", true), $file, $line, $marker), true);
|
||||
$count += 2;
|
||||
$tokenCount = count($this->__tokens);
|
||||
$parenthesis = 1;
|
||||
|
||||
while ((($tokenCount - $count) > 0) && $parenthesis) {
|
||||
if (is_array($this->__tokens[$count])) {
|
||||
$this->out($this->__tokens[$count][1], false);
|
||||
} else {
|
||||
$this->out($this->__tokens[$count], false);
|
||||
if ($this->__tokens[$count] == '(') {
|
||||
$parenthesis++;
|
||||
}
|
||||
|
||||
if ($this->__tokens[$count] == ')') {
|
||||
$parenthesis--;
|
||||
}
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
$this->out("\n", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search files that may contain translateable strings
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __searchFiles() {
|
||||
foreach ($this->__paths as $path) {
|
||||
$Folder = new Folder($path);
|
||||
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
|
||||
$this->__files = array_merge($this->__files, $files);
|
||||
}
|
||||
}
|
||||
}
|
422
php-practice/web-cake/html/cake/console/libs/tasks/fixture.php
Normal file
422
php-practice/web-cake/html/cake/console/libs/tasks/fixture.php
Normal file
@@ -0,0 +1,422 @@
|
||||
<?php
|
||||
/**
|
||||
* The FixtureTask handles creating and updating fixture files.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
||||
/**
|
||||
* Task class for creating and updating fixtures files.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class FixtureTask extends BakeTask {
|
||||
|
||||
/**
|
||||
* Tasks to be loaded by this Task
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('DbConfig', 'Model', 'Template');
|
||||
|
||||
/**
|
||||
* path to fixtures directory
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $path = null;
|
||||
|
||||
/**
|
||||
* Schema instance
|
||||
*
|
||||
* @var object
|
||||
* @access protected
|
||||
*/
|
||||
var $_Schema = null;
|
||||
|
||||
/**
|
||||
* Override initialize
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __construct(&$dispatch) {
|
||||
parent::__construct($dispatch);
|
||||
$this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
* Handles dispatching to interactive, named, or all processess.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function execute() {
|
||||
if (empty($this->args)) {
|
||||
$this->__interactive();
|
||||
}
|
||||
|
||||
if (isset($this->args[0])) {
|
||||
$this->interactive = false;
|
||||
if (!isset($this->connection)) {
|
||||
$this->connection = 'default';
|
||||
}
|
||||
if (strtolower($this->args[0]) == 'all') {
|
||||
return $this->all();
|
||||
}
|
||||
$model = $this->_modelName($this->args[0]);
|
||||
$this->bake($model);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake All the Fixtures at once. Will only bake fixtures for models that exist.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function all() {
|
||||
$this->interactive = false;
|
||||
$this->Model->interactive = false;
|
||||
$tables = $this->Model->listAll($this->connection, false);
|
||||
foreach ($tables as $table) {
|
||||
$model = $this->_modelName($table);
|
||||
$this->bake($model);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactive baking function
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __interactive() {
|
||||
$this->DbConfig->interactive = $this->Model->interactive = $this->interactive = true;
|
||||
$this->hr();
|
||||
$this->out(sprintf("Bake Fixture\nPath: %s", $this->path));
|
||||
$this->hr();
|
||||
|
||||
$useDbConfig = $this->connection;
|
||||
if (!isset($this->connection)) {
|
||||
$this->connection = $this->DbConfig->getConfig();
|
||||
}
|
||||
$modelName = $this->Model->getName($this->connection);
|
||||
$useTable = $this->Model->getTable($modelName, $this->connection);
|
||||
$importOptions = $this->importOptions($modelName);
|
||||
$this->bake($modelName, $useTable, $importOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interacts with the User to setup an array of import options. For a fixture.
|
||||
*
|
||||
* @param string $modelName Name of model you are dealing with.
|
||||
* @return array Array of import options.
|
||||
* @access public
|
||||
*/
|
||||
function importOptions($modelName) {
|
||||
$options = array();
|
||||
$doSchema = $this->in(__('Would you like to import schema for this fixture?', true), array('y', 'n'), 'n');
|
||||
if ($doSchema == 'y') {
|
||||
$options['schema'] = $modelName;
|
||||
}
|
||||
$doRecords = $this->in(__('Would you like to use record importing for this fixture?', true), array('y', 'n'), 'n');
|
||||
if ($doRecords == 'y') {
|
||||
$options['records'] = true;
|
||||
}
|
||||
if ($doRecords == 'n') {
|
||||
$prompt = sprintf(__("Would you like to build this fixture with data from %s's table?", true), $modelName);
|
||||
$fromTable = $this->in($prompt, array('y', 'n'), 'n');
|
||||
if (strtolower($fromTable) == 'y') {
|
||||
$options['fromTable'] = true;
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles and writes a Fixture file
|
||||
*
|
||||
* @param string $model Name of model to bake.
|
||||
* @param string $useTable Name of table to use.
|
||||
* @param array $importOptions Options for var $import
|
||||
* @return string Baked fixture content
|
||||
* @access public
|
||||
*/
|
||||
function bake($model, $useTable = false, $importOptions = array()) {
|
||||
if (!class_exists('CakeSchema')) {
|
||||
App::import('Model', 'CakeSchema', false);
|
||||
}
|
||||
$table = $schema = $records = $import = $modelImport = $recordImport = null;
|
||||
if (!$useTable) {
|
||||
$useTable = Inflector::tableize($model);
|
||||
} elseif ($useTable != Inflector::tableize($model)) {
|
||||
$table = $useTable;
|
||||
}
|
||||
|
||||
if (!empty($importOptions)) {
|
||||
if (isset($importOptions['schema'])) {
|
||||
$modelImport = "'model' => '{$importOptions['schema']}'";
|
||||
}
|
||||
if (isset($importOptions['records'])) {
|
||||
$recordImport = "'records' => true";
|
||||
}
|
||||
if ($modelImport && $recordImport) {
|
||||
$modelImport .= ', ';
|
||||
}
|
||||
if (!empty($modelImport) || !empty($recordImport)) {
|
||||
$import = sprintf("array(%s%s)", $modelImport, $recordImport);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_Schema = new CakeSchema();
|
||||
$data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection));
|
||||
|
||||
if (!isset($data['tables'][$useTable])) {
|
||||
$this->err('Could not find your selected table ' . $useTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
$tableInfo = $data['tables'][$useTable];
|
||||
if (is_null($modelImport)) {
|
||||
$schema = $this->_generateSchema($tableInfo);
|
||||
}
|
||||
|
||||
if (!isset($importOptions['records']) && !isset($importOptions['fromTable'])) {
|
||||
$recordCount = 1;
|
||||
if (isset($this->params['count'])) {
|
||||
$recordCount = $this->params['count'];
|
||||
}
|
||||
$records = $this->_makeRecordString($this->_generateRecords($tableInfo, $recordCount));
|
||||
}
|
||||
if (isset($this->params['records']) || isset($importOptions['fromTable'])) {
|
||||
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
|
||||
}
|
||||
$out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import', 'fields'));
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the fixture file, and write to disk
|
||||
*
|
||||
* @param string $model name of the model being generated
|
||||
* @param string $fixture Contents of the fixture file.
|
||||
* @return string Content saved into fixture file.
|
||||
* @access public
|
||||
*/
|
||||
function generateFixtureFile($model, $otherVars) {
|
||||
$defaults = array('table' => null, 'schema' => null, 'records' => null, 'import' => null, 'fields' => null);
|
||||
$vars = array_merge($defaults, $otherVars);
|
||||
|
||||
$path = $this->getPath();
|
||||
$filename = Inflector::underscore($model) . '_fixture.php';
|
||||
|
||||
$this->Template->set('model', $model);
|
||||
$this->Template->set($vars);
|
||||
$content = $this->Template->generate('classes', 'fixture');
|
||||
|
||||
$this->out("\nBaking test fixture for $model...");
|
||||
$this->createFile($path . $filename, $content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the fixtures.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function getPath() {
|
||||
$path = $this->path;
|
||||
if (isset($this->plugin)) {
|
||||
$path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'fixtures' . DS;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a string representation of a schema.
|
||||
*
|
||||
* @param array $table Table schema array
|
||||
* @return string fields definitions
|
||||
* @access protected
|
||||
*/
|
||||
function _generateSchema($tableInfo) {
|
||||
$schema = $this->_Schema->generateTable('f', $tableInfo);
|
||||
return substr($schema, 10, -2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate String representation of Records
|
||||
*
|
||||
* @param array $table Table schema array
|
||||
* @return array Array of records to use in the fixture.
|
||||
* @access protected
|
||||
*/
|
||||
function _generateRecords($tableInfo, $recordCount = 1) {
|
||||
$records = array();
|
||||
for ($i = 0; $i < $recordCount; $i++) {
|
||||
$record = array();
|
||||
foreach ($tableInfo as $field => $fieldInfo) {
|
||||
if (empty($fieldInfo['type'])) {
|
||||
continue;
|
||||
}
|
||||
switch ($fieldInfo['type']) {
|
||||
case 'integer':
|
||||
case 'float':
|
||||
$insert = $i + 1;
|
||||
break;
|
||||
case 'string':
|
||||
case 'binary':
|
||||
$isPrimaryUuid = (
|
||||
isset($fieldInfo['key']) && strtolower($fieldInfo['key']) == 'primary' &&
|
||||
isset($fieldInfo['length']) && $fieldInfo['length'] == 36
|
||||
);
|
||||
if ($isPrimaryUuid) {
|
||||
$insert = String::uuid();
|
||||
} else {
|
||||
$insert = "Lorem ipsum dolor sit amet";
|
||||
if (!empty($fieldInfo['length'])) {
|
||||
$insert = substr($insert, 0, (int)$fieldInfo['length'] - 2);
|
||||
}
|
||||
}
|
||||
$insert = "'$insert'";
|
||||
break;
|
||||
case 'timestamp':
|
||||
$ts = time();
|
||||
$insert = "'$ts'";
|
||||
break;
|
||||
case 'datetime':
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$insert = "'$ts'";
|
||||
break;
|
||||
case 'date':
|
||||
$ts = date('Y-m-d');
|
||||
$insert = "'$ts'";
|
||||
break;
|
||||
case 'time':
|
||||
$ts = date('H:i:s');
|
||||
$insert = "'$ts'";
|
||||
break;
|
||||
case 'boolean':
|
||||
$insert = 1;
|
||||
break;
|
||||
case 'text':
|
||||
$insert = "'Lorem ipsum dolor sit amet, aliquet feugiat.";
|
||||
$insert .= " Convallis morbi fringilla gravida,";
|
||||
$insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin";
|
||||
$insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla";
|
||||
$insert .= " vestibulum massa neque ut et, id hendrerit sit,";
|
||||
$insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
|
||||
$insert .= " duis vestibulum nunc mattis convallis.'";
|
||||
break;
|
||||
}
|
||||
$record[$field] = $insert;
|
||||
}
|
||||
$records[] = $record;
|
||||
}
|
||||
return $records;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a $records array into a a string.
|
||||
*
|
||||
* @param array $records Array of records to be converted to string
|
||||
* @return string A string value of the $records array.
|
||||
* @access protected
|
||||
*/
|
||||
function _makeRecordString($records) {
|
||||
$out = "array(\n";
|
||||
foreach ($records as $record) {
|
||||
$values = array();
|
||||
foreach ($record as $field => $value) {
|
||||
$values[] = "\t\t\t'$field' => $value";
|
||||
}
|
||||
$out .= "\t\tarray(\n";
|
||||
$out .= implode(",\n", $values);
|
||||
$out .= "\n\t\t),\n";
|
||||
}
|
||||
$out .= "\t)";
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact with the user to get a custom SQL condition and use that to extract data
|
||||
* to build a fixture.
|
||||
*
|
||||
* @param string $modelName name of the model to take records from.
|
||||
* @param string $useTable Name of table to use.
|
||||
* @return array Array of records.
|
||||
* @access protected
|
||||
*/
|
||||
function _getRecordsFromTable($modelName, $useTable = null) {
|
||||
if ($this->interactive) {
|
||||
$condition = null;
|
||||
$prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10", true);
|
||||
while (!$condition) {
|
||||
$condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10');
|
||||
}
|
||||
} else {
|
||||
$condition = 'WHERE 1=1 LIMIT ' . (isset($this->params['count']) ? $this->params['count'] : 10);
|
||||
}
|
||||
App::import('Model', 'Model', false);
|
||||
$modelObject =& new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
|
||||
$records = $modelObject->find('all', array(
|
||||
'conditions' => $condition,
|
||||
'recursive' => -1
|
||||
));
|
||||
$db =& ConnectionManager::getDataSource($modelObject->useDbConfig);
|
||||
$schema = $modelObject->schema(true);
|
||||
$out = array();
|
||||
foreach ($records as $record) {
|
||||
$row = array();
|
||||
foreach ($record[$modelObject->alias] as $field => $value) {
|
||||
$row[$field] = $db->value($value, $schema[$field]['type']);
|
||||
}
|
||||
$out[] = $row;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays help contents
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->hr();
|
||||
$this->out("Usage: cake bake fixture <arg1> <params>");
|
||||
$this->hr();
|
||||
$this->out('Arguments:');
|
||||
$this->out();
|
||||
$this->out("<name>");
|
||||
$this->out("\tName of the fixture to bake. Can use Plugin.name");
|
||||
$this->out("\tas a shortcut for plugin baking.");
|
||||
$this->out();
|
||||
$this->out('Commands:');
|
||||
$this->out("\nfixture <name>\n\tbakes fixture with specified name.");
|
||||
$this->out("\nfixture all\n\tbakes all fixtures.");
|
||||
$this->out();
|
||||
$this->out('Parameters:');
|
||||
$this->out("\t-count When using generated data, the number of records to include in the fixture(s).");
|
||||
$this->out("\t-connection Which database configuration to use for baking.");
|
||||
$this->out("\t-plugin CamelCased name of plugin to bake fixtures for.");
|
||||
$this->out("\t-records Used with -count and <name>/all commands to pull [n] records from the live tables");
|
||||
$this->out("\t Where [n] is either -count or the default of 10.");
|
||||
$this->out();
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
930
php-practice/web-cake/html/cake/console/libs/tasks/model.php
Normal file
930
php-practice/web-cake/html/cake/console/libs/tasks/model.php
Normal file
@@ -0,0 +1,930 @@
|
||||
<?php
|
||||
/**
|
||||
* The ModelTask handles creating and updating models files.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
||||
|
||||
/**
|
||||
* Task class for creating and updating model files.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class ModelTask extends BakeTask {
|
||||
|
||||
/**
|
||||
* path to MODELS directory
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $path = MODELS;
|
||||
|
||||
/**
|
||||
* tasks
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('DbConfig', 'Fixture', 'Test', 'Template');
|
||||
|
||||
/**
|
||||
* Tables to skip when running all()
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $skipTables = array('i18n');
|
||||
|
||||
/**
|
||||
* Holds tables found on connection.
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_tables = array();
|
||||
|
||||
/**
|
||||
* Holds validation method map.
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_validations = array();
|
||||
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function execute() {
|
||||
App::import('Model', 'Model', false);
|
||||
|
||||
if (empty($this->args)) {
|
||||
$this->__interactive();
|
||||
}
|
||||
|
||||
if (!empty($this->args[0])) {
|
||||
$this->interactive = false;
|
||||
if (!isset($this->connection)) {
|
||||
$this->connection = 'default';
|
||||
}
|
||||
if (strtolower($this->args[0]) == 'all') {
|
||||
return $this->all();
|
||||
}
|
||||
$model = $this->_modelName($this->args[0]);
|
||||
$object = $this->_getModelObject($model);
|
||||
if ($this->bake($object, false)) {
|
||||
if ($this->_checkUnitTest()) {
|
||||
$this->bakeFixture($model);
|
||||
$this->bakeTest($model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake all models at once.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function all() {
|
||||
$this->listAll($this->connection, false);
|
||||
$unitTestExists = $this->_checkUnitTest();
|
||||
foreach ($this->_tables as $table) {
|
||||
if (in_array($table, $this->skipTables)) {
|
||||
continue;
|
||||
}
|
||||
$modelClass = Inflector::classify($table);
|
||||
$this->out(sprintf(__('Baking %s', true), $modelClass));
|
||||
$object = $this->_getModelObject($modelClass);
|
||||
if ($this->bake($object, false) && $unitTestExists) {
|
||||
$this->bakeFixture($modelClass);
|
||||
$this->bakeTest($modelClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a model object for a class name.
|
||||
*
|
||||
* @param string $className Name of class you want model to be.
|
||||
* @return object Model instance
|
||||
*/
|
||||
function &_getModelObject($className, $table = null) {
|
||||
if (!$table) {
|
||||
$table = Inflector::tableize($className);
|
||||
}
|
||||
$object =& new Model(array('name' => $className, 'table' => $table, 'ds' => $this->connection));
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a key value list of options and a prompt.
|
||||
*
|
||||
* @param array $options Array of options to use for the selections. indexes must start at 0
|
||||
* @param string $prompt Prompt to use for options list.
|
||||
* @param integer $default The default option for the given prompt.
|
||||
* @return result of user choice.
|
||||
*/
|
||||
function inOptions($options, $prompt = null, $default = null) {
|
||||
$valid = false;
|
||||
$max = count($options);
|
||||
while (!$valid) {
|
||||
foreach ($options as $i => $option) {
|
||||
$this->out($i + 1 .'. ' . $option);
|
||||
}
|
||||
if (empty($prompt)) {
|
||||
$prompt = __('Make a selection from the choices above', true);
|
||||
}
|
||||
$choice = $this->in($prompt, null, $default);
|
||||
if (intval($choice) > 0 && intval($choice) <= $max) {
|
||||
$valid = true;
|
||||
}
|
||||
}
|
||||
return $choice - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles interactive baking
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __interactive() {
|
||||
$this->hr();
|
||||
$this->out(sprintf("Bake Model\nPath: %s", $this->path));
|
||||
$this->hr();
|
||||
$this->interactive = true;
|
||||
|
||||
$primaryKey = 'id';
|
||||
$validate = $associations = array();
|
||||
|
||||
if (empty($this->connection)) {
|
||||
$this->connection = $this->DbConfig->getConfig();
|
||||
}
|
||||
$currentModelName = $this->getName();
|
||||
$useTable = $this->getTable($currentModelName);
|
||||
$db =& ConnectionManager::getDataSource($this->connection);
|
||||
$fullTableName = $db->fullTableName($useTable);
|
||||
|
||||
if (in_array($useTable, $this->_tables)) {
|
||||
$tempModel = new Model(array('name' => $currentModelName, 'table' => $useTable, 'ds' => $this->connection));
|
||||
$fields = $tempModel->schema(true);
|
||||
if (!array_key_exists('id', $fields)) {
|
||||
$primaryKey = $this->findPrimaryKey($fields);
|
||||
}
|
||||
} else {
|
||||
$this->err(sprintf(__('Table %s does not exist, cannot bake a model without a table.', true), $useTable));
|
||||
$this->_stop();
|
||||
return false;
|
||||
}
|
||||
$displayField = $tempModel->hasField(array('name', 'title'));
|
||||
if (!$displayField) {
|
||||
$displayField = $this->findDisplayField($tempModel->schema());
|
||||
}
|
||||
|
||||
$prompt = __("Would you like to supply validation criteria \nfor the fields in your model?", true);
|
||||
$wannaDoValidation = $this->in($prompt, array('y','n'), 'y');
|
||||
if (array_search($useTable, $this->_tables) !== false && strtolower($wannaDoValidation) == 'y') {
|
||||
$validate = $this->doValidation($tempModel);
|
||||
}
|
||||
|
||||
$prompt = __("Would you like to define model associations\n(hasMany, hasOne, belongsTo, etc.)?", true);
|
||||
$wannaDoAssoc = $this->in($prompt, array('y','n'), 'y');
|
||||
if (strtolower($wannaDoAssoc) == 'y') {
|
||||
$associations = $this->doAssociations($tempModel);
|
||||
}
|
||||
|
||||
$this->out();
|
||||
$this->hr();
|
||||
$this->out(__('The following Model will be created:', true));
|
||||
$this->hr();
|
||||
$this->out("Name: " . $currentModelName);
|
||||
|
||||
if ($this->connection !== 'default') {
|
||||
$this->out(sprintf(__("DB Config: %s", true), $this->connection));
|
||||
}
|
||||
if ($fullTableName !== Inflector::tableize($currentModelName)) {
|
||||
$this->out(sprintf(__("DB Table: %s", true), $fullTableName));
|
||||
}
|
||||
if ($primaryKey != 'id') {
|
||||
$this->out(sprintf(__("Primary Key: %s", true), $primaryKey));
|
||||
}
|
||||
if (!empty($validate)) {
|
||||
$this->out(sprintf(__("Validation: %s", true), print_r($validate, true)));
|
||||
}
|
||||
if (!empty($associations)) {
|
||||
$this->out(__("Associations:", true));
|
||||
$assocKeys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
foreach ($assocKeys as $assocKey) {
|
||||
$this->_printAssociation($currentModelName, $assocKey, $associations);
|
||||
}
|
||||
}
|
||||
|
||||
$this->hr();
|
||||
$looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');
|
||||
|
||||
if (strtolower($looksGood) == 'y') {
|
||||
$vars = compact('associations', 'validate', 'primaryKey', 'useTable', 'displayField');
|
||||
$vars['useDbConfig'] = $this->connection;
|
||||
if ($this->bake($currentModelName, $vars)) {
|
||||
if ($this->_checkUnitTest()) {
|
||||
$this->bakeFixture($currentModelName, $useTable);
|
||||
$this->bakeTest($currentModelName, $useTable, $associations);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print out all the associations of a particular type
|
||||
*
|
||||
* @param string $modelName Name of the model relations belong to.
|
||||
* @param string $type Name of association you want to see. i.e. 'belongsTo'
|
||||
* @param string $associations Collection of associations.
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
function _printAssociation($modelName, $type, $associations) {
|
||||
if (!empty($associations[$type])) {
|
||||
for ($i = 0; $i < count($associations[$type]); $i++) {
|
||||
$out = "\t" . $modelName . ' ' . $type . ' ' . $associations[$type][$i]['alias'];
|
||||
$this->out($out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a primary Key in a list of fields.
|
||||
*
|
||||
* @param array $fields Array of fields that might have a primary key.
|
||||
* @return string Name of field that is a primary key.
|
||||
* @access public
|
||||
*/
|
||||
function findPrimaryKey($fields) {
|
||||
foreach ($fields as $name => $field) {
|
||||
if (isset($field['key']) && $field['key'] == 'primary') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this->in(__('What is the primaryKey?', true), null, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* interact with the user to find the displayField value for a model.
|
||||
*
|
||||
* @param array $fields Array of fields to look for and choose as a displayField
|
||||
* @return mixed Name of field to use for displayField or false if the user declines to choose
|
||||
*/
|
||||
function findDisplayField($fields) {
|
||||
$fieldNames = array_keys($fields);
|
||||
$prompt = __("A displayField could not be automatically detected\nwould you like to choose one?", true);
|
||||
$continue = $this->in($prompt, array('y', 'n'));
|
||||
if (strtolower($continue) == 'n') {
|
||||
return false;
|
||||
}
|
||||
$prompt = __('Choose a field from the options above:', true);
|
||||
$choice = $this->inOptions($fieldNames, $prompt);
|
||||
return $fieldNames[$choice];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles Generation and user interaction for creating validation.
|
||||
*
|
||||
* @param object $model Model to have validations generated for.
|
||||
* @return array $validate Array of user selected validations.
|
||||
* @access public
|
||||
*/
|
||||
function doValidation(&$model) {
|
||||
if (!is_object($model)) {
|
||||
return false;
|
||||
}
|
||||
$fields = $model->schema();
|
||||
|
||||
if (empty($fields)) {
|
||||
return false;
|
||||
}
|
||||
$validate = array();
|
||||
$this->initValidations();
|
||||
foreach ($fields as $fieldName => $field) {
|
||||
$validation = $this->fieldValidation($fieldName, $field, $model->primaryKey);
|
||||
if (!empty($validation)) {
|
||||
$validate[$fieldName] = $validation;
|
||||
}
|
||||
}
|
||||
return $validate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the _validations array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function initValidations() {
|
||||
$options = $choices = array();
|
||||
if (class_exists('Validation')) {
|
||||
$parent = get_class_methods(get_parent_class('Validation'));
|
||||
$options = get_class_methods('Validation');
|
||||
$options = array_diff($options, $parent);
|
||||
}
|
||||
sort($options);
|
||||
$default = 1;
|
||||
foreach ($options as $key => $option) {
|
||||
if ($option{0} != '_' && strtolower($option) != 'getinstance') {
|
||||
$choices[$default] = strtolower($option);
|
||||
$default++;
|
||||
}
|
||||
}
|
||||
$this->_validations = $choices;
|
||||
return $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does individual field validation handling.
|
||||
*
|
||||
* @param string $fieldName Name of field to be validated.
|
||||
* @param array $metaData metadata for field
|
||||
* @return array Array of validation for the field.
|
||||
*/
|
||||
function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
|
||||
$defaultChoice = count($this->_validations);
|
||||
$validate = $alreadyChosen = array();
|
||||
|
||||
$anotherValidator = 'y';
|
||||
while ($anotherValidator == 'y') {
|
||||
if ($this->interactive) {
|
||||
$this->out();
|
||||
$this->out(sprintf(__('Field: %s', true), $fieldName));
|
||||
$this->out(sprintf(__('Type: %s', true), $metaData['type']));
|
||||
$this->hr();
|
||||
$this->out(__('Please select one of the following validation options:', true));
|
||||
$this->hr();
|
||||
}
|
||||
|
||||
$prompt = '';
|
||||
for ($i = 1; $i < $defaultChoice; $i++) {
|
||||
$prompt .= $i . ' - ' . $this->_validations[$i] . "\n";
|
||||
}
|
||||
$prompt .= sprintf(__("%s - Do not do any validation on this field.\n", true), $defaultChoice);
|
||||
$prompt .= __("... or enter in a valid regex validation string.\n", true);
|
||||
|
||||
$methods = array_flip($this->_validations);
|
||||
$guess = $defaultChoice;
|
||||
if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) {
|
||||
if ($fieldName == 'email') {
|
||||
$guess = $methods['email'];
|
||||
} elseif ($metaData['type'] == 'string') {
|
||||
$guess = $methods['notempty'];
|
||||
} elseif ($metaData['type'] == 'integer') {
|
||||
$guess = $methods['numeric'];
|
||||
} elseif ($metaData['type'] == 'boolean') {
|
||||
$guess = $methods['boolean'];
|
||||
} elseif ($metaData['type'] == 'date') {
|
||||
$guess = $methods['date'];
|
||||
} elseif ($metaData['type'] == 'time') {
|
||||
$guess = $methods['time'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->interactive === true) {
|
||||
$choice = $this->in($prompt, null, $guess);
|
||||
if (in_array($choice, $alreadyChosen)) {
|
||||
$this->out(__("You have already chosen that validation rule,\nplease choose again", true));
|
||||
continue;
|
||||
}
|
||||
if (!isset($this->_validations[$choice]) && is_numeric($choice)) {
|
||||
$this->out(__('Please make a valid selection.', true));
|
||||
continue;
|
||||
}
|
||||
$alreadyChosen[] = $choice;
|
||||
} else {
|
||||
$choice = $guess;
|
||||
}
|
||||
|
||||
if (isset($this->_validations[$choice])) {
|
||||
$validatorName = $this->_validations[$choice];
|
||||
} else {
|
||||
$validatorName = Inflector::slug($choice);
|
||||
}
|
||||
|
||||
if ($choice != $defaultChoice) {
|
||||
if (is_numeric($choice) && isset($this->_validations[$choice])) {
|
||||
$validate[$validatorName] = $this->_validations[$choice];
|
||||
} else {
|
||||
$validate[$validatorName] = $choice;
|
||||
}
|
||||
}
|
||||
if ($this->interactive == true && $choice != $defaultChoice) {
|
||||
$anotherValidator = $this->in(__('Would you like to add another validation rule?', true), array('y', 'n'), 'n');
|
||||
} else {
|
||||
$anotherValidator = 'n';
|
||||
}
|
||||
}
|
||||
return $validate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles associations
|
||||
*
|
||||
* @param object $model
|
||||
* @return array $assocaitons
|
||||
* @access public
|
||||
*/
|
||||
function doAssociations(&$model) {
|
||||
if (!is_object($model)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->interactive === true) {
|
||||
$this->out(__('One moment while the associations are detected.', true));
|
||||
}
|
||||
|
||||
$fields = $model->schema(true);
|
||||
if (empty($fields)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($this->_tables)) {
|
||||
$this->_tables = $this->getAllTables();
|
||||
}
|
||||
|
||||
$associations = array(
|
||||
'belongsTo' => array(), 'hasMany' => array(), 'hasOne'=> array(), 'hasAndBelongsToMany' => array()
|
||||
);
|
||||
$possibleKeys = array();
|
||||
|
||||
$associations = $this->findBelongsTo($model, $associations);
|
||||
$associations = $this->findHasOneAndMany($model, $associations);
|
||||
$associations = $this->findHasAndBelongsToMany($model, $associations);
|
||||
|
||||
if ($this->interactive !== true) {
|
||||
unset($associations['hasOne']);
|
||||
}
|
||||
|
||||
if ($this->interactive === true) {
|
||||
$this->hr();
|
||||
if (empty($associations)) {
|
||||
$this->out(__('None found.', true));
|
||||
} else {
|
||||
$this->out(__('Please confirm the following associations:', true));
|
||||
$this->hr();
|
||||
$associations = $this->confirmAssociations($model, $associations);
|
||||
}
|
||||
$associations = $this->doMoreAssociations($model, $associations);
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find belongsTo relations and add them to the associations list.
|
||||
*
|
||||
* @param object $model Model instance of model being generated.
|
||||
* @param array $associations Array of inprogress associations
|
||||
* @return array $associations with belongsTo added in.
|
||||
*/
|
||||
function findBelongsTo(&$model, $associations) {
|
||||
$fields = $model->schema(true);
|
||||
foreach ($fields as $fieldName => $field) {
|
||||
$offset = strpos($fieldName, '_id');
|
||||
if ($fieldName != $model->primaryKey && $fieldName != 'parent_id' && $offset !== false) {
|
||||
$tmpModelName = $this->_modelNameFromKey($fieldName);
|
||||
$associations['belongsTo'][] = array(
|
||||
'alias' => $tmpModelName,
|
||||
'className' => $tmpModelName,
|
||||
'foreignKey' => $fieldName,
|
||||
);
|
||||
} elseif ($fieldName == 'parent_id') {
|
||||
$associations['belongsTo'][] = array(
|
||||
'alias' => 'Parent' . $model->name,
|
||||
'className' => $model->name,
|
||||
'foreignKey' => $fieldName,
|
||||
);
|
||||
}
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the hasOne and HasMany relations and add them to associations list
|
||||
*
|
||||
* @param object $model Model instance being generated
|
||||
* @param array $associations Array of inprogress associations
|
||||
* @return array $associations with hasOne and hasMany added in.
|
||||
*/
|
||||
function findHasOneAndMany(&$model, $associations) {
|
||||
$foreignKey = $this->_modelKey($model->name);
|
||||
foreach ($this->_tables as $otherTable) {
|
||||
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
|
||||
$modelFieldsTemp = $tempOtherModel->schema(true);
|
||||
|
||||
$pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/';
|
||||
$possibleJoinTable = preg_match($pattern , $otherTable);
|
||||
if ($possibleJoinTable == true) {
|
||||
continue;
|
||||
}
|
||||
foreach ($modelFieldsTemp as $fieldName => $field) {
|
||||
$assoc = false;
|
||||
if ($fieldName != $model->primaryKey && $fieldName == $foreignKey) {
|
||||
$assoc = array(
|
||||
'alias' => $tempOtherModel->name,
|
||||
'className' => $tempOtherModel->name,
|
||||
'foreignKey' => $fieldName
|
||||
);
|
||||
} elseif ($otherTable == $model->table && $fieldName == 'parent_id') {
|
||||
$assoc = array(
|
||||
'alias' => 'Child' . $model->name,
|
||||
'className' => $model->name,
|
||||
'foreignKey' => $fieldName
|
||||
);
|
||||
}
|
||||
if ($assoc) {
|
||||
$associations['hasOne'][] = $assoc;
|
||||
$associations['hasMany'][] = $assoc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the hasAndBelongsToMany relations and add them to associations list
|
||||
*
|
||||
* @param object $model Model instance being generated
|
||||
* @param array $associations Array of inprogress associations
|
||||
* @return array $associations with hasAndBelongsToMany added in.
|
||||
*/
|
||||
function findHasAndBelongsToMany(&$model, $associations) {
|
||||
$foreignKey = $this->_modelKey($model->name);
|
||||
foreach ($this->_tables as $otherTable) {
|
||||
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
|
||||
$modelFieldsTemp = $tempOtherModel->schema(true);
|
||||
|
||||
$offset = strpos($otherTable, $model->table . '_');
|
||||
$otherOffset = strpos($otherTable, '_' . $model->table);
|
||||
|
||||
if ($offset !== false) {
|
||||
$offset = strlen($model->table . '_');
|
||||
$habtmName = $this->_modelName(substr($otherTable, $offset));
|
||||
$associations['hasAndBelongsToMany'][] = array(
|
||||
'alias' => $habtmName,
|
||||
'className' => $habtmName,
|
||||
'foreignKey' => $foreignKey,
|
||||
'associationForeignKey' => $this->_modelKey($habtmName),
|
||||
'joinTable' => $otherTable
|
||||
);
|
||||
} elseif ($otherOffset !== false) {
|
||||
$habtmName = $this->_modelName(substr($otherTable, 0, $otherOffset));
|
||||
$associations['hasAndBelongsToMany'][] = array(
|
||||
'alias' => $habtmName,
|
||||
'className' => $habtmName,
|
||||
'foreignKey' => $foreignKey,
|
||||
'associationForeignKey' => $this->_modelKey($habtmName),
|
||||
'joinTable' => $otherTable
|
||||
);
|
||||
}
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact with the user and confirm associations.
|
||||
*
|
||||
* @param array $model Temporary Model instance.
|
||||
* @param array $associations Array of associations to be confirmed.
|
||||
* @return array Array of confirmed associations
|
||||
*/
|
||||
function confirmAssociations(&$model, $associations) {
|
||||
foreach ($associations as $type => $settings) {
|
||||
if (!empty($associations[$type])) {
|
||||
$count = count($associations[$type]);
|
||||
$response = 'y';
|
||||
foreach ($associations[$type] as $i => $assoc) {
|
||||
$prompt = "{$model->name} {$type} {$assoc['alias']}?";
|
||||
$response = $this->in($prompt, array('y','n'), 'y');
|
||||
|
||||
if ('n' == strtolower($response)) {
|
||||
unset($associations[$type][$i]);
|
||||
} elseif ($type == 'hasMany') {
|
||||
unset($associations['hasOne'][$i]);
|
||||
}
|
||||
}
|
||||
$associations[$type] = array_merge($associations[$type]);
|
||||
}
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact with the user and generate additional non-conventional associations
|
||||
*
|
||||
* @param object $model Temporary model instance
|
||||
* @param array $associations Array of associations.
|
||||
* @return array Array of associations.
|
||||
*/
|
||||
function doMoreAssociations($model, $associations) {
|
||||
$prompt = __('Would you like to define some additional model associations?', true);
|
||||
$wannaDoMoreAssoc = $this->in($prompt, array('y','n'), 'n');
|
||||
$possibleKeys = $this->_generatePossibleKeys();
|
||||
while (strtolower($wannaDoMoreAssoc) == 'y') {
|
||||
$assocs = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
$this->out(__('What is the association type?', true));
|
||||
$assocType = intval($this->inOptions($assocs, __('Enter a number',true)));
|
||||
|
||||
$this->out(__("For the following options be very careful to match your setup exactly.\nAny spelling mistakes will cause errors.", true));
|
||||
$this->hr();
|
||||
|
||||
$alias = $this->in(__('What is the alias for this association?', true));
|
||||
$className = $this->in(sprintf(__('What className will %s use?', true), $alias), null, $alias );
|
||||
$suggestedForeignKey = null;
|
||||
|
||||
if ($assocType == 0) {
|
||||
$showKeys = $possibleKeys[$model->table];
|
||||
$suggestedForeignKey = $this->_modelKey($alias);
|
||||
} else {
|
||||
$otherTable = Inflector::tableize($className);
|
||||
if (in_array($otherTable, $this->_tables)) {
|
||||
if ($assocType < 3) {
|
||||
$showKeys = $possibleKeys[$otherTable];
|
||||
} else {
|
||||
$showKeys = null;
|
||||
}
|
||||
} else {
|
||||
$otherTable = $this->in(__('What is the table for this model?', true));
|
||||
$showKeys = $possibleKeys[$otherTable];
|
||||
}
|
||||
$suggestedForeignKey = $this->_modelKey($model->name);
|
||||
}
|
||||
if (!empty($showKeys)) {
|
||||
$this->out(__('A helpful List of possible keys', true));
|
||||
$foreignKey = $this->inOptions($showKeys, __('What is the foreignKey?', true));
|
||||
$foreignKey = $showKeys[intval($foreignKey)];
|
||||
}
|
||||
if (!isset($foreignKey)) {
|
||||
$foreignKey = $this->in(__('What is the foreignKey? Specify your own.', true), null, $suggestedForeignKey);
|
||||
}
|
||||
if ($assocType == 3) {
|
||||
$associationForeignKey = $this->in(__('What is the associationForeignKey?', true), null, $this->_modelKey($model->name));
|
||||
$joinTable = $this->in(__('What is the joinTable?', true));
|
||||
}
|
||||
$associations[$assocs[$assocType]] = array_values((array)$associations[$assocs[$assocType]]);
|
||||
$count = count($associations[$assocs[$assocType]]);
|
||||
$i = ($count > 0) ? $count : 0;
|
||||
$associations[$assocs[$assocType]][$i]['alias'] = $alias;
|
||||
$associations[$assocs[$assocType]][$i]['className'] = $className;
|
||||
$associations[$assocs[$assocType]][$i]['foreignKey'] = $foreignKey;
|
||||
if ($assocType == 3) {
|
||||
$associations[$assocs[$assocType]][$i]['associationForeignKey'] = $associationForeignKey;
|
||||
$associations[$assocs[$assocType]][$i]['joinTable'] = $joinTable;
|
||||
}
|
||||
$wannaDoMoreAssoc = $this->in(__('Define another association?', true), array('y','n'), 'y');
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all possible keys to use on custom associations.
|
||||
*
|
||||
* @return array array of tables and possible keys
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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 unit test file
|
||||
*
|
||||
* @param string $className Model class name
|
||||
* @access private
|
||||
*/
|
||||
function bakeTest($className) {
|
||||
$this->Test->interactive = $this->interactive;
|
||||
$this->Test->plugin = $this->plugin;
|
||||
$this->Test->connection = $this->connection;
|
||||
return $this->Test->bake('Model', $className);
|
||||
}
|
||||
|
||||
/**
|
||||
* outputs the a list of possible models or controllers from database
|
||||
*
|
||||
* @param string $useDbConfig Database configuration name
|
||||
* @access public
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the user to specify the model he wants to bake, and returns the selected model name.
|
||||
*
|
||||
* @return string the model name
|
||||
* @access public
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays help contents
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->hr();
|
||||
$this->out("Usage: cake bake model <arg1>");
|
||||
$this->hr();
|
||||
$this->out('Arguments:');
|
||||
$this->out();
|
||||
$this->out("<name>");
|
||||
$this->out("\tName of the model to bake. Can use Plugin.name");
|
||||
$this->out("\tas a shortcut for plugin baking.");
|
||||
$this->out();
|
||||
$this->out('Commands:');
|
||||
$this->out();
|
||||
$this->out("model");
|
||||
$this->out("\tbakes model in interactive mode.");
|
||||
$this->out();
|
||||
$this->out("model <name>");
|
||||
$this->out("\tbakes model file with no associations or validation");
|
||||
$this->out();
|
||||
$this->out("model all");
|
||||
$this->out("\tbakes all model files with associations and validation");
|
||||
$this->out();
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
247
php-practice/web-cake/html/cake/console/libs/tasks/plugin.php
Normal file
247
php-practice/web-cake/html/cake/console/libs/tasks/plugin.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
/**
|
||||
* The Plugin Task handles creating an empty plugin, ready to be used
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Task class for creating a plugin
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class PluginTask extends Shell {
|
||||
|
||||
/**
|
||||
* Tasks
|
||||
*
|
||||
*/
|
||||
var $tasks = array('Model', 'Controller', 'View');
|
||||
|
||||
/**
|
||||
* path to CONTROLLERS directory
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $path = null;
|
||||
|
||||
/**
|
||||
* initialize
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function initialize() {
|
||||
$this->path = APP . 'plugins' . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactive interface
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake the plugin, create directories and files
|
||||
*
|
||||
* @params $plugin name of the plugin in CamelCased format
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* find and change $this->path to the user selection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
* Help
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->hr();
|
||||
$this->out("Usage: cake bake plugin <arg1> <arg2>...");
|
||||
$this->hr();
|
||||
$this->out('Commands:');
|
||||
$this->out();
|
||||
$this->out("plugin <name>");
|
||||
$this->out("\tbakes plugin directory structure");
|
||||
$this->out();
|
||||
$this->out("plugin <name> model");
|
||||
$this->out("\tbakes model. Run 'cake bake model help' for more info.");
|
||||
$this->out();
|
||||
$this->out("plugin <name> controller");
|
||||
$this->out("\tbakes controller. Run 'cake bake controller help' for more info.");
|
||||
$this->out();
|
||||
$this->out("plugin <name> view");
|
||||
$this->out("\tbakes view. Run 'cake bake view help' for more info.");
|
||||
$this->out();
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
371
php-practice/web-cake/html/cake/console/libs/tasks/project.php
Normal file
371
php-practice/web-cake/html/cake/console/libs/tasks/project.php
Normal file
@@ -0,0 +1,371 @@
|
||||
<?php
|
||||
/**
|
||||
* The Project Task handles creating the base application
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.bake
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
/**
|
||||
* Task class for creating new project apps and plugins
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class ProjectTask extends Shell {
|
||||
|
||||
/**
|
||||
* configs path (used in testing).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $configPath = null;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a file with a default home page to the project.
|
||||
*
|
||||
* @param string $dir Path to project
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and writes 'Security.salt'
|
||||
*
|
||||
* @param string $path Project path
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
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.cipherSeed'
|
||||
*
|
||||
* @param string $path Project path
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
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 CAKE_CORE_INCLUDE_PATH
|
||||
*
|
||||
* @param string $path Project path
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables Configure::read('Routing.prefixes') in /app/config/core.php
|
||||
*
|
||||
* @param string $name Name to use as admin routing
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for Configure::read('Routing.prefixes') and forces user to input it if not enabled
|
||||
*
|
||||
* @return string Admin route to use
|
||||
* @access public
|
||||
*/
|
||||
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 '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Help
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->hr();
|
||||
$this->out("Usage: cake bake project <arg1>");
|
||||
$this->hr();
|
||||
$this->out('Commands:');
|
||||
$this->out();
|
||||
$this->out("project <name>");
|
||||
$this->out("\tbakes app directory structure.");
|
||||
$this->out("\tif <name> begins with '/' path is absolute.");
|
||||
$this->out();
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
}
|
209
php-practice/web-cake/html/cake/console/libs/tasks/template.php
Normal file
209
php-practice/web-cake/html/cake/console/libs/tasks/template.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* Template Task can generate templated output Used in other Tasks
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
class TemplateTask extends Shell {
|
||||
|
||||
/**
|
||||
* variables to add to template scope
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $templateVars = array();
|
||||
|
||||
/**
|
||||
* Paths to look for templates on.
|
||||
* Contains a list of $theme => $path
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $templatePaths = array();
|
||||
|
||||
/**
|
||||
* Initialize callback. Setup paths for the template task.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function initialize() {
|
||||
$this->templatePaths = $this->_findThemes();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
function _findThemes() {
|
||||
$paths = App::path('shells');
|
||||
$core = array_pop($paths);
|
||||
$separator = DS === '/' ? '/' : '\\\\';
|
||||
$core = preg_replace('#libs' . $separator . '$#', '', $core);
|
||||
$paths[] = $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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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 '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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 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.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
456
php-practice/web-cake/html/cake/console/libs/tasks/test.php
Normal file
456
php-practice/web-cake/html/cake/console/libs/tasks/test.php
Normal file
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
/**
|
||||
* The TestTask handles creating and updating test files.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
||||
|
||||
/**
|
||||
* Task class for creating and updating test files.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class TestTask extends BakeTask {
|
||||
|
||||
/**
|
||||
* path to TESTS directory
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $path = TESTS;
|
||||
|
||||
/**
|
||||
* Tasks used.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('Template');
|
||||
|
||||
/**
|
||||
* class types that methods can be generated for
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $classTypes = array('Model', 'Controller', 'Component', 'Behavior', 'Helper');
|
||||
|
||||
/**
|
||||
* Internal list of fixtures that have been added so far.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
var $_fixtures = array();
|
||||
|
||||
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles interactive baking
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __interactive($type = null) {
|
||||
$this->interactive = true;
|
||||
$this->hr();
|
||||
$this->out(__('Bake Tests', true));
|
||||
$this->out(sprintf(__("Path: %s", true), $this->path));
|
||||
$this->hr();
|
||||
|
||||
if ($type) {
|
||||
$type = Inflector::camelize($type);
|
||||
if (!in_array($type, $this->classTypes)) {
|
||||
$this->error(sprintf('Incorrect type provided. Please choose one of %s', implode(', ', $this->classTypes)));
|
||||
}
|
||||
} else {
|
||||
$type = $this->getObjectType();
|
||||
}
|
||||
$className = $this->getClassName($type);
|
||||
return $this->bake($type, $className);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact with the user and get their chosen type. Can exit the script.
|
||||
*
|
||||
* @return string Users chosen type.
|
||||
* @access public
|
||||
*/
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function getClassName($objectType) {
|
||||
$options = App::objects(strtolower($objectType));
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function typeCanDetectFixtures($type) {
|
||||
$type = strtolower($type);
|
||||
return ($type == 'controller' || $type == 'model');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function isLoadableClass($type, $class) {
|
||||
return App::import($type, $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function getRealClassName($type, $class) {
|
||||
if (strtolower($type) == 'model') {
|
||||
return $class;
|
||||
}
|
||||
return $class . $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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 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
|
||||
*/
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact with the user to get additional fixtures they want to use.
|
||||
*
|
||||
* @return array Array of fixtures the user wants to add.
|
||||
* @access public
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function hasMockClass($type) {
|
||||
$type = strtolower($type);
|
||||
return $type == 'controller';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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';
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help file.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
491
php-practice/web-cake/html/cake/console/libs/tasks/view.php
Normal file
491
php-practice/web-cake/html/cake/console/libs/tasks/view.php
Normal file
@@ -0,0 +1,491 @@
|
||||
<?php
|
||||
/**
|
||||
* The View Tasks handles creating and updating view files.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Controller', 'Controller', false);
|
||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
||||
|
||||
/**
|
||||
* Task class for creating and updating view files.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class ViewTask extends BakeTask {
|
||||
|
||||
/**
|
||||
* Tasks to be loaded by this Task
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('Project', 'Controller', 'DbConfig', 'Template');
|
||||
|
||||
/**
|
||||
* path to VIEWS directory
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $path = VIEWS;
|
||||
|
||||
/**
|
||||
* Name of the controller being used
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $controllerName = null;
|
||||
|
||||
/**
|
||||
* Path to controller to put views
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $controllerPath = null;
|
||||
|
||||
/**
|
||||
* The template file to use
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $template = null;
|
||||
|
||||
/**
|
||||
* Actions to use for scaffolding
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $scaffoldActions = array('index', 'view', 'add', 'edit');
|
||||
|
||||
/**
|
||||
* An array of action names that don't require templates. These
|
||||
* actions will not emit errors when doing bakeActions()
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $noTemplateActions = array('delete');
|
||||
|
||||
/**
|
||||
* Override initialize
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of actions that can / should have views baked for them.
|
||||
*
|
||||
* @return array Array of action names that should be baked
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake All views for All controllers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles interactive baking
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function __interactive() {
|
||||
$this->hr();
|
||||
$this->out(sprintf("Bake View\nPath: %s", $this->path));
|
||||
$this->hr();
|
||||
|
||||
$this->DbConfig->interactive = $this->Controller->interactive = $this->interactive = true;
|
||||
|
||||
if (empty($this->connection)) {
|
||||
$this->connection = $this->DbConfig->getConfig();
|
||||
}
|
||||
|
||||
$this->Controller->connection = $this->connection;
|
||||
$this->controllerName = $this->Controller->getName();
|
||||
|
||||
$this->controllerPath = strtolower(Inflector::underscore($this->controllerName));
|
||||
|
||||
$prompt = sprintf(__("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if it exist.", true), $this->controllerName);
|
||||
$interactive = $this->in($prompt, array('y', 'n'), 'n');
|
||||
|
||||
if (strtolower($interactive) == 'n') {
|
||||
$this->interactive = false;
|
||||
}
|
||||
|
||||
$prompt = __("Would you like to create some CRUD views\n(index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller\nand model classes (including associated models).", true);
|
||||
$wannaDoScaffold = $this->in($prompt, array('y','n'), 'y');
|
||||
|
||||
$wannaDoAdmin = $this->in(__("Would you like to create the views for admin routing?", true), array('y','n'), 'n');
|
||||
|
||||
if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoAdmin) == 'y') {
|
||||
$vars = $this->__loadController();
|
||||
if (strtolower($wannaDoScaffold) == 'y') {
|
||||
$actions = $this->scaffoldActions;
|
||||
$this->bakeActions($actions, $vars);
|
||||
}
|
||||
if (strtolower($wannaDoAdmin) == 'y') {
|
||||
$admin = $this->Project->getPrefix();
|
||||
$regularActions = $this->scaffoldActions;
|
||||
$adminActions = array();
|
||||
foreach ($regularActions as $action) {
|
||||
$adminActions[] = $admin . $action;
|
||||
}
|
||||
$this->bakeActions($adminActions, $vars);
|
||||
}
|
||||
$this->hr();
|
||||
$this->out();
|
||||
$this->out(__("View Scaffolding Complete.\n", true));
|
||||
} else {
|
||||
$this->customAction();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake a view file for each of the supplied actions
|
||||
*
|
||||
* @param array $actions Array of actions to make files for.
|
||||
* @return void
|
||||
*/
|
||||
function bakeActions($actions, $vars) {
|
||||
foreach ($actions as $action) {
|
||||
$content = $this->getContent($action, $vars);
|
||||
$this->bake($action, $content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handle creation of baking a custom action view file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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 . $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);
|
||||
$this->_stop();
|
||||
} else {
|
||||
$this->out(__('Bake Aborted.', true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles and writes bakes the view file.
|
||||
*
|
||||
* @param string $action Action to bake
|
||||
* @param string $content Content to write
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the template name based on the action name
|
||||
*
|
||||
* @param string $action name
|
||||
* @return string template name
|
||||
* @access public
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays help contents
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->hr();
|
||||
$this->out("Usage: cake bake view <arg1> <arg2>...");
|
||||
$this->hr();
|
||||
$this->out('Arguments:');
|
||||
$this->out();
|
||||
$this->out("<controller>");
|
||||
$this->out("\tName of the controller views to bake. Can use Plugin.name");
|
||||
$this->out("\tas a shortcut for plugin baking.");
|
||||
$this->out();
|
||||
$this->out("<action>");
|
||||
$this->out("\tName of the action view to bake");
|
||||
$this->out();
|
||||
$this->out('Commands:');
|
||||
$this->out();
|
||||
$this->out("view <controller>");
|
||||
$this->out("\tWill read the given controller for methods");
|
||||
$this->out("\tand bake corresponding views.");
|
||||
$this->out("\tUsing the -admin flag will only bake views for actions");
|
||||
$this->out("\tthat begin with Routing.admin.");
|
||||
$this->out("\tIf var scaffold is found it will bake the CRUD actions");
|
||||
$this->out("\t(index,view,add,edit)");
|
||||
$this->out();
|
||||
$this->out("view <controller> <action>");
|
||||
$this->out("\tWill bake a template. core templates: (index, add, edit, view)");
|
||||
$this->out();
|
||||
$this->out("view <controller> <template> <alias>");
|
||||
$this->out("\tWill use the template specified");
|
||||
$this->out("\tbut name the file based on the alias");
|
||||
$this->out();
|
||||
$this->out("view all");
|
||||
$this->out("\tBake all CRUD action views for all controllers.");
|
||||
$this->out("\tRequires that models and controllers exist.");
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns associations for controllers models.
|
||||
*
|
||||
* @return array $associations
|
||||
* @access private
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
370
php-practice/web-cake/html/cake/console/libs/testsuite.php
Normal file
370
php-practice/web-cake/html/cake/console/libs/testsuite.php
Normal file
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
/**
|
||||
* Test Suite Shell
|
||||
*
|
||||
* This Shell allows the running of test suites via the cake command line
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.4433
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
class TestSuiteShell extends Shell {
|
||||
|
||||
/**
|
||||
* The test category, "app", "core" or the name of a plugin
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $category = '';
|
||||
|
||||
/**
|
||||
* "group", "case" or "all"
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $type = '';
|
||||
|
||||
/**
|
||||
* Path to the test case/group file
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $file = '';
|
||||
|
||||
/**
|
||||
* Storage for plugins that have tests
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $plugins = array();
|
||||
|
||||
/**
|
||||
* Convenience variable to avoid duplicated code
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $isPluginTest = false;
|
||||
|
||||
/**
|
||||
* Stores if the user wishes to get a code coverage analysis report
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $doCoverage = false;
|
||||
|
||||
/**
|
||||
* Initialization method installs Simpletest and loads all plugins
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {
|
||||
$corePath = App::core('cake');
|
||||
if (isset($corePath[0])) {
|
||||
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
|
||||
} else {
|
||||
define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
|
||||
}
|
||||
|
||||
$this->__installSimpleTest();
|
||||
|
||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
|
||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'reporter' . DS . 'cake_cli_reporter.php';
|
||||
|
||||
$plugins = App::objects('plugin');
|
||||
foreach ($plugins as $p) {
|
||||
$this->plugins[] = Inflector::underscore($p);
|
||||
}
|
||||
$this->parseArgs();
|
||||
$this->getManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the arguments given into the Shell object properties.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function parseArgs() {
|
||||
if (empty($this->args)) {
|
||||
return;
|
||||
}
|
||||
$this->category = $this->args[0];
|
||||
|
||||
if (!in_array($this->category, array('app', 'core'))) {
|
||||
$this->isPluginTest = true;
|
||||
}
|
||||
|
||||
if (isset($this->args[1])) {
|
||||
$this->type = $this->args[1];
|
||||
}
|
||||
|
||||
if (isset($this->args[2])) {
|
||||
if ($this->args[2] == 'cov') {
|
||||
$this->doCoverage = true;
|
||||
} else {
|
||||
$this->file = Inflector::underscore($this->args[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->args[3]) && $this->args[3] == 'cov') {
|
||||
$this->doCoverage = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a manager instance, and set the app/plugin properties.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function getManager() {
|
||||
$this->Manager = new TestManager();
|
||||
$this->Manager->appTest = ($this->category === 'app');
|
||||
if ($this->isPluginTest) {
|
||||
$this->Manager->pluginTest = $this->category;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point to this shell
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function main() {
|
||||
$this->out(__('CakePHP Test Shell', true));
|
||||
$this->hr();
|
||||
|
||||
if (count($this->args) == 0) {
|
||||
$this->error(__('Sorry, you did not pass any arguments!', true));
|
||||
}
|
||||
|
||||
if ($this->__canRun()) {
|
||||
$message = sprintf(__('Running %s %s %s', true), $this->category, $this->type, $this->file);
|
||||
$this->out($message);
|
||||
|
||||
$exitCode = 0;
|
||||
if (!$this->__run()) {
|
||||
$exitCode = 1;
|
||||
}
|
||||
$this->_stop($exitCode);
|
||||
} else {
|
||||
$this->error(__('Sorry, the tests could not be found.', true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Help screen
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->out('Usage: ');
|
||||
$this->out("\tcake testsuite category test_type file");
|
||||
$this->out("\t\t- category - \"app\", \"core\" or name of a plugin");
|
||||
$this->out("\t\t- test_type - \"case\", \"group\" or \"all\"");
|
||||
$this->out("\t\t- test_file - file name with folder prefix and without the (test|group).php suffix");
|
||||
$this->out();
|
||||
$this->out('Examples: ');
|
||||
$this->out("\t\tcake testsuite app all");
|
||||
$this->out("\t\tcake testsuite core all");
|
||||
$this->out();
|
||||
$this->out("\t\tcake testsuite app case behaviors/debuggable");
|
||||
$this->out("\t\tcake testsuite app case models/my_model");
|
||||
$this->out("\t\tcake testsuite app case controllers/my_controller");
|
||||
$this->out();
|
||||
$this->out("\t\tcake testsuite core case file");
|
||||
$this->out("\t\tcake testsuite core case router");
|
||||
$this->out("\t\tcake testsuite core case set");
|
||||
$this->out();
|
||||
$this->out("\t\tcake testsuite app group mygroup");
|
||||
$this->out("\t\tcake testsuite core group acl");
|
||||
$this->out("\t\tcake testsuite core group socket");
|
||||
$this->out();
|
||||
$this->out("\t\tcake testsuite bugs case models/bug");
|
||||
$this->out("\t\t // for the plugin 'bugs' and its test case 'models/bug'");
|
||||
$this->out("\t\tcake testsuite bugs group bug");
|
||||
$this->out("\t\t // for the plugin bugs and its test group 'bug'");
|
||||
$this->out();
|
||||
$this->out('Code Coverage Analysis: ');
|
||||
$this->out("\n\nAppend 'cov' to any of the above in order to enable code coverage analysis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the arguments supplied point to a valid test file and thus the shell can be run.
|
||||
*
|
||||
* @return bool true if it's a valid test file, false otherwise
|
||||
* @access private
|
||||
*/
|
||||
function __canRun() {
|
||||
$isNeitherAppNorCore = !in_array($this->category, array('app', 'core'));
|
||||
$isPlugin = in_array(Inflector::underscore($this->category), $this->plugins);
|
||||
|
||||
if ($isNeitherAppNorCore && !$isPlugin) {
|
||||
$message = sprintf(
|
||||
__('%s is an invalid test category (either "app", "core" or name of a plugin)', true),
|
||||
$this->category
|
||||
);
|
||||
$this->error($message);
|
||||
return false;
|
||||
}
|
||||
|
||||
$folder = $this->__findFolderByCategory($this->category);
|
||||
if (!file_exists($folder)) {
|
||||
$this->err(sprintf(__('%s not found', true), $folder));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!in_array($this->type, array('all', 'group', 'case'))) {
|
||||
$this->err(sprintf(__('%s is invalid. Should be case, group or all', true), $this->type));
|
||||
return false;
|
||||
}
|
||||
|
||||
$fileName = $this->__getFileName($folder, $this->isPluginTest);
|
||||
if ($fileName === true || file_exists($folder . $fileName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
__('%s %s %s is an invalid test identifier', true),
|
||||
$this->category, $this->type, $this->file
|
||||
);
|
||||
$this->err($message);
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Executes the tests depending on our settings
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __run() {
|
||||
$Reporter = new CakeCliReporter('utf-8', array(
|
||||
'app' => $this->Manager->appTest,
|
||||
'plugin' => $this->Manager->pluginTest,
|
||||
'group' => ($this->type === 'group'),
|
||||
'codeCoverage' => $this->doCoverage
|
||||
));
|
||||
|
||||
if ($this->type == 'all') {
|
||||
return $this->Manager->runAllTests($Reporter);
|
||||
}
|
||||
|
||||
if ($this->doCoverage) {
|
||||
if (!extension_loaded('xdebug')) {
|
||||
$this->out(__('You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation. Download it from http://www.xdebug.org/docs/install', true));
|
||||
$this->_stop(0);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'group') {
|
||||
$ucFirstGroup = ucfirst($this->file);
|
||||
if ($this->doCoverage) {
|
||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
|
||||
CodeCoverageManager::init($ucFirstGroup, $Reporter);
|
||||
CodeCoverageManager::start();
|
||||
}
|
||||
$result = $this->Manager->runGroupTest($ucFirstGroup, $Reporter);
|
||||
return $result;
|
||||
}
|
||||
|
||||
$folder = $folder = $this->__findFolderByCategory($this->category);
|
||||
$case = $this->__getFileName($folder, $this->isPluginTest);
|
||||
|
||||
if ($this->doCoverage) {
|
||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
|
||||
CodeCoverageManager::init($case, $Reporter);
|
||||
CodeCoverageManager::start();
|
||||
}
|
||||
$result = $this->Manager->runTestCase($case, $Reporter);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the concrete filename for the inputted test name and category/type
|
||||
*
|
||||
* @param string $folder Folder name to look for files in.
|
||||
* @param boolean $isPlugin If the test case is a plugin.
|
||||
* @return mixed Either string filename or boolean false on failure. Or true if the type is 'all'
|
||||
* @access private
|
||||
*/
|
||||
function __getFileName($folder, $isPlugin) {
|
||||
$ext = $this->Manager->getExtension($this->type);
|
||||
switch ($this->type) {
|
||||
case 'all':
|
||||
return true;
|
||||
case 'group':
|
||||
return $this->file . $ext;
|
||||
case 'case':
|
||||
if ($this->category == 'app' || $isPlugin) {
|
||||
return $this->file . $ext;
|
||||
}
|
||||
$coreCase = $this->file . $ext;
|
||||
$coreLibCase = 'libs' . DS . $this->file . $ext;
|
||||
|
||||
if ($this->category == 'core' && file_exists($folder . DS . $coreCase)) {
|
||||
return $coreCase;
|
||||
} elseif ($this->category == 'core' && file_exists($folder . DS . $coreLibCase)) {
|
||||
return $coreLibCase;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the correct folder to look for tests for based on the input category and type.
|
||||
*
|
||||
* @param string $category The category of the test. Either 'app', 'core' or a plugin name.
|
||||
* @return string the folder path
|
||||
* @access private
|
||||
*/
|
||||
function __findFolderByCategory($category) {
|
||||
$folder = '';
|
||||
$paths = array(
|
||||
'core' => CAKE,
|
||||
'app' => APP
|
||||
);
|
||||
$typeDir = $this->type === 'group' ? 'groups' : 'cases';
|
||||
|
||||
if (array_key_exists($category, $paths)) {
|
||||
$folder = $paths[$category] . 'tests' . DS . $typeDir . DS;
|
||||
} else {
|
||||
$pluginPath = App::pluginPath($category);
|
||||
if (is_dir($pluginPath . 'tests')) {
|
||||
$folder = $pluginPath . 'tests' . DS . $typeDir . DS;
|
||||
}
|
||||
}
|
||||
return $folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* tries to install simpletest and exits gracefully if it is not there
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __installSimpleTest() {
|
||||
if (!App::import('Vendor', 'simpletest' . DS . 'reporter')) {
|
||||
$this->err(__('Sorry, Simpletest could not be found. Download it from http://simpletest.org and install it to your vendors directory.', true));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Bake Template for Controller action generation.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.console.libs.template.objects
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
|
||||
function <?php echo $admin ?>index() {
|
||||
$this-><?php echo $currentModelName ?>->recursive = 0;
|
||||
$this->set('<?php echo $pluralName ?>', $this->paginate());
|
||||
}
|
||||
|
||||
function <?php echo $admin ?>view($id = null) {
|
||||
if (!$id) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('Invalid <?php echo strtolower($singularHumanName) ?>', true));
|
||||
$this->redirect(array('action' => 'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(__('Invalid <?php echo strtolower($singularHumanName); ?>', true), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
}
|
||||
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
|
||||
}
|
||||
|
||||
<?php $compact = array(); ?>
|
||||
function <?php echo $admin ?>add() {
|
||||
if (!empty($this->data)) {
|
||||
$this-><?php echo $currentModelName; ?>->create();
|
||||
if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved', true));
|
||||
$this->redirect(array('action' => 'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.', true), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
} else {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.', true));
|
||||
<?php endif; ?>
|
||||
}
|
||||
}
|
||||
<?php
|
||||
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
|
||||
foreach ($modelObj->{$assoc} as $associationName => $relation):
|
||||
if (!empty($associationName)):
|
||||
$otherModelName = $this->_modelName($associationName);
|
||||
$otherPluralName = $this->_pluralName($associationName);
|
||||
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
|
||||
$compact[] = "'{$otherPluralName}'";
|
||||
endif;
|
||||
endforeach;
|
||||
endforeach;
|
||||
if (!empty($compact)):
|
||||
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
|
||||
endif;
|
||||
?>
|
||||
}
|
||||
|
||||
<?php $compact = array(); ?>
|
||||
function <?php echo $admin; ?>edit($id = null) {
|
||||
if (!$id && empty($this->data)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('Invalid <?php echo strtolower($singularHumanName); ?>', true));
|
||||
$this->redirect(array('action' => 'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(sprintf(__('Invalid <?php echo strtolower($singularHumanName); ?>', true)), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
}
|
||||
if (!empty($this->data)) {
|
||||
if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved', true));
|
||||
$this->redirect(array('action' => 'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.', true), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
} else {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.', true));
|
||||
<?php endif; ?>
|
||||
}
|
||||
}
|
||||
if (empty($this->data)) {
|
||||
$this->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
|
||||
}
|
||||
<?php
|
||||
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
|
||||
foreach ($modelObj->{$assoc} as $associationName => $relation):
|
||||
if (!empty($associationName)):
|
||||
$otherModelName = $this->_modelName($associationName);
|
||||
$otherPluralName = $this->_pluralName($associationName);
|
||||
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
|
||||
$compact[] = "'{$otherPluralName}'";
|
||||
endif;
|
||||
endforeach;
|
||||
endforeach;
|
||||
if (!empty($compact)):
|
||||
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
|
||||
endif;
|
||||
?>
|
||||
}
|
||||
|
||||
function <?php echo $admin; ?>delete($id = null) {
|
||||
if (!$id) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('Invalid id for <?php echo strtolower($singularHumanName); ?>', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(sprintf(__('Invalid <?php echo strtolower($singularHumanName); ?>', true)), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
}
|
||||
if ($this-><?php echo $currentModelName; ?>->delete($id)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted', true), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
}
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted', true));
|
||||
<?php else: ?>
|
||||
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted', true), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
$this->redirect(array('action' => 'index'));
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Controller bake template file
|
||||
*
|
||||
* Allows templating of Controllers generated from bake.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
echo "<?php\n";
|
||||
?>
|
||||
class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>AppController {
|
||||
|
||||
var $name = '<?php echo $controllerName; ?>';
|
||||
<?php if ($isScaffold): ?>
|
||||
var $scaffold;
|
||||
<?php else: ?>
|
||||
<?php
|
||||
if (count($helpers)):
|
||||
echo "\tvar \$helpers = array(";
|
||||
for ($i = 0, $len = count($helpers); $i < $len; $i++):
|
||||
if ($i != $len - 1):
|
||||
echo "'" . Inflector::camelize($helpers[$i]) . "', ";
|
||||
else:
|
||||
echo "'" . Inflector::camelize($helpers[$i]) . "'";
|
||||
endif;
|
||||
endfor;
|
||||
echo ");\n";
|
||||
endif;
|
||||
|
||||
if (count($components)):
|
||||
echo "\tvar \$components = array(";
|
||||
for ($i = 0, $len = count($components); $i < $len; $i++):
|
||||
if ($i != $len - 1):
|
||||
echo "'" . Inflector::camelize($components[$i]) . "', ";
|
||||
else:
|
||||
echo "'" . Inflector::camelize($components[$i]) . "'";
|
||||
endif;
|
||||
endfor;
|
||||
echo ");\n";
|
||||
endif;
|
||||
|
||||
echo $actions;
|
||||
|
||||
endif; ?>
|
||||
|
||||
}
|
||||
<?php echo "?>"; ?>
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Fixture Template file
|
||||
*
|
||||
* Fixture Template used when baking fixtures with bake
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<?php echo '<?php' . "\n"; ?>
|
||||
/* <?php echo $model; ?> Fixture generated on: <?php echo date('Y-m-d H:m:s') . " : ". time(); ?> */
|
||||
class <?php echo $model; ?>Fixture extends CakeTestFixture {
|
||||
var $name = '<?php echo $model; ?>';
|
||||
<?php if ($table): ?>
|
||||
var $table = '<?php echo $table; ?>';
|
||||
<?php endif; ?>
|
||||
<?php if ($import): ?>
|
||||
var $import = <?php echo $import; ?>;
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($schema): ?>
|
||||
var $fields = <?php echo $schema; ?>;
|
||||
<?php endif;?>
|
||||
|
||||
<?php if ($records): ?>
|
||||
var $records = <?php echo $records; ?>;
|
||||
<?php endif;?>
|
||||
}
|
||||
<?php echo '?>'; ?>
|
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Model template file.
|
||||
*
|
||||
* Used by bake to create new Model files.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.console.libs.templates.objects
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
echo "<?php\n"; ?>
|
||||
class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel {
|
||||
var $name = '<?php echo $name; ?>';
|
||||
<?php if ($useDbConfig != 'default'): ?>
|
||||
var $useDbConfig = '<?php echo $useDbConfig; ?>';
|
||||
<?php endif;?>
|
||||
<?php if ($useTable && $useTable !== Inflector::tableize($name)):
|
||||
$table = "'$useTable'";
|
||||
echo "\tvar \$useTable = $table;\n";
|
||||
endif;
|
||||
if ($primaryKey !== 'id'): ?>
|
||||
var $primaryKey = '<?php echo $primaryKey; ?>';
|
||||
<?php endif;
|
||||
if ($displayField): ?>
|
||||
var $displayField = '<?php echo $displayField; ?>';
|
||||
<?php endif;
|
||||
|
||||
if (!empty($validate)):
|
||||
echo "\tvar \$validate = array(\n";
|
||||
foreach ($validate as $field => $validations):
|
||||
echo "\t\t'$field' => array(\n";
|
||||
foreach ($validations as $key => $validator):
|
||||
echo "\t\t\t'$key' => array(\n";
|
||||
echo "\t\t\t\t'rule' => array('$validator'),\n";
|
||||
echo "\t\t\t\t//'message' => 'Your custom message here',\n";
|
||||
echo "\t\t\t\t//'allowEmpty' => false,\n";
|
||||
echo "\t\t\t\t//'required' => false,\n";
|
||||
echo "\t\t\t\t//'last' => false, // Stop validation after this rule\n";
|
||||
echo "\t\t\t\t//'on' => 'create', // Limit validation to 'create' or 'update' operations\n";
|
||||
echo "\t\t\t),\n";
|
||||
endforeach;
|
||||
echo "\t\t),\n";
|
||||
endforeach;
|
||||
echo "\t);\n";
|
||||
endif;
|
||||
|
||||
foreach ($associations as $assoc):
|
||||
if (!empty($assoc)):
|
||||
?>
|
||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
||||
<?php
|
||||
break;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
foreach (array('hasOne', 'belongsTo') as $assocType):
|
||||
if (!empty($associations[$assocType])):
|
||||
$typeCount = count($associations[$assocType]);
|
||||
echo "\n\tvar \$$assocType = array(";
|
||||
foreach ($associations[$assocType] as $i => $relation):
|
||||
$out = "\n\t\t'{$relation['alias']}' => array(\n";
|
||||
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
|
||||
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
|
||||
$out .= "\t\t\t'conditions' => '',\n";
|
||||
$out .= "\t\t\t'fields' => '',\n";
|
||||
$out .= "\t\t\t'order' => ''\n";
|
||||
$out .= "\t\t)";
|
||||
if ($i + 1 < $typeCount) {
|
||||
$out .= ",";
|
||||
}
|
||||
echo $out;
|
||||
endforeach;
|
||||
echo "\n\t);\n";
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
if (!empty($associations['hasMany'])):
|
||||
$belongsToCount = count($associations['hasMany']);
|
||||
echo "\n\tvar \$hasMany = array(";
|
||||
foreach ($associations['hasMany'] as $i => $relation):
|
||||
$out = "\n\t\t'{$relation['alias']}' => array(\n";
|
||||
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
|
||||
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
|
||||
$out .= "\t\t\t'dependent' => false,\n";
|
||||
$out .= "\t\t\t'conditions' => '',\n";
|
||||
$out .= "\t\t\t'fields' => '',\n";
|
||||
$out .= "\t\t\t'order' => '',\n";
|
||||
$out .= "\t\t\t'limit' => '',\n";
|
||||
$out .= "\t\t\t'offset' => '',\n";
|
||||
$out .= "\t\t\t'exclusive' => '',\n";
|
||||
$out .= "\t\t\t'finderQuery' => '',\n";
|
||||
$out .= "\t\t\t'counterQuery' => ''\n";
|
||||
$out .= "\t\t)";
|
||||
if ($i + 1 < $belongsToCount) {
|
||||
$out .= ",";
|
||||
}
|
||||
echo $out;
|
||||
endforeach;
|
||||
echo "\n\t);\n\n";
|
||||
endif;
|
||||
|
||||
if (!empty($associations['hasAndBelongsToMany'])):
|
||||
$habtmCount = count($associations['hasAndBelongsToMany']);
|
||||
echo "\n\tvar \$hasAndBelongsToMany = array(";
|
||||
foreach ($associations['hasAndBelongsToMany'] as $i => $relation):
|
||||
$out = "\n\t\t'{$relation['alias']}' => array(\n";
|
||||
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
|
||||
$out .= "\t\t\t'joinTable' => '{$relation['joinTable']}',\n";
|
||||
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
|
||||
$out .= "\t\t\t'associationForeignKey' => '{$relation['associationForeignKey']}',\n";
|
||||
$out .= "\t\t\t'unique' => true,\n";
|
||||
$out .= "\t\t\t'conditions' => '',\n";
|
||||
$out .= "\t\t\t'fields' => '',\n";
|
||||
$out .= "\t\t\t'order' => '',\n";
|
||||
$out .= "\t\t\t'limit' => '',\n";
|
||||
$out .= "\t\t\t'offset' => '',\n";
|
||||
$out .= "\t\t\t'finderQuery' => '',\n";
|
||||
$out .= "\t\t\t'deleteQuery' => '',\n";
|
||||
$out .= "\t\t\t'insertQuery' => ''\n";
|
||||
$out .= "\t\t)";
|
||||
if ($i + 1 < $habtmCount) {
|
||||
$out .= ",";
|
||||
}
|
||||
echo $out;
|
||||
endforeach;
|
||||
echo "\n\t);\n\n";
|
||||
endif;
|
||||
?>
|
||||
}
|
||||
<?php echo '?>'; ?>
|
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Test Case bake template
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.console.libs.templates.objects
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
echo "<?php\n";
|
||||
echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n";
|
||||
?>
|
||||
App::import('<?php echo $type; ?>', '<?php echo $plugin . $className;?>');
|
||||
|
||||
<?php if ($mock and strtolower($type) == 'controller'): ?>
|
||||
class Test<?php echo $fullClassName; ?> extends <?php echo $fullClassName; ?> {
|
||||
var $autoRender = false;
|
||||
|
||||
function redirect($url, $status = null, $exit = true) {
|
||||
$this->redirectUrl = $url;
|
||||
}
|
||||
}
|
||||
|
||||
<?php endif; ?>
|
||||
class <?php echo $fullClassName; ?>TestCase extends CakeTestCase {
|
||||
<?php if (!empty($fixtures)): ?>
|
||||
var $fixtures = array('<?php echo join("', '", $fixtures); ?>');
|
||||
|
||||
<?php endif; ?>
|
||||
function startTest() {
|
||||
$this-><?php echo $className . ' =& ' . $construction; ?>
|
||||
}
|
||||
|
||||
function endTest() {
|
||||
unset($this-><?php echo $className;?>);
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
<?php foreach ($methods as $method): ?>
|
||||
function test<?php echo Inflector::classify($method); ?>() {
|
||||
|
||||
}
|
||||
|
||||
<?php endforeach;?>
|
||||
}
|
||||
<?php echo '?>'; ?>
|
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.templates.views
|
||||
* @since CakePHP(tm) v 1.2.0.5234
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar;?> form">
|
||||
<?php echo "<?php echo \$this->Form->create('{$modelClass}');?>\n";?>
|
||||
<fieldset>
|
||||
<legend><?php printf("<?php __('%s %s'); ?>", Inflector::humanize($action), $singularHumanName); ?></legend>
|
||||
<?php
|
||||
echo "\t<?php\n";
|
||||
foreach ($fields as $field) {
|
||||
if (strpos($action, 'add') !== false && $field == $primaryKey) {
|
||||
continue;
|
||||
} elseif (!in_array($field, array('created', 'modified', 'updated'))) {
|
||||
echo "\t\techo \$this->Form->input('{$field}');\n";
|
||||
}
|
||||
}
|
||||
if (!empty($associations['hasAndBelongsToMany'])) {
|
||||
foreach ($associations['hasAndBelongsToMany'] as $assocName => $assocData) {
|
||||
echo "\t\techo \$this->Form->input('{$assocName}');\n";
|
||||
}
|
||||
}
|
||||
echo "\t?>\n";
|
||||
?>
|
||||
</fieldset>
|
||||
<?php
|
||||
echo "<?php echo \$this->Form->end(__('Submit', true));?>\n";
|
||||
?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<h3><?php echo "<?php __('Actions'); ?>"; ?></h3>
|
||||
<ul>
|
||||
|
||||
<?php if (strpos($action, 'add') === false): ?>
|
||||
<li><?php echo "<?php echo \$this->Html->link(__('Delete', true), array('action' => 'delete', \$this->Form->value('{$modelClass}.{$primaryKey}')), null, sprintf(__('Are you sure you want to delete # %s?', true), \$this->Form->value('{$modelClass}.{$primaryKey}'))); ?>";?></li>
|
||||
<?php endif;?>
|
||||
<li><?php echo "<?php echo \$this->Html->link(__('List " . $pluralHumanName . "', true), array('action' => 'index'));?>";?></li>
|
||||
<?php
|
||||
$done = array();
|
||||
foreach ($associations as $type => $data) {
|
||||
foreach ($data as $alias => $details) {
|
||||
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
|
||||
$done[] = $details['controller'];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
$output = "<h2>Sweet, \"" . Inflector::humanize($app) . "\" got Baked by CakePHP!</h2>\n";
|
||||
$output .="
|
||||
<?php
|
||||
if (Configure::read() > 0):
|
||||
Debugger::checkSecurityKeys();
|
||||
endif;
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
if (is_writable(TMP)):
|
||||
echo '<span class=\"notice success\">';
|
||||
__('Your tmp directory is writable.');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class=\"notice\">';
|
||||
__('Your tmp directory is NOT writable.');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
\$settings = Cache::settings();
|
||||
if (!empty(\$settings)):
|
||||
echo '<span class=\"notice success\">';
|
||||
printf(__('The %s is being used for caching. To change the config edit APP/config/core.php ', true), '<em>'. \$settings['engine'] . 'Engine</em>');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class=\"notice\">';
|
||||
__('Your cache is NOT working. Please check the settings in APP/config/core.php');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
\$filePresent = null;
|
||||
if (file_exists(CONFIGS . 'database.php')):
|
||||
echo '<span class=\"notice success\">';
|
||||
__('Your database configuration file is present.');
|
||||
\$filePresent = true;
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class=\"notice\">';
|
||||
__('Your database configuration file is NOT present.');
|
||||
echo '<br/>';
|
||||
__('Rename config/database.php.default to config/database.php');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
if (!empty(\$filePresent)):
|
||||
if (!class_exists('ConnectionManager')) {
|
||||
require LIBS . 'model' . DS . 'connection_manager.php';
|
||||
}
|
||||
\$db = ConnectionManager::getInstance();
|
||||
\$connected = \$db->getDataSource('default');
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
if (\$connected->isConnected()):
|
||||
echo '<span class=\"notice success\">';
|
||||
__('Cake is able to connect to the database.');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class=\"notice\">';
|
||||
__('Cake is NOT able to connect to the database.');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>\n";
|
||||
$output .= "<?php endif;?>\n";
|
||||
$output .= "<h3><?php __('Editing this Page') ?></h3>\n";
|
||||
$output .= "<p>\n";
|
||||
$output .= "<?php\n";
|
||||
$output .= "\tprintf(__('To change the content of this page, edit: %s\n";
|
||||
$output .= "\t\tTo change its layout, edit: %s\n";
|
||||
$output .= "\t\tYou can also add some CSS styles for your pages at: %s', true),\n";
|
||||
$output .= "\t\tAPP . 'views' . DS . 'pages' . DS . 'home.ctp.<br />', APP . 'views' . DS . 'layouts' . DS . 'default.ctp.<br />', APP . 'webroot' . DS . 'css');\n";
|
||||
$output .= "?>\n";
|
||||
$output .= "</p>\n";
|
||||
?>
|
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.templates.views
|
||||
* @since CakePHP(tm) v 1.2.0.5234
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar;?> index">
|
||||
<h2><?php echo "<?php __('{$pluralHumanName}');?>";?></h2>
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<?php foreach ($fields as $field):?>
|
||||
<th><?php echo "<?php echo \$this->Paginator->sort('{$field}');?>";?></th>
|
||||
<?php endforeach;?>
|
||||
<th class="actions"><?php echo "<?php __('Actions');?>";?></th>
|
||||
</tr>
|
||||
<?php
|
||||
echo "<?php
|
||||
\$i = 0;
|
||||
foreach (\${$pluralVar} as \${$singularVar}):
|
||||
\$class = null;
|
||||
if (\$i++ % 2 == 0) {
|
||||
\$class = ' class=\"altrow\"';
|
||||
}
|
||||
?>\n";
|
||||
echo "\t<tr<?php echo \$class;?>>\n";
|
||||
foreach ($fields as $field) {
|
||||
$isKey = false;
|
||||
if (!empty($associations['belongsTo'])) {
|
||||
foreach ($associations['belongsTo'] as $alias => $details) {
|
||||
if ($field === $details['foreignKey']) {
|
||||
$isKey = true;
|
||||
echo "\t\t<td>\n\t\t\t<?php echo \$this->Html->link(\${$singularVar}['{$alias}']['{$details['displayField']}'], array('controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?>\n\t\t</td>\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($isKey !== true) {
|
||||
echo "\t\t<td><?php echo \${$singularVar}['{$modelClass}']['{$field}']; ?> </td>\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "\t\t<td class=\"actions\">\n";
|
||||
echo "\t\t\t<?php echo \$this->Html->link(__('View', true), array('action' => 'view', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
|
||||
echo "\t\t\t<?php echo \$this->Html->link(__('Edit', true), array('action' => 'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
|
||||
echo "\t\t\t<?php echo \$this->Html->link(__('Delete', true), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, sprintf(__('Are you sure you want to delete # %s?', true), \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
|
||||
echo "\t\t</td>\n";
|
||||
echo "\t</tr>\n";
|
||||
|
||||
echo "<?php endforeach; ?>\n";
|
||||
?>
|
||||
</table>
|
||||
<p>
|
||||
<?php echo "<?php
|
||||
echo \$this->Paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
|
||||
));
|
||||
?>";?>
|
||||
</p>
|
||||
|
||||
<div class="paging">
|
||||
<?php echo "\t<?php echo \$this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>\n";?>
|
||||
| <?php echo "\t<?php echo \$this->Paginator->numbers();?>\n"?> |
|
||||
<?php echo "\t<?php echo \$this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>\n";?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<h3><?php echo "<?php __('Actions'); ?>"; ?></h3>
|
||||
<ul>
|
||||
<li><?php echo "<?php echo \$this->Html->link(__('New " . $singularHumanName . "', true), array('action' => 'add')); ?>";?></li>
|
||||
<?php
|
||||
$done = array();
|
||||
foreach ($associations as $type => $data) {
|
||||
foreach ($data as $alias => $details) {
|
||||
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
|
||||
$done[] = $details['controller'];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.templates.views
|
||||
* @since CakePHP(tm) v 1.2.0.5234
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar;?> view">
|
||||
<h2><?php echo "<?php __('{$singularHumanName}');?>";?></h2>
|
||||
<dl><?php echo "<?php \$i = 0; \$class = ' class=\"altrow\"';?>\n";?>
|
||||
<?php
|
||||
foreach ($fields as $field) {
|
||||
$isKey = false;
|
||||
if (!empty($associations['belongsTo'])) {
|
||||
foreach ($associations['belongsTo'] as $alias => $details) {
|
||||
if ($field === $details['foreignKey']) {
|
||||
$isKey = true;
|
||||
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('" . Inflector::humanize(Inflector::underscore($alias)) . "'); ?></dt>\n";
|
||||
echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t\t\t<?php echo \$this->Html->link(\${$singularVar}['{$alias}']['{$details['displayField']}'], array('controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?>\n\t\t\t \n\t\t</dd>\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($isKey !== true) {
|
||||
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('" . Inflector::humanize($field) . "'); ?></dt>\n";
|
||||
echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t\t\t<?php echo \${$singularVar}['{$modelClass}']['{$field}']; ?>\n\t\t\t \n\t\t</dd>\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<h3><?php echo "<?php __('Actions'); ?>"; ?></h3>
|
||||
<ul>
|
||||
<?php
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('Edit " . $singularHumanName ."', true), array('action' => 'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('Delete " . $singularHumanName . "', true), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, sprintf(__('Are you sure you want to delete # %s?', true), \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('List " . $pluralHumanName . "', true), array('action' => 'index')); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('New " . $singularHumanName . "', true), array('action' => 'add')); ?> </li>\n";
|
||||
|
||||
$done = array();
|
||||
foreach ($associations as $type => $data) {
|
||||
foreach ($data as $alias => $details) {
|
||||
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
|
||||
$done[] = $details['controller'];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
if (!empty($associations['hasOne'])) :
|
||||
foreach ($associations['hasOne'] as $alias => $details): ?>
|
||||
<div class="related">
|
||||
<h3><?php echo "<?php __('Related " . Inflector::humanize($details['controller']) . "');?>";?></h3>
|
||||
<?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?>
|
||||
<dl><?php echo "\t<?php \$i = 0; \$class = ' class=\"altrow\"';?>\n";?>
|
||||
<?php
|
||||
foreach ($details['fields'] as $field) {
|
||||
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('" . Inflector::humanize($field) . "');?></dt>\n";
|
||||
echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t<?php echo \${$singularVar}['{$alias}']['{$field}'];?>\n </dd>\n";
|
||||
}
|
||||
?>
|
||||
</dl>
|
||||
<?php echo "<?php endif; ?>\n";?>
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo "<?php echo \$this->Html->link(__('Edit " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'edit', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?></li>\n";?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endforeach;
|
||||
endif;
|
||||
if (empty($associations['hasMany'])) {
|
||||
$associations['hasMany'] = array();
|
||||
}
|
||||
if (empty($associations['hasAndBelongsToMany'])) {
|
||||
$associations['hasAndBelongsToMany'] = array();
|
||||
}
|
||||
$relations = array_merge($associations['hasMany'], $associations['hasAndBelongsToMany']);
|
||||
$i = 0;
|
||||
foreach ($relations as $alias => $details):
|
||||
$otherSingularVar = Inflector::variable($alias);
|
||||
$otherPluralHumanName = Inflector::humanize($details['controller']);
|
||||
?>
|
||||
<div class="related">
|
||||
<h3><?php echo "<?php __('Related " . $otherPluralHumanName . "');?>";?></h3>
|
||||
<?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?>
|
||||
<table cellpadding = "0" cellspacing = "0">
|
||||
<tr>
|
||||
<?php
|
||||
foreach ($details['fields'] as $field) {
|
||||
echo "\t\t<th><?php __('" . Inflector::humanize($field) . "'); ?></th>\n";
|
||||
}
|
||||
?>
|
||||
<th class="actions"><?php echo "<?php __('Actions');?>";?></th>
|
||||
</tr>
|
||||
<?php
|
||||
echo "\t<?php
|
||||
\$i = 0;
|
||||
foreach (\${$singularVar}['{$alias}'] as \${$otherSingularVar}):
|
||||
\$class = null;
|
||||
if (\$i++ % 2 == 0) {
|
||||
\$class = ' class=\"altrow\"';
|
||||
}
|
||||
?>\n";
|
||||
echo "\t\t<tr<?php echo \$class;?>>\n";
|
||||
|
||||
foreach ($details['fields'] as $field) {
|
||||
echo "\t\t\t<td><?php echo \${$otherSingularVar}['{$field}'];?></td>\n";
|
||||
}
|
||||
|
||||
echo "\t\t\t<td class=\"actions\">\n";
|
||||
echo "\t\t\t\t<?php echo \$this->Html->link(__('View', true), array('controller' => '{$details['controller']}', 'action' => 'view', \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
|
||||
echo "\t\t\t\t<?php echo \$this->Html->link(__('Edit', true), array('controller' => '{$details['controller']}', 'action' => 'edit', \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
|
||||
echo "\t\t\t\t<?php echo \$this->Html->link(__('Delete', true), array('controller' => '{$details['controller']}', 'action' => 'delete', \${$otherSingularVar}['{$details['primaryKey']}']), null, sprintf(__('Are you sure you want to delete # %s?', true), \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
|
||||
echo "\t\t\t</td>\n";
|
||||
echo "\t\t</tr>\n";
|
||||
|
||||
echo "\t<?php endforeach; ?>\n";
|
||||
?>
|
||||
</table>
|
||||
<?php echo "<?php endif; ?>\n\n";?>
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo "<?php echo \$this->Html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add'));?>";?> </li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach;?>
|
@@ -0,0 +1,5 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
RewriteRule ^$ webroot/ [L]
|
||||
RewriteRule (.*) webroot/$1 [L]
|
||||
</IfModule>
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Application level Controller
|
||||
*
|
||||
* This file is application-wide controller file. You can put all
|
||||
* application-wide controller-related methods here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Application Controller
|
||||
*
|
||||
* Add your application-wide methods in the class below, your controllers
|
||||
* will inherit them.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.app
|
||||
*/
|
||||
class AppController extends Controller {
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Application level View Helper
|
||||
*
|
||||
* This file is application-wide helper file. You can put all
|
||||
* application-wide helper-related methods here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Helper', 'Helper', false);
|
||||
|
||||
/**
|
||||
* This is a placeholder class.
|
||||
* Create the same file in app/app_helper.php
|
||||
*
|
||||
* Add your application-wide methods in the class below, your helpers
|
||||
* will inherit them.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake
|
||||
*/
|
||||
class AppHelper extends Helper {
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Application model for Cake.
|
||||
*
|
||||
* This file is application-wide model file. You can put all
|
||||
* application-wide model-related methods here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Application model for Cake.
|
||||
*
|
||||
* Add your application-wide methods in the class below, your models
|
||||
* will inherit them.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.app
|
||||
*/
|
||||
class AppModel extends Model {
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
;<?php exit() ?>
|
||||
; SVN FILE: $Id$
|
||||
;/**
|
||||
; * ACL Configuration
|
||||
; *
|
||||
; *
|
||||
; * PHP versions 4 and 5
|
||||
; *
|
||||
; * CakePHP(tm) : Rapid Development Framework http://www.cakephp.org/
|
||||
; * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
; *
|
||||
; * Licensed under The MIT License
|
||||
; * Redistributions of files must retain the above copyright notice.
|
||||
; *
|
||||
; * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
; * @link http://cakephp.org CakePHP(tm) Project
|
||||
; * @package cake
|
||||
; * @subpackage cake.app.config
|
||||
; * @since CakePHP(tm) v 0.10.0.1076
|
||||
; * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
; */
|
||||
|
||||
; acl.ini.php - Cake ACL Configuration
|
||||
; ---------------------------------------------------------------------
|
||||
; Use this file to specify user permissions.
|
||||
; aco = access control object (something in your application)
|
||||
; aro = access request object (something requesting access)
|
||||
;
|
||||
; User records are added as follows:
|
||||
;
|
||||
; [uid]
|
||||
; groups = group1, group2, group3
|
||||
; allow = aco1, aco2, aco3
|
||||
; deny = aco4, aco5, aco6
|
||||
;
|
||||
; Group records are added in a similar manner:
|
||||
;
|
||||
; [gid]
|
||||
; allow = aco1, aco2, aco3
|
||||
; deny = aco4, aco5, aco6
|
||||
;
|
||||
; The allow, deny, and groups sections are all optional.
|
||||
; NOTE: groups names *cannot* ever be the same as usernames!
|
||||
;
|
||||
; ACL permissions are checked in the following order:
|
||||
; 1. Check for user denies (and DENY if specified)
|
||||
; 2. Check for user allows (and ALLOW if specified)
|
||||
; 3. Gather user's groups
|
||||
; 4. Check group denies (and DENY if specified)
|
||||
; 5. Check group allows (and ALLOW if specified)
|
||||
; 6. If no aro, aco, or group information is found, DENY
|
||||
;
|
||||
; ---------------------------------------------------------------------
|
||||
|
||||
;-------------------------------------
|
||||
;Users
|
||||
;-------------------------------------
|
||||
|
||||
[username-goes-here]
|
||||
groups = group1, group2
|
||||
deny = aco1, aco2
|
||||
allow = aco3, aco4
|
||||
|
||||
;-------------------------------------
|
||||
;Groups
|
||||
;-------------------------------------
|
||||
|
||||
[groupname-goes-here]
|
||||
deny = aco5, aco6
|
||||
allow = aco7, aco8
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php
|
||||
*
|
||||
* This is an application wide file to load any function that is not used within a class
|
||||
* define. You can also use this to include or require any files in your application.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP(tm) v 0.10.8.2117
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* The settings below can be used to set additional paths to models, views and controllers.
|
||||
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
|
||||
*
|
||||
* App::build(array(
|
||||
* 'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
|
||||
* 'models' => array('/full/path/to/models/', '/next/full/path/to/models/'),
|
||||
* 'views' => array('/full/path/to/views/', '/next/full/path/to/views/'),
|
||||
* 'controllers' => array(/full/path/to/controllers/', '/next/full/path/to/controllers/'),
|
||||
* 'datasources' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
|
||||
* 'behaviors' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
|
||||
* 'components' => array('/full/path/to/components/', '/next/full/path/to/components/'),
|
||||
* 'helpers' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'),
|
||||
* 'vendors' => array('/full/path/to/vendors/', '/next/full/path/to/vendors/'),
|
||||
* 'shells' => array('/full/path/to/shells/', '/next/full/path/to/shells/'),
|
||||
* 'locales' => array('/full/path/to/locale/', '/next/full/path/to/locale/')
|
||||
* ));
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* As of 1.3, additional rules for the inflector are added below
|
||||
*
|
||||
* Inflector::rules('singular', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
|
||||
* Inflector::rules('plural', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
|
||||
*
|
||||
*/
|
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
/**
|
||||
* This is core configuration file.
|
||||
*
|
||||
* Use it to configure core behavior of Cake.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* CakePHP Debug Level:
|
||||
*
|
||||
* Production Mode:
|
||||
* 0: No error messages, errors, or warnings shown. Flash messages redirect.
|
||||
*
|
||||
* Development Mode:
|
||||
* 1: Errors and warnings shown, model caches refreshed, flash messages halted.
|
||||
* 2: As in 1, but also with full debug messages and SQL output.
|
||||
*
|
||||
* In production mode, flash messages redirect after a time interval.
|
||||
* In development mode, you need to click the flash message to continue.
|
||||
*/
|
||||
Configure::write('debug', 2);
|
||||
|
||||
/**
|
||||
* CakePHP Log Level:
|
||||
*
|
||||
* In case of Production Mode CakePHP gives you the possibility to continue logging errors.
|
||||
*
|
||||
* The following parameters can be used:
|
||||
* Boolean: Set true/false to activate/deactivate logging
|
||||
* Configure::write('log', true);
|
||||
*
|
||||
* Integer: Use built-in PHP constants to set the error level (see error_reporting)
|
||||
* Configure::write('log', E_ERROR | E_WARNING);
|
||||
* Configure::write('log', E_ALL ^ E_NOTICE);
|
||||
*/
|
||||
Configure::write('log', true);
|
||||
|
||||
/**
|
||||
* Application wide charset encoding
|
||||
*/
|
||||
Configure::write('App.encoding', 'UTF-8');
|
||||
|
||||
/**
|
||||
* To configure CakePHP *not* to use mod_rewrite and to
|
||||
* use CakePHP pretty URLs, remove these .htaccess
|
||||
* files:
|
||||
*
|
||||
* /.htaccess
|
||||
* /app/.htaccess
|
||||
* /app/webroot/.htaccess
|
||||
*
|
||||
* And uncomment the App.baseUrl below:
|
||||
*/
|
||||
//Configure::write('App.baseUrl', env('SCRIPT_NAME'));
|
||||
|
||||
/**
|
||||
* Uncomment the define below to use CakePHP prefix routes.
|
||||
*
|
||||
* The value of the define determines the names of the routes
|
||||
* and their associated controller actions:
|
||||
*
|
||||
* Set to an array of prefixes you want to use in your application. Use for
|
||||
* admin or other prefixed routes.
|
||||
*
|
||||
* Routing.prefixes = array('admin', 'manager');
|
||||
*
|
||||
* Enables:
|
||||
* `admin_index()` and `/admin/controller/index`
|
||||
* `manager_index()` and `/manager/controller/index`
|
||||
*
|
||||
* [Note Routing.admin is deprecated in 1.3. Use Routing.prefixes instead]
|
||||
*/
|
||||
//Configure::write('Routing.prefixes', array('admin'));
|
||||
|
||||
/**
|
||||
* Turn off all caching application-wide.
|
||||
*
|
||||
*/
|
||||
//Configure::write('Cache.disable', true);
|
||||
|
||||
/**
|
||||
* Enable cache checking.
|
||||
*
|
||||
* If set to true, for view caching you must still use the controller
|
||||
* var $cacheAction inside your controllers to define caching settings.
|
||||
* You can either set it controller-wide by setting var $cacheAction = true,
|
||||
* or in each action using $this->cacheAction = true.
|
||||
*
|
||||
*/
|
||||
//Configure::write('Cache.check', true);
|
||||
|
||||
/**
|
||||
* Defines the default error type when using the log() function. Used for
|
||||
* differentiating error logging and debugging. Currently PHP supports LOG_DEBUG.
|
||||
*/
|
||||
define('LOG_ERROR', 2);
|
||||
|
||||
/**
|
||||
* The preferred session handling method. Valid values:
|
||||
*
|
||||
* 'php' Uses settings defined in your php.ini.
|
||||
* 'cake' Saves session files in CakePHP's /tmp directory.
|
||||
* 'database' Uses CakePHP's database sessions.
|
||||
*
|
||||
* To define a custom session handler, save it at /app/config/<name>.php.
|
||||
* Set the value of 'Session.save' to <name> to utilize it in CakePHP.
|
||||
*
|
||||
* To use database sessions, run the app/config/schema/sessions.php schema using
|
||||
* the cake shell command: cake schema create Sessions
|
||||
*
|
||||
*/
|
||||
Configure::write('Session.save', 'php');
|
||||
|
||||
/**
|
||||
* The model name to be used for the session model.
|
||||
*
|
||||
* 'Session.save' must be set to 'database' in order to utilize this constant.
|
||||
*
|
||||
* The model name set here should *not* be used elsewhere in your application.
|
||||
*/
|
||||
//Configure::write('Session.model', 'Session');
|
||||
|
||||
/**
|
||||
* The name of the table used to store CakePHP database sessions.
|
||||
*
|
||||
* 'Session.save' must be set to 'database' in order to utilize this constant.
|
||||
*
|
||||
* The table name set here should *not* include any table prefix defined elsewhere.
|
||||
*
|
||||
* Please note that if you set a value for Session.model (above), any value set for
|
||||
* Session.table will be ignored.
|
||||
*
|
||||
* [Note: Session.table is deprecated as of CakePHP 1.3]
|
||||
*/
|
||||
//Configure::write('Session.table', 'cake_sessions');
|
||||
|
||||
/**
|
||||
* The DATABASE_CONFIG::$var to use for database session handling.
|
||||
*
|
||||
* 'Session.save' must be set to 'database' in order to utilize this constant.
|
||||
*/
|
||||
//Configure::write('Session.database', 'default');
|
||||
|
||||
/**
|
||||
* The name of CakePHP's session cookie.
|
||||
*
|
||||
* Note the guidelines for Session names states: "The session name references
|
||||
* the session id in cookies and URLs. It should contain only alphanumeric
|
||||
* characters."
|
||||
* @link http://php.net/session_name
|
||||
*/
|
||||
Configure::write('Session.cookie', 'CAKEPHP');
|
||||
|
||||
/**
|
||||
* Session time out time (in seconds).
|
||||
* Actual value depends on 'Security.level' setting.
|
||||
*/
|
||||
Configure::write('Session.timeout', '120');
|
||||
|
||||
/**
|
||||
* If set to false, sessions are not automatically started.
|
||||
*/
|
||||
Configure::write('Session.start', true);
|
||||
|
||||
/**
|
||||
* When set to false, HTTP_USER_AGENT will not be checked
|
||||
* in the session. You might want to set the value to false, when dealing with
|
||||
* older versions of IE, Chrome Frame or certain web-browsing devices and AJAX
|
||||
*/
|
||||
Configure::write('Session.checkAgent', true);
|
||||
|
||||
/**
|
||||
* The level of CakePHP security. The session timeout time defined
|
||||
* in 'Session.timeout' is multiplied according to the settings here.
|
||||
* Valid values:
|
||||
*
|
||||
* 'high' Session timeout in 'Session.timeout' x 10
|
||||
* 'medium' Session timeout in 'Session.timeout' x 100
|
||||
* 'low' Session timeout in 'Session.timeout' x 300
|
||||
*
|
||||
* CakePHP session IDs are also regenerated between requests if
|
||||
* 'Security.level' is set to 'high'.
|
||||
*/
|
||||
Configure::write('Security.level', 'medium');
|
||||
|
||||
/**
|
||||
* A random string used in security hashing methods.
|
||||
*/
|
||||
Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
|
||||
|
||||
/**
|
||||
* A random numeric string (digits only) used to encrypt/decrypt strings.
|
||||
*/
|
||||
Configure::write('Security.cipherSeed', '76859309657453542496749683645');
|
||||
|
||||
/**
|
||||
* Apply timestamps with the last modified time to static assets (js, css, images).
|
||||
* Will append a querystring parameter containing the time the file was modified. This is
|
||||
* useful for invalidating browser caches.
|
||||
*
|
||||
* Set to `true` to apply timestamps, when debug = 0, or set to 'force' to always enable
|
||||
* timestamping.
|
||||
*/
|
||||
//Configure::write('Asset.timestamp', true);
|
||||
/**
|
||||
* Compress CSS output by removing comments, whitespace, repeating tags, etc.
|
||||
* This requires a/var/cache directory to be writable by the web server for caching.
|
||||
* and /vendors/csspp/csspp.php
|
||||
*
|
||||
* To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use HtmlHelper::css().
|
||||
*/
|
||||
//Configure::write('Asset.filter.css', 'css.php');
|
||||
|
||||
/**
|
||||
* Plug in your own custom JavaScript compressor by dropping a script in your webroot to handle the
|
||||
* output, and setting the config below to the name of the script.
|
||||
*
|
||||
* To use, prefix your JavaScript link URLs with '/cjs/' instead of '/js/' or use JavaScriptHelper::link().
|
||||
*/
|
||||
//Configure::write('Asset.filter.js', 'custom_javascript_output_filter.php');
|
||||
|
||||
/**
|
||||
* The classname and database used in CakePHP's
|
||||
* access control lists.
|
||||
*/
|
||||
Configure::write('Acl.classname', 'DbAcl');
|
||||
Configure::write('Acl.database', 'default');
|
||||
|
||||
/**
|
||||
* If you are on PHP 5.3 uncomment this line and correct your server timezone
|
||||
* to fix the date & time related errors.
|
||||
*/
|
||||
//date_default_timezone_set('UTC');
|
||||
|
||||
/**
|
||||
*
|
||||
* Cache Engine Configuration
|
||||
* Default settings provided below
|
||||
*
|
||||
* File storage engine.
|
||||
*
|
||||
* Cache::config('default', array(
|
||||
* 'engine' => 'File', //[required]
|
||||
* 'duration'=> 3600, //[optional]
|
||||
* 'probability'=> 100, //[optional]
|
||||
* 'path' => CACHE, //[optional] use system tmp directory - remember to use absolute path
|
||||
* 'prefix' => 'cake_', //[optional] prefix every cache file with this string
|
||||
* 'lock' => false, //[optional] use file locking
|
||||
* 'serialize' => true, [optional]
|
||||
* ));
|
||||
*
|
||||
*
|
||||
* APC (http://pecl.php.net/package/APC)
|
||||
*
|
||||
* Cache::config('default', array(
|
||||
* 'engine' => 'Apc', //[required]
|
||||
* 'duration'=> 3600, //[optional]
|
||||
* 'probability'=> 100, //[optional]
|
||||
* 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
|
||||
* ));
|
||||
*
|
||||
* Xcache (http://xcache.lighttpd.net/)
|
||||
*
|
||||
* Cache::config('default', array(
|
||||
* 'engine' => 'Xcache', //[required]
|
||||
* 'duration'=> 3600, //[optional]
|
||||
* 'probability'=> 100, //[optional]
|
||||
* 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
|
||||
* 'user' => 'user', //user from xcache.admin.user settings
|
||||
* 'password' => 'password', //plaintext password (xcache.admin.pass)
|
||||
* ));
|
||||
*
|
||||
*
|
||||
* Memcache (http://www.danga.com/memcached/)
|
||||
*
|
||||
* Cache::config('default', array(
|
||||
* 'engine' => 'Memcache', //[required]
|
||||
* 'duration'=> 3600, //[optional]
|
||||
* 'probability'=> 100, //[optional]
|
||||
* 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
|
||||
* 'servers' => array(
|
||||
* '127.0.0.1:11211' // localhost, default port 11211
|
||||
* ), //[optional]
|
||||
* 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
|
||||
* ));
|
||||
*
|
||||
*/
|
||||
Cache::config('default', array('engine' => 'File'));
|
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* This is core configuration file.
|
||||
*
|
||||
* Use it to configure core behaviour ofCake.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
/**
|
||||
* In this file you set up your database connection details.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.config
|
||||
*/
|
||||
/**
|
||||
* Database configuration class.
|
||||
* You can specify multiple configurations for production, development and testing.
|
||||
*
|
||||
* driver => The name of a supported driver; valid options are as follows:
|
||||
* mysql - MySQL 4 & 5,
|
||||
* mysqli - MySQL 4 & 5 Improved Interface (PHP5 only),
|
||||
* sqlite - SQLite (PHP5 only),
|
||||
* postgres - PostgreSQL 7 and higher,
|
||||
* mssql - Microsoft SQL Server 2000 and higher,
|
||||
* db2 - IBM DB2, Cloudscape, and Apache Derby (http://php.net/ibm-db2)
|
||||
* oracle - Oracle 8 and higher
|
||||
* firebird - Firebird/Interbase
|
||||
* sybase - Sybase ASE
|
||||
* adodb-[drivername] - ADOdb interface wrapper (see below),
|
||||
* odbc - ODBC DBO driver
|
||||
*
|
||||
* You can add custom database drivers (or override existing drivers) by adding the
|
||||
* appropriate file to app/models/datasources/dbo. Drivers should be named 'dbo_x.php',
|
||||
* where 'x' is the name of the database.
|
||||
*
|
||||
* persistent => true / false
|
||||
* Determines whether or not the database should use a persistent connection
|
||||
*
|
||||
* connect =>
|
||||
* ADOdb set the connect to one of these
|
||||
* (http://phplens.com/adodb/supported.databases.html) and
|
||||
* append it '|p' for persistent connection. (mssql|p for example, or just mssql for not persistent)
|
||||
* For all other databases, this setting is deprecated.
|
||||
*
|
||||
* host =>
|
||||
* the host you connect to the database. To add a socket or port number, use 'port' => #
|
||||
*
|
||||
* prefix =>
|
||||
* Uses the given prefix for all the tables in this database. This setting can be overridden
|
||||
* on a per-table basis with the Model::$tablePrefix property.
|
||||
*
|
||||
* schema =>
|
||||
* For Postgres and DB2, specifies which schema you would like to use the tables in. Postgres defaults to
|
||||
* 'public', DB2 defaults to empty.
|
||||
*
|
||||
* encoding =>
|
||||
* For MySQL, MySQLi, Postgres and DB2, specifies the character encoding to use when connecting to the
|
||||
* database. Uses database default.
|
||||
*
|
||||
*/
|
||||
class DATABASE_CONFIG {
|
||||
|
||||
var $default = array(
|
||||
'driver' => 'mysql',
|
||||
'persistent' => false,
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'database_name',
|
||||
'prefix' => '',
|
||||
);
|
||||
|
||||
var $test = array(
|
||||
'driver' => 'mysql',
|
||||
'persistent' => false,
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'test_database_name',
|
||||
'prefix' => '',
|
||||
);
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Routes Configuration
|
||||
*
|
||||
* In this file, you set up routes to your controllers and their actions.
|
||||
* Routes are very important mechanism that allows you to freely connect
|
||||
* different urls to chosen controllers and their actions (functions).
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Here, we are connecting '/' (base path) to controller called 'Pages',
|
||||
* its action called 'display', and we pass a param to select the view file
|
||||
* to use (in this case, /app/views/pages/home.ctp)...
|
||||
*/
|
||||
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
||||
|
||||
/**
|
||||
* ...and connect the rest of 'Pages' controller's urls.
|
||||
*/
|
||||
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/*DbAcl schema generated on: 2007-11-24 15:11:13 : 1195945453*/
|
||||
|
||||
/**
|
||||
* This is Acl Schema file
|
||||
*
|
||||
* Use it to configure database for ACL
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config.sql
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Using the Schema command line utility
|
||||
* cake schema run create DbAcl
|
||||
*
|
||||
*/
|
||||
class DbAclSchema extends CakeSchema {
|
||||
|
||||
var $name = 'DbAcl';
|
||||
|
||||
function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function after($event = array()) {
|
||||
}
|
||||
|
||||
var $acos = array(
|
||||
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
|
||||
'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
'model' => array('type'=>'string', 'null' => true),
|
||||
'foreign_key' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
'alias' => array('type'=>'string', 'null' => true),
|
||||
'lft' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
'rght' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
|
||||
);
|
||||
|
||||
var $aros = array(
|
||||
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
|
||||
'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
'model' => array('type'=>'string', 'null' => true),
|
||||
'foreign_key' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
'alias' => array('type'=>'string', 'null' => true),
|
||||
'lft' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
'rght' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
|
||||
);
|
||||
|
||||
var $aros_acos = array(
|
||||
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
|
||||
'aro_id' => array('type'=>'integer', 'null' => false, 'length' => 10, 'key' => 'index'),
|
||||
'aco_id' => array('type'=>'integer', 'null' => false, 'length' => 10),
|
||||
'_create' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),
|
||||
'_read' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),
|
||||
'_update' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),
|
||||
'_delete' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'ARO_ACO_KEY' => array('column' => array('aro_id', 'aco_id'), 'unique' => 1))
|
||||
);
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
# $Id$
|
||||
#
|
||||
# Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
#
|
||||
# Licensed under The MIT License
|
||||
# Redistributions of files must retain the above copyright notice.
|
||||
# MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
CREATE TABLE acos (
|
||||
id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
parent_id INTEGER(10) DEFAULT NULL,
|
||||
model VARCHAR(255) DEFAULT '',
|
||||
foreign_key INTEGER(10) UNSIGNED DEFAULT NULL,
|
||||
alias VARCHAR(255) DEFAULT '',
|
||||
lft INTEGER(10) DEFAULT NULL,
|
||||
rght INTEGER(10) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE aros_acos (
|
||||
id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
aro_id INTEGER(10) UNSIGNED NOT NULL,
|
||||
aco_id INTEGER(10) UNSIGNED NOT NULL,
|
||||
_create CHAR(2) NOT NULL DEFAULT 0,
|
||||
_read CHAR(2) NOT NULL DEFAULT 0,
|
||||
_update CHAR(2) NOT NULL DEFAULT 0,
|
||||
_delete CHAR(2) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
|
||||
CREATE TABLE aros (
|
||||
id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
parent_id INTEGER(10) DEFAULT NULL,
|
||||
model VARCHAR(255) DEFAULT '',
|
||||
foreign_key INTEGER(10) UNSIGNED DEFAULT NULL,
|
||||
alias VARCHAR(255) DEFAULT '',
|
||||
lft INTEGER(10) DEFAULT NULL,
|
||||
rght INTEGER(10) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*i18n schema generated on: 2007-11-25 07:11:25 : 1196004805*/
|
||||
|
||||
/**
|
||||
* This is i18n Schema file
|
||||
*
|
||||
* Use it to configure database for i18n
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config.sql
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Using the Schema command line utility
|
||||
* cake schema run create i18n
|
||||
*
|
||||
*/
|
||||
class i18nSchema extends CakeSchema {
|
||||
|
||||
var $name = 'i18n';
|
||||
|
||||
function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function after($event = array()) {
|
||||
}
|
||||
|
||||
var $i18n = array(
|
||||
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
|
||||
'locale' => array('type'=>'string', 'null' => false, 'length' => 6, 'key' => 'index'),
|
||||
'model' => array('type'=>'string', 'null' => false, 'key' => 'index'),
|
||||
'foreign_key' => array('type'=>'integer', 'null' => false, 'length' => 10, 'key' => 'index'),
|
||||
'field' => array('type'=>'string', 'null' => false, 'key' => 'index'),
|
||||
'content' => array('type'=>'text', 'null' => true, 'default' => NULL),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'locale' => array('column' => 'locale', 'unique' => 0), 'model' => array('column' => 'model', 'unique' => 0), 'row_id' => array('column' => 'foreign_key', 'unique' => 0), 'field' => array('column' => 'field', 'unique' => 0))
|
||||
);
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
# $Id$
|
||||
#
|
||||
# Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
#
|
||||
# Licensed under The MIT License
|
||||
# Redistributions of files must retain the above copyright notice.
|
||||
# MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
CREATE TABLE i18n (
|
||||
id int(10) NOT NULL auto_increment,
|
||||
locale varchar(6) NOT NULL,
|
||||
model varchar(255) NOT NULL,
|
||||
foreign_key int(10) NOT NULL,
|
||||
field varchar(255) NOT NULL,
|
||||
content mediumtext,
|
||||
PRIMARY KEY (id),
|
||||
# UNIQUE INDEX I18N_LOCALE_FIELD(locale, model, foreign_key, field),
|
||||
# INDEX I18N_LOCALE_ROW(locale, model, foreign_key),
|
||||
# INDEX I18N_LOCALE_MODEL(locale, model),
|
||||
# INDEX I18N_FIELD(model, foreign_key, field),
|
||||
# INDEX I18N_ROW(model, foreign_key),
|
||||
INDEX locale (locale),
|
||||
INDEX model (model),
|
||||
INDEX row_id (foreign_key),
|
||||
INDEX field (field)
|
||||
);
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*Sessions schema generated on: 2007-11-25 07:11:54 : 1196004714*/
|
||||
|
||||
/**
|
||||
* This is Sessions Schema file
|
||||
*
|
||||
* Use it to configure database for Sessions
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config.sql
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Using the Schema command line utility
|
||||
* cake schema run create Sessions
|
||||
*
|
||||
*/
|
||||
class SessionsSchema extends CakeSchema {
|
||||
|
||||
var $name = 'Sessions';
|
||||
|
||||
function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function after($event = array()) {
|
||||
}
|
||||
|
||||
var $cake_sessions = array(
|
||||
'id' => array('type'=>'string', 'null' => false, 'key' => 'primary'),
|
||||
'data' => array('type'=>'text', 'null' => true, 'default' => NULL),
|
||||
'expires' => array('type'=>'integer', 'null' => true, 'default' => NULL),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
|
||||
);
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
# $Id$
|
||||
#
|
||||
# Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
# 1785 E. Sahara Avenue, Suite 490-204
|
||||
# Las Vegas, Nevada 89104
|
||||
#
|
||||
# Licensed under The MIT License
|
||||
# Redistributions of files must retain the above copyright notice.
|
||||
# MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
CREATE TABLE cake_sessions (
|
||||
id varchar(255) NOT NULL default '',
|
||||
data text,
|
||||
expires int(11) default NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Static content controller.
|
||||
*
|
||||
* This file will render views from views/pages/
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.controller
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Static content controller
|
||||
*
|
||||
* Override this controller by placing a copy in controllers directory of an application
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.controller
|
||||
*/
|
||||
class PagesController extends AppController {
|
||||
|
||||
/**
|
||||
* Controller name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'Pages';
|
||||
|
||||
/**
|
||||
* Default helper
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $helpers = array('Html');
|
||||
|
||||
/**
|
||||
* This controller does not use a model
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array();
|
||||
|
||||
/**
|
||||
* Displays a view
|
||||
*
|
||||
* @param mixed What page to display
|
||||
* @access public
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
require 'webroot' . DIRECTORY_SEPARATOR . 'index.php';
|
0
php-practice/web-cake/html/cake/console/templates/skel/tests/fixtures/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/tests/fixtures/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/tmp/cache/models/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/tmp/cache/models/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/tmp/cache/persistent/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/tmp/cache/persistent/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/tmp/cache/views/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/tmp/cache/views/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/vendors/shells/tasks/empty
vendored
Normal file
0
php-practice/web-cake/html/cake/console/templates/skel/vendors/shells/tasks/empty
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.elements.email.html
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<?php
|
||||
$content = explode("\n", $content);
|
||||
|
||||
foreach ($content as $line):
|
||||
echo '<p> ' . $line . '</p>';
|
||||
endforeach;
|
||||
?>
|
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.elements.email.text
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<?php echo $content; ?>
|
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<?php echo $content_for_layout; ?>
|
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.templates.skel.views.layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<?php echo $this->Html->charset(); ?>
|
||||
<title>
|
||||
<?php __('CakePHP: the rapid development php framework:'); ?>
|
||||
<?php echo $title_for_layout; ?>
|
||||
</title>
|
||||
<?php
|
||||
echo $this->Html->meta('icon');
|
||||
|
||||
echo $this->Html->css('cake.generic');
|
||||
|
||||
echo $scripts_for_layout;
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="header">
|
||||
<h1><?php echo $this->Html->link(__('CakePHP: the rapid development php framework', true), 'http://cakephp.org'); ?></h1>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
||||
<?php echo $this->Session->flash(); ?>
|
||||
|
||||
<?php echo $content_for_layout; ?>
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<?php echo $this->Html->link(
|
||||
$this->Html->image('cake.power.gif', array('alt'=> __('CakePHP: the rapid development php framework', true), 'border' => '0')),
|
||||
'http://www.cakephp.org/',
|
||||
array('target' => '_blank', 'escape' => false)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo $this->element('sql_dump'); ?>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts.email.html
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo $title_for_layout;?></title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php echo $content_for_layout;?>
|
||||
|
||||
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts.email.text
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
|
||||
<?php echo $content_for_layout;?>
|
||||
|
||||
This email was sent using the CakePHP Framework, http://cakephp.org.
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<?php echo $this->Html->charset(); ?>
|
||||
<title><?php echo $page_title; ?></title>
|
||||
|
||||
<?php if (Configure::read() == 0) { ?>
|
||||
<meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/>
|
||||
<?php } ?>
|
||||
<style><!--
|
||||
P { text-align:center; font:bold 1.1em sans-serif }
|
||||
A { color:#444; text-decoration:none }
|
||||
A:HOVER { text-decoration: underline; color:#44E }
|
||||
--></style>
|
||||
</head>
|
||||
<body>
|
||||
<p><a href="<?php echo $url?>"><?php echo $message?></a></p>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,2 @@
|
||||
<?php echo $scripts_for_layout; ?>
|
||||
<script type="text/javascript"><?php echo $content_for_layout; ?></script>
|
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
echo $rss->header();
|
||||
|
||||
if (!isset($channel)) {
|
||||
$channel = array();
|
||||
}
|
||||
if (!isset($channel['title'])) {
|
||||
$channel['title'] = $title_for_layout;
|
||||
}
|
||||
|
||||
echo $rss->document(
|
||||
$rss->channel(
|
||||
array(), $channel, $content_for_layout
|
||||
)
|
||||
);
|
||||
|
||||
?>
|
@@ -0,0 +1,2 @@
|
||||
<?php echo $xml->header(); ?>
|
||||
<?php echo $content_for_layout; ?>
|
@@ -0,0 +1,6 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
|
||||
</IfModule>
|
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* CSS Functions
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.webroot
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
exit('File Not Found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure required files are included
|
||||
*/
|
||||
if (!class_exists('File')) {
|
||||
require LIBS . 'file.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Make clean CSS
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write CSS cache
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @param unknown_type $content
|
||||
* @return unknown
|
||||
*/
|
||||
function write_css_cache($path, $content) {
|
||||
if (!is_dir(dirname($path))) {
|
||||
mkdir(dirname($path));
|
||||
}
|
||||
$cache = new File($path);
|
||||
return $cache->write($content);
|
||||
}
|
||||
|
||||
if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
|
||||
exit('Wrong file name.');
|
||||
}
|
||||
|
||||
$filename = 'css/' . $regs[1];
|
||||
$filepath = CSS . $regs[1];
|
||||
$cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
|
||||
|
||||
if (!file_exists($filepath)) {
|
||||
exit('Wrong file name.');
|
||||
}
|
||||
|
||||
if (file_exists($cachepath)) {
|
||||
$templateModified = filemtime($filepath);
|
||||
$cacheModified = filemtime($cachepath);
|
||||
|
||||
if ($templateModified > $cacheModified) {
|
||||
$output = make_clean_css($filepath, $filename);
|
||||
write_css_cache($cachepath, $output);
|
||||
} else {
|
||||
$output = file_get_contents($cachepath);
|
||||
}
|
||||
} else {
|
||||
$output = make_clean_css($filepath, $filename);
|
||||
write_css_cache($cachepath, $output);
|
||||
$templateModified = time();
|
||||
}
|
||||
|
||||
header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
|
||||
header("Content-Type: text/css");
|
||||
header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
|
||||
header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
|
||||
header("Pragma: cache"); // HTTP/1.0
|
||||
print $output;
|
@@ -0,0 +1,535 @@
|
||||
/**
|
||||
*
|
||||
* Generic CSS for CakePHP
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.webroot.css
|
||||
* @since CakePHP(tm)
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
* {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
/** General Style Info **/
|
||||
body {
|
||||
background: #003d4c;
|
||||
color: #fff;
|
||||
font-family:'lucida grande',verdana,helvetica,arial,sans-serif;
|
||||
font-size:90%;
|
||||
margin: 0;
|
||||
}
|
||||
a {
|
||||
color: #003d4c;
|
||||
text-decoration: underline;
|
||||
font-weight: bold;
|
||||
}
|
||||
a:hover {
|
||||
color: #367889;
|
||||
text-decoration:none;
|
||||
}
|
||||
a img {
|
||||
border:none;
|
||||
}
|
||||
h1, h2, h3, h4 {
|
||||
font-weight: normal;
|
||||
margin-bottom:0.5em;
|
||||
}
|
||||
h1 {
|
||||
background:#fff;
|
||||
color: #003d4c;
|
||||
font-size: 100%;
|
||||
}
|
||||
h2 {
|
||||
background:#fff;
|
||||
color: #e32;
|
||||
font-family:'Gill Sans','lucida grande', helvetica, arial, sans-serif;
|
||||
font-size: 190%;
|
||||
}
|
||||
h3 {
|
||||
color: #993;
|
||||
font-family:'Gill Sans','lucida grande', helvetica, arial, sans-serif;
|
||||
font-size: 165%;
|
||||
}
|
||||
h4 {
|
||||
color: #993;
|
||||
font-weight: normal;
|
||||
}
|
||||
ul, li {
|
||||
margin: 0 12px;
|
||||
}
|
||||
|
||||
/** Layout **/
|
||||
#container {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#header{
|
||||
padding: 10px 20px;
|
||||
}
|
||||
#header h1 {
|
||||
line-height:20px;
|
||||
background: #003d4c url('../img/cake.icon.png') no-repeat left;
|
||||
color: #fff;
|
||||
padding: 0px 30px;
|
||||
}
|
||||
#header h1 a {
|
||||
color: #fff;
|
||||
background: #003d4c;
|
||||
font-weight: normal;
|
||||
text-decoration: none;
|
||||
}
|
||||
#header h1 a:hover {
|
||||
color: #fff;
|
||||
background: #003d4c;
|
||||
text-decoration: underline;
|
||||
}
|
||||
#content{
|
||||
background: #fff;
|
||||
clear: both;
|
||||
color: #333;
|
||||
padding: 10px 20px 40px 20px;
|
||||
overflow: auto;
|
||||
}
|
||||
#footer {
|
||||
clear: both;
|
||||
padding: 6px 10px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/** containers **/
|
||||
div.form,
|
||||
div.index,
|
||||
div.view {
|
||||
float:right;
|
||||
width:76%;
|
||||
border-left:1px solid #666;
|
||||
padding:10px 2%;
|
||||
}
|
||||
div.actions {
|
||||
float:left;
|
||||
width:16%;
|
||||
padding:10px 1.5%;
|
||||
}
|
||||
div.actions h3 {
|
||||
padding-top:0;
|
||||
color:#777;
|
||||
}
|
||||
|
||||
|
||||
/** Tables **/
|
||||
table {
|
||||
background: #fff;
|
||||
border-right:0;
|
||||
clear: both;
|
||||
color: #333;
|
||||
margin-bottom: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
th {
|
||||
border:0;
|
||||
border-bottom:2px solid #555;
|
||||
text-align: left;
|
||||
padding:4px;
|
||||
}
|
||||
th a {
|
||||
display: block;
|
||||
padding: 2px 4px;
|
||||
text-decoration: none;
|
||||
}
|
||||
th a.asc:after {
|
||||
content: ' ⇣';
|
||||
}
|
||||
th a.desc:after {
|
||||
content: ' ⇡';
|
||||
}
|
||||
table tr td {
|
||||
background: #fff;
|
||||
padding: 6px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
border-bottom:1px solid #ddd;
|
||||
}
|
||||
table tr:nth-child(2n) td {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
table .altrow td {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
td.actions {
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
table td.actions a {
|
||||
margin: 0px 6px;
|
||||
padding:2px 5px;
|
||||
}
|
||||
.cake-sql-log table {
|
||||
background: #f4f4f4;
|
||||
}
|
||||
.cake-sql-log td {
|
||||
padding: 4px 8px;
|
||||
text-align: left;
|
||||
font-family: Monaco, Consolas, "Courier New", monospaced;
|
||||
}
|
||||
.cake-sql-log caption {
|
||||
color:#fff;
|
||||
}
|
||||
|
||||
/** Paging **/
|
||||
div.paging {
|
||||
background:#fff;
|
||||
color: #ccc;
|
||||
margin-top: 1em;
|
||||
clear:both;
|
||||
}
|
||||
div.paging span.disabled {
|
||||
color: #ddd;
|
||||
display: inline;
|
||||
}
|
||||
div.paging span.current {
|
||||
color: #c73e14;
|
||||
}
|
||||
div.paging span a {
|
||||
}
|
||||
|
||||
/** Scaffold View **/
|
||||
dl {
|
||||
line-height: 2em;
|
||||
margin: 0em 0em;
|
||||
width: 60%;
|
||||
}
|
||||
dl .altrow {
|
||||
background: #f4f4f4;
|
||||
}
|
||||
dt {
|
||||
font-weight: bold;
|
||||
padding-left: 4px;
|
||||
vertical-align: top;
|
||||
}
|
||||
dd {
|
||||
margin-left: 10em;
|
||||
margin-top: -2em;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
/** Forms **/
|
||||
form {
|
||||
clear: both;
|
||||
margin-right: 20px;
|
||||
padding: 0;
|
||||
width: 95%;
|
||||
}
|
||||
fieldset {
|
||||
border: 1px solid #ccc;
|
||||
margin-bottom: 1em;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
fieldset legend {
|
||||
background:#fff;
|
||||
color: #e32;
|
||||
font-size: 160%;
|
||||
font-weight: bold;
|
||||
}
|
||||
fieldset fieldset {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 20px;
|
||||
padding: 16px 10px;
|
||||
}
|
||||
fieldset fieldset legend {
|
||||
font-size: 120%;
|
||||
font-weight: normal;
|
||||
}
|
||||
fieldset fieldset div {
|
||||
clear: left;
|
||||
margin: 0 20px;
|
||||
}
|
||||
form div {
|
||||
clear: both;
|
||||
margin-bottom: 1em;
|
||||
padding: .5em;
|
||||
vertical-align: text-top;
|
||||
}
|
||||
form .input {
|
||||
color: #444;
|
||||
}
|
||||
form .required {
|
||||
font-weight: bold;
|
||||
}
|
||||
form .required label:after {
|
||||
color: #e32;
|
||||
content: '*';
|
||||
display:inline;
|
||||
}
|
||||
form div.submit {
|
||||
border: 0;
|
||||
clear: both;
|
||||
margin-top: 10px;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
font-size: 110%;
|
||||
margin-bottom:3px;
|
||||
}
|
||||
input, textarea {
|
||||
clear: both;
|
||||
font-size: 140%;
|
||||
font-family: "frutiger linotype", "lucida grande", "verdana", sans-serif;
|
||||
padding: 1%;
|
||||
width:98%;
|
||||
}
|
||||
select {
|
||||
clear: both;
|
||||
font-size: 120%;
|
||||
vertical-align: text-bottom;
|
||||
}
|
||||
select[multiple=multiple] {
|
||||
width: 100%;
|
||||
}
|
||||
option {
|
||||
font-size: 120%;
|
||||
padding: 0 3px;
|
||||
}
|
||||
input[type=checkbox] {
|
||||
clear: left;
|
||||
float: left;
|
||||
margin: 0px 6px 7px 2px;
|
||||
width: auto;
|
||||
}
|
||||
div.checkbox label {
|
||||
display: inline;
|
||||
}
|
||||
input[type=radio] {
|
||||
float:left;
|
||||
width:auto;
|
||||
margin: 0 3px 7px 0;
|
||||
}
|
||||
div.radio label {
|
||||
margin: 0 0 6px 20px;
|
||||
}
|
||||
input[type=submit] {
|
||||
display: inline;
|
||||
font-size: 110%;
|
||||
width: auto;
|
||||
}
|
||||
form .submit input[type=submit] {
|
||||
background:#62af56;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#a8ea9c), to(#62af56));
|
||||
background-image: -moz-linear-gradient(top, #a8ea9c, #62af56);
|
||||
border-color: #2d6324;
|
||||
color: #000;
|
||||
text-shadow: #8cee7c 0px 1px 0px;
|
||||
}
|
||||
form .submit input[type=submit]:hover {
|
||||
background:#4ca83d;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#85e573), to(#4ca83d));
|
||||
background-image: -moz-linear-gradient(top, #85e573, #4ca83d);
|
||||
}
|
||||
|
||||
/** Notices and Errors **/
|
||||
div.message {
|
||||
clear: both;
|
||||
color: #fff;
|
||||
font-size: 140%;
|
||||
font-weight: bold;
|
||||
margin: 0 0 1em 0;
|
||||
background: #c73e14;
|
||||
padding: 5px;
|
||||
}
|
||||
div.error-message {
|
||||
clear: both;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
background: #c73e14;
|
||||
}
|
||||
p.error {
|
||||
background-color: #e32;
|
||||
color: #fff;
|
||||
font-family: Courier, monospace;
|
||||
font-size: 120%;
|
||||
line-height: 140%;
|
||||
padding: 0.8em;
|
||||
margin: 1em 0;
|
||||
}
|
||||
p.error em {
|
||||
color: #000;
|
||||
font-weight: normal;
|
||||
line-height: 140%;
|
||||
}
|
||||
.notice {
|
||||
background: #ffcc00;
|
||||
color: #000;
|
||||
display: block;
|
||||
font-family: Courier, monospace;
|
||||
font-size: 120%;
|
||||
line-height: 140%;
|
||||
padding: 0.8em;
|
||||
margin: 1em 0;
|
||||
}
|
||||
.success {
|
||||
background: green;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/** Actions **/
|
||||
div.actions ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
div.actions li {
|
||||
margin:0 0 0.5em 0;
|
||||
list-style-type: none;
|
||||
white-space: nowrap;
|
||||
padding: 0;
|
||||
}
|
||||
div.actions ul li a {
|
||||
font-weight: normal;
|
||||
display: block;
|
||||
clear: both;
|
||||
}
|
||||
div.actions ul li a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
input[type=submit],
|
||||
div.actions ul li a,
|
||||
td.actions a {
|
||||
font-weight:normal;
|
||||
padding: 4px 8px;
|
||||
background:#e6e49f;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#f1f1d4), to(#e6e49f));
|
||||
background-image: -moz-linear-gradient(top, #f1f1d4, #e6e49f);
|
||||
color:#333;
|
||||
border:1px solid #aaac62;
|
||||
-webkit-border-radius:8px;
|
||||
-moz-border-radius:8px;
|
||||
border-radius:8px;
|
||||
text-decoration:none;
|
||||
text-shadow: #fff 0px 1px 0px;
|
||||
min-width: 0;
|
||||
}
|
||||
input[type=submit]:hover,
|
||||
div.actions ul li a:hover,
|
||||
td.actions a:hover {
|
||||
background: #f0f09a;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#f7f7e1), to(#eeeca9));
|
||||
}
|
||||
|
||||
/** Related **/
|
||||
div.related {
|
||||
clear: both;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/** Debugging **/
|
||||
pre {
|
||||
color: #000;
|
||||
background: #f0f0f0;
|
||||
padding: 1em;
|
||||
}
|
||||
pre.cake-debug {
|
||||
background: #ffcc00;
|
||||
font-size: 120%;
|
||||
line-height: 140%;
|
||||
margin-top: 1em;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
}
|
||||
div.cake-stack-trace {
|
||||
background: #fff;
|
||||
color: #333;
|
||||
margin: 0px;
|
||||
padding: 6px;
|
||||
font-size: 120%;
|
||||
line-height: 140%;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
}
|
||||
div.cake-code-dump pre {
|
||||
position: relative;
|
||||
overflow: auto;
|
||||
}
|
||||
div.cake-stack-trace pre, div.cake-code-dump pre {
|
||||
color: #000;
|
||||
background-color: #F0F0F0;
|
||||
margin: 0px;
|
||||
padding: 1em;
|
||||
overflow: auto;
|
||||
}
|
||||
div.cake-code-dump pre, div.cake-code-dump pre code {
|
||||
clear: both;
|
||||
font-size: 12px;
|
||||
line-height: 15px;
|
||||
margin: 4px 2px;
|
||||
padding: 4px;
|
||||
overflow: auto;
|
||||
}
|
||||
div.cake-code-dump span.code-highlight {
|
||||
background-color: #ff0;
|
||||
padding: 4px;
|
||||
}
|
||||
div.code-coverage-results div.code-line {
|
||||
padding-left:5px;
|
||||
display:block;
|
||||
margin-left:10px;
|
||||
}
|
||||
div.code-coverage-results div.uncovered span.content {
|
||||
background:#ecc;
|
||||
}
|
||||
div.code-coverage-results div.covered span.content {
|
||||
background:#cec;
|
||||
}
|
||||
div.code-coverage-results div.ignored span.content {
|
||||
color:#aaa;
|
||||
}
|
||||
div.code-coverage-results span.line-num {
|
||||
color:#666;
|
||||
display:block;
|
||||
float:left;
|
||||
width:20px;
|
||||
text-align:right;
|
||||
margin-right:5px;
|
||||
}
|
||||
div.code-coverage-results span.line-num strong {
|
||||
color:#666;
|
||||
}
|
||||
div.code-coverage-results div.start {
|
||||
border:1px solid #aaa;
|
||||
border-width:1px 1px 0px 1px;
|
||||
margin-top:30px;
|
||||
padding-top:5px;
|
||||
}
|
||||
div.code-coverage-results div.end {
|
||||
border:1px solid #aaa;
|
||||
border-width:0px 1px 1px 1px;
|
||||
margin-bottom:30px;
|
||||
padding-bottom:5px;
|
||||
}
|
||||
div.code-coverage-results div.realstart {
|
||||
margin-top:0px;
|
||||
}
|
||||
div.code-coverage-results p.note {
|
||||
color:#bbb;
|
||||
padding:5px;
|
||||
margin:5px 0 10px;
|
||||
font-size:10px;
|
||||
}
|
||||
div.code-coverage-results span.result-bad {
|
||||
color: #a00;
|
||||
}
|
||||
div.code-coverage-results span.result-ok {
|
||||
color: #fa0;
|
||||
}
|
||||
div.code-coverage-results span.result-good {
|
||||
color: #0a0;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 372 B |
Binary file not shown.
After Width: | Height: | Size: 943 B |
Binary file not shown.
After Width: | Height: | Size: 201 B |
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Index
|
||||
*
|
||||
* The Front Controller for handling every request
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.webroot
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
/**
|
||||
* Use the DS to separate the directories in other defines
|
||||
*/
|
||||
if (!defined('DS')) {
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
}
|
||||
/**
|
||||
* These defines should only be edited if you have cake installed in
|
||||
* a directory layout other than the way it is distributed.
|
||||
* When using custom settings be sure to use the DS and do not add a trailing DS.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The full path to the directory which holds "app", WITHOUT a trailing DS.
|
||||
*
|
||||
*/
|
||||
if (!defined('ROOT')) {
|
||||
define('ROOT', dirname(dirname(dirname(__FILE__))));
|
||||
}
|
||||
/**
|
||||
* The actual directory name for the "app".
|
||||
*
|
||||
*/
|
||||
if (!defined('APP_DIR')) {
|
||||
define('APP_DIR', basename(dirname(dirname(__FILE__))));
|
||||
}
|
||||
/**
|
||||
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
|
||||
*
|
||||
*/
|
||||
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
||||
define('CAKE_CORE_INCLUDE_PATH', ROOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Editing below this line should NOT be necessary.
|
||||
* Change at your own risk.
|
||||
*
|
||||
*/
|
||||
if (!defined('WEBROOT_DIR')) {
|
||||
define('WEBROOT_DIR', basename(dirname(__FILE__)));
|
||||
}
|
||||
if (!defined('WWW_ROOT')) {
|
||||
define('WWW_ROOT', dirname(__FILE__) . DS);
|
||||
}
|
||||
if (!defined('CORE_PATH')) {
|
||||
if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
|
||||
define('APP_PATH', null);
|
||||
define('CORE_PATH', null);
|
||||
} else {
|
||||
define('APP_PATH', ROOT . DS . APP_DIR . DS);
|
||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
||||
}
|
||||
}
|
||||
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
|
||||
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
|
||||
}
|
||||
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
|
||||
return;
|
||||
} else {
|
||||
$Dispatcher = new Dispatcher();
|
||||
$Dispatcher->dispatch();
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Web Access Frontend for TestSuite
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.cake.tests.libs
|
||||
* @since CakePHP(tm) v 1.2.0.4433
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
set_time_limit(0);
|
||||
ini_set('display_errors', 1);
|
||||
/**
|
||||
* Use the DS to separate the directories in other defines
|
||||
*/
|
||||
if (!defined('DS')) {
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
}
|
||||
/**
|
||||
* These defines should only be edited if you have cake installed in
|
||||
* a directory layout other than the way it is distributed.
|
||||
* When using custom settings be sure to use the DS and do not add a trailing DS.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The full path to the directory which holds "app", WITHOUT a trailing DS.
|
||||
*
|
||||
*/
|
||||
if (!defined('ROOT')) {
|
||||
define('ROOT', dirname(dirname(dirname(__FILE__))));
|
||||
}
|
||||
/**
|
||||
* The actual directory name for the "app".
|
||||
*
|
||||
*/
|
||||
if (!defined('APP_DIR')) {
|
||||
define('APP_DIR', basename(dirname(dirname(__FILE__))));
|
||||
}
|
||||
/**
|
||||
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
|
||||
*
|
||||
*/
|
||||
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
||||
define('CAKE_CORE_INCLUDE_PATH', ROOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Editing below this line should not be necessary.
|
||||
* Change at your own risk.
|
||||
*
|
||||
*/
|
||||
if (!defined('WEBROOT_DIR')) {
|
||||
define('WEBROOT_DIR', basename(dirname(__FILE__)));
|
||||
}
|
||||
if (!defined('WWW_ROOT')) {
|
||||
define('WWW_ROOT', dirname(__FILE__) . DS);
|
||||
}
|
||||
if (!defined('CORE_PATH')) {
|
||||
if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
|
||||
define('APP_PATH', null);
|
||||
define('CORE_PATH', null);
|
||||
} else {
|
||||
define('APP_PATH', ROOT . DS . APP_DIR . DS);
|
||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
||||
}
|
||||
}
|
||||
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
|
||||
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$corePath = App::core('cake');
|
||||
if (isset($corePath[0])) {
|
||||
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
|
||||
} else {
|
||||
define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
|
||||
}
|
||||
|
||||
if (Configure::read('debug') < 1) {
|
||||
die(__('Debug setting does not allow access to this url.', true));
|
||||
}
|
||||
|
||||
require_once CAKE_TESTS_LIB . 'cake_test_suite_dispatcher.php';
|
||||
|
||||
$Dispatcher = new CakeTestSuiteDispatcher();
|
||||
$Dispatcher->dispatch();
|
Reference in New Issue
Block a user