Skip to content

Commit

Permalink
Merge branch '1.3-misc' into 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 26, 2009
2 parents daa97f7 + 03b1089 commit bf551c2
Show file tree
Hide file tree
Showing 18 changed files with 539 additions and 137 deletions.
8 changes: 4 additions & 4 deletions .gitignore
@@ -1,4 +1,4 @@
app/config
app/tmp
plugins
vendors
/app/config
/app/tmp
/plugins
/vendors
90 changes: 48 additions & 42 deletions cake/libs/model/connection_manager.php
Expand Up @@ -25,8 +25,8 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
uses ('model' . DS . 'datasources' . DS . 'datasource');
config('database');
require LIBS . 'model' . DS . 'datasources' . DS . 'datasource.php';
include_once CONFIGS . 'database.php';

/**
* Manages loaded instances of DataSource objects
Expand Down Expand Up @@ -104,18 +104,23 @@ function &getDataSource($name) {
$return =& $_this->_dataSources[$name];
return $return;
}

$connections = $_this->enumConnectionObjects();
if (!empty($connections[$name])) {
$conn = $connections[$name];
$class = $conn['classname'];
$_this->loadDataSource($name);
$_this->_dataSources[$name] =& new $class($_this->config->{$name});
$_this->_dataSources[$name]->configKeyName = $name;
} else {

if (empty($connections[$name])) {
trigger_error(sprintf(__("ConnectionManager::getDataSource - Non-existent data source %s", true), $name), E_USER_ERROR);
return null;
$null = null;
return $null;
}
$conn = $connections[$name];
$class = $conn['classname'];

if ($_this->loadDataSource($name) === null) {
trigger_error(sprintf(__("ConnectionManager::getDataSource - Could not load class %s", true), $class), E_USER_ERROR);
$null = null;
return $null;
}
$_this->_dataSources[$name] =& new $class($_this->config->{$name});
$_this->_dataSources[$name]->configKeyName = $name;

$return =& $_this->_dataSources[$name];
return $return;
Expand All @@ -137,19 +142,14 @@ function sourceList() {
* Gets a DataSource name from an object reference
*
* @param object $source DataSource object
* @return string Datasource name
* @return string Datasource name, or null if source is not present
* in the ConnectionManager.
* @access public
* @static
*/
function getSourceName(&$source) {
$_this =& ConnectionManager::getInstance();
$names = array_keys($_this->_dataSources);
for ($i = 0; $i < count($names); $i++) {
if ($_this->_dataSources[$names[$i]] === $source) {
return $names[$i];
}
}
return null;
return array_search($source, $_this->_dataSources);
}

/**
Expand All @@ -172,23 +172,23 @@ function loadDataSource($connName) {
$conn = $connections[$connName];
}

if (class_exists($conn['classname'])) {
return false;
}

if (!empty($conn['parent'])) {
$_this->loadDataSource($conn['parent']);
}

if (class_exists($conn['classname'])) {
return false;
}
$conn = array_merge(array('plugin' => null, 'classname' => null, 'parent' => null), $conn);
$class = "{$conn['plugin']}.{$conn['classname']}";

if (file_exists(MODELS . 'datasources' . DS . $conn['filename'] . '.php')) {
require (MODELS . 'datasources' . DS . $conn['filename'] . '.php');
} elseif (fileExistsInPath(LIBS . 'model' . DS . 'datasources' . DS . $conn['filename'] . '.php')) {
require (LIBS . 'model' . DS . 'datasources' . DS . $conn['filename'] . '.php');
} else {
$error = __('Unable to load DataSource file %s.php', true);
trigger_error(sprintf($error, $conn['filename']), E_USER_ERROR);
if (!App::import('Datasource', $class, false)) {
$error = __('ConnectionManager::loadDataSource - Unable to import DataSource class %s', true);
trigger_error(sprintf($error, $class), E_USER_ERROR);
return null;
}
return true;
}

/**
Expand All @@ -209,7 +209,7 @@ function enumConnectionObjects() {

if ($connections != null) {
foreach ($connections as $name => $config) {
$_this->_connectionsEnum[$name] = $_this->__getDriver($config);
$_this->_connectionsEnum[$name] = $_this->__connectionData($config);
}
return $_this->_connectionsEnum;
} else {
Expand All @@ -233,34 +233,40 @@ function &create($name = '', $config = array()) {
$null = null;
return $null;
}

$_this->config->{$name} = $config;
$_this->_connectionsEnum[$name] = $_this->__getDriver($config);
$_this->_connectionsEnum[$name] = $_this->__connectionData($config);
$return =& $_this->getDataSource($name);
return $return;
}

/**
* Returns the file, class name, and parent for the given driver.
*
* @return array An indexed array with: filename, classname, and parent
* @return array An indexed array with: filename, classname, plugin and parent
* @access private
*/
function __getDriver($config) {
function __connectionData($config) {
if (!isset($config['datasource'])) {
$config['datasource'] = 'dbo';
}
$filename = $classname = $parent = $plugin = null;

if (isset($config['driver']) && $config['driver'] != null && !empty($config['driver'])) {
$filename = $config['datasource'] . DS . $config['datasource'] . '_' . $config['driver'];
$classname = Inflector::camelize(strtolower($config['datasource'] . '_' . $config['driver']));
$parent = $this->__getDriver(array('datasource' => $config['datasource']));
if (!empty($config['driver'])) {
$source = $config['datasource'] . '_' . $config['driver'];

$filename = $config['datasource'] . DS . $source;
$classname = Inflector::camelize(strtolower($source));
$parent = $this->__connectionData(array('datasource' => $config['datasource']));
} else {
$filename = $config['datasource'] . '_source';
$classname = Inflector::camelize(strtolower($config['datasource'] . '_source'));
$parent = null;
if (strpos($config['datasource'], '.') !== false) {
list($plugin, $classname) = explode('.', $config['datasource']);
$filename = Inflector::underscore($classname);
} else {
$filename = $config['datasource'] . '_source';
$classname = Inflector::camelize(strtolower($filename));
}
}
return array('filename' => $filename, 'classname' => $classname, 'parent' => $parent);
return compact('filename', 'classname', 'parent', 'plugin');
}

/**
Expand Down
56 changes: 44 additions & 12 deletions cake/libs/set.php
Expand Up @@ -373,8 +373,8 @@ function format($data, $format, $keys) {
* Bugs as you find them. Suggestions for additional features to imlement are also very welcome!
*
* @param string $path An absolute XPath 2.0 path
* @param string $data An array of data to extract from
* @param string $options Currently only supports 'flatten' which can be disabled for higher XPath-ness
* @param array $data An array of data to extract from
* @param array $options Currently only supports 'flatten' which can be disabled for higher XPath-ness
* @return array An array of matched items
* @access public
* @static
Expand Down Expand Up @@ -820,14 +820,17 @@ function diff($val1, $val2 = null) {

/**
* Determines if two Sets or arrays are equal
* This method is deprecated, and will be removed in a future release.
*
* @param array $val1 First value
* @param array $val2 Second value
* @return boolean true if they are equal, false otherwise
* @access public
* @static
* @deprecated
*/
function isEqual($val1, $val2 = null) {
trigger_error('Set::isEqual() is deprecated. Please use standard comparison operators instead.', E_USER_WARNING);
return ($val1 == $val2);
}

Expand Down Expand Up @@ -1002,11 +1005,10 @@ function combine($data, $path1 = null, $path2 = null, $groupPath = null) {
}

/**
* Converts an object into an array. If $object is no object, reverse
* will return the same value.
*
* Converts an object into an array.
* @param object $object Object to reverse
* @return array
* @return array Array representation of given object
* @public
* @static
*/
function reverse($object) {
Expand Down Expand Up @@ -1110,10 +1112,10 @@ function __flatten($results, $key = null) {
/**
* Sorts an array by any value, determined by a Set-compatible path
*
* @param array $data
* @param array $data An array of data to sort
* @param string $path A Set-compatible path to the array value
* @param string $dir asc/desc
* @return array
* @param string $dir Direction of sorting - either ascending (ASC), or descending (DESC)
* @return array Sorted array of data
* @static
*/
function sort($data, $path, $dir) {
Expand All @@ -1138,11 +1140,41 @@ function sort($data, $path, $dir) {
}

/**
* Deprecated, Set class should be called statically
* Allows the application of a callback method to elements of an
* array extracted by a Set::extract() compatible path.
*
* @param mixed $path Set-compatible path to the array value
* @param array $data An array of data to extract from & then process with the $callback.
* @param mixed $callback Callback method to be applied to extracted data.
* See http://ca2.php.net/manual/en/language.pseudo-types.php#language.types.callback for examples
* of callback formats.
* @param array $options Options are:
* - type : can be pass, map, or reduce. Map will handoff the given callback
* to array_map, reduce will handoff to array_reduce, and pass will
* use call_user_func_array().
* @return mixed Result of the callback when applied to extracted data
* @access public
* @static
*/
function &get() {
trigger_error('get() is deprecated. Set class should be called statically', E_USER_WARNING);
function apply($path, $data, $callback, $options = array()) {
$defaults = array('type' => 'pass');
$options = array_merge($defaults, $options);

$extracted = Set::extract($path, $data);

if ($options['type'] === 'map') {
$result = array_map($callback, &$extracted);

} elseif ($options['type'] === 'reduce') {
$result = array_reduce(&$extracted, $callback);

} elseif ($options['type'] === 'pass') {
$result = call_user_func_array($callback, array($extracted));
} else {
return null;
}

return $result;
}
}
?>
2 changes: 1 addition & 1 deletion cake/libs/validation.php
Expand Up @@ -843,7 +843,7 @@ function ssn($check, $regex = null, $country = null) {
function url($check, $strict = false) {
$_this =& Validation::getInstance();
$_this->check = $check;
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=') . '\/0-9a-z]|(%[0-9a-f]{2}))';
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~') . '\/0-9a-z]|(%[0-9a-f]{2}))';
$_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
'(?:' . $_this->__pattern['ip'] . '|' . $_this->__pattern['hostname'] . ')(?::[1-9][0-9]{0,3})?' .
'(?:\/?|\/' . $validChars . '*)?' .
Expand Down
19 changes: 19 additions & 0 deletions cake/libs/view/helper.php
Expand Up @@ -224,6 +224,25 @@ function webroot($file) {
return $webPath;
}

/**
* Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in
* Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force'
* a timestamp will be added.
*
* @param string $path The file path to timestamp, the path must be inside WWW_ROOT
* @return string Path with a timestamp added, or not.
**/
function assetTimestamp($path) {
$timestampEnabled = (
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
Configure::read('Asset.timestamp') === 'force'
);
if (strpos($path, '?') === false && $timestampEnabled) {
$path .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
}
return $path;
}

/**
* Used to remove harmful tags from content
*
Expand Down
37 changes: 7 additions & 30 deletions cake/libs/view/helpers/html.php
Expand Up @@ -373,17 +373,7 @@ function css($path, $rel = null, $htmlAttributes = array(), $inline = true) {
$path .= '.css';
}
}

$path = $this->webroot($path);

$url = $path;
$timestampEnabled = (
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
Configure::read('Asset.timestamp') === 'force'
);
if (strpos($path, '?') === false && $timestampEnabled) {
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
}
$url = $this->webroot($this->assetTimestamp($path));

if (Configure::read('Asset.filter.css')) {
$url = str_replace(CSS_URL, 'ccss/', $url);
Expand Down Expand Up @@ -452,21 +442,10 @@ function script($url, $options = array()) {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
$url = $this->webroot($url);
if (strpos($url, '?') === false) {
if (strpos($url, '.js') === false) {
$url .= '.js';
}
}

$timestampEnabled = (
(Configure::read('Asset.timestamp') === true && Configure::read('debug') > 0) ||
Configure::read('Asset.timestamp') === 'force'
);

if (strpos($url, '?') === false && $timestampEnabled) {
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
if (strpos($url, '?') === false && strpos($url, '.js') === false) {
$url .= '.js';
}
$url = $this->webroot($this->assetTimestamp($url));

if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
Expand Down Expand Up @@ -607,13 +586,11 @@ function getCrumbs($separator = '&raquo;', $startText = false) {
function image($path, $options = array()) {
if (is_array($path)) {
$path = $this->url($path);
} elseif ($path[0] === '/') {
$path = $this->webroot($path);
} elseif (strpos($path, '://') === false) {
$path = $this->webroot(IMAGES_URL . $path);
if ((Configure::read('Asset.timestamp') == true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') {
$path .= '?' . @filemtime(str_replace('/', DS, WWW_ROOT . $path));
if ($path[0] !== '/') {
$path = IMAGES_URL . $path;
}
$path = $this->webroot($this->assetTimestamp($path));
}

if (!isset($options['alt'])) {
Expand Down
11 changes: 1 addition & 10 deletions cake/libs/view/helpers/javascript.php
Expand Up @@ -270,16 +270,7 @@ function link($url, $inline = true) {
$url .= '.js';
}
}

$url = $this->webroot($url);
$timestampEnabled = (
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
Configure::read('Asset.timestamp') === 'force'
);

if (strpos($url, '?') === false && $timestampEnabled) {
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
}
$url = $this->webroot($this->assetTimestamp($url));

if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
Expand Down

0 comments on commit bf551c2

Please sign in to comment.