Permalink
Browse files

Merge branch 'master' into dev

  • Loading branch information...
2 parents 3f25bdf + 57aa30b commit dd0189f8ba8056ac97748d71da48870a8fa2104f @gwoo gwoo committed Jul 4, 2012
View
@@ -132,6 +132,12 @@ public function __construct(array $config = array()) {
parent::__construct($config + $defaults);
}
+ /**
+ * Populates the `$response` property with a new instance of the `Response` class passing it
+ * configuration, and sets some rendering options, depending on the incoming request.
+ *
+ * @return void
+ */
protected function _init() {
parent::_init();
$this->request = $this->request ?: $this->_config['request'];
@@ -195,7 +201,7 @@ public function __invoke($request, $dispatchParams, array $options = array()) {
/**
* This method is used to pass along any data from the controller to the view and layout
*
- * @param array $data sets of <variable name> => <variable value> to pass to view layer.
+ * @param array $data sets of `<variable name> => <variable value>` to pass to view layer.
* @return void
*/
public function set($data = array()) {
View
@@ -246,7 +246,7 @@ public function env($key) {
$this->_env[$key] = $val;
if ($key == 'REMOTE_ADDR') {
- foreach(array('HTTP_X_FORWARDED_FOR', 'HTTP_PC_REMOTE_ADDR') as $altKey) {
+ foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_PC_REMOTE_ADDR') as $altKey) {
if ($addr = $this->env($altKey)) {
$val = $addr;
break;
View
@@ -0,0 +1,21 @@
+{
+ "name": "UnionOfRAD/lithium",
+ "type": "library",
+ "description": "The core library of the Lithium PHP framework",
+ "keywords": ["lithium", "framework"],
+ "homepage": "http://lithify.me",
+ "license": "BSD-3-Clause",
+ "authors": [
+ {
+ "name": "Union of RAD",
+ "homepage": "http://union-of-rad.org"
+ },
+ {
+ "name": "The Lithium Community",
+ "homepage": "http://github.com/UnionOfRAD/lithium/graphs/contributors"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.6"
+ }
+}
@@ -13,6 +13,7 @@
use RuntimeException;
use lithium\core\Libraries;
use lithium\util\String;
+use lithium\util\Inflector;
/**
* The Library command is used to archive and extract Phar::GZ archives. Requires zlib extension.
@@ -237,7 +238,7 @@ public function extract($name = 'new', $result = null) {
$this->out(basename($to) . " created in " . dirname($to) . " from {$from}");
if (empty($this->namespace)) {
- $this->namespace = basename($to);
+ $this->namespace = Inflector::underscore(basename($to));
}
$replacements = $this->_findReplacements($to);
View
@@ -257,6 +257,22 @@ public function map($filter, array $options = array()) {
}
/**
+ * Reduce, or fold, a collection down to a single value
+ *
+ * Overridden to load any data that has not yet been loaded.
+ *
+ * @param callback $filter The filter to apply.
+ * @param mixed $initial Initial value
+ * @return mixed A single reduced value
+ */
+ public function reduce($filter, $initial = false) {
+ if (!$this->closed()) {
+ while ($this->next()) {}
+ }
+ return parent::reduce($filter);
+ }
+
+ /**
* Sorts the objects in the collection, useful in situations where
* you are already using the underlying datastore to sort results.
*
View
@@ -244,6 +244,19 @@ class Model extends \lithium\core\StaticObject {
* a collection, along with a `'data'` key, which contains the schema for that collection, in
* the format specified above.
*
+ * When defining `'$_schema'` where the data source is MongoDB, the types map to database types as follows:
+ *
+ * {{{
+ * id => MongoId
+ * date => MongoDate
+ * regex => MongoRegex
+ * integer => integer
+ * float => float
+ * boolean => boolean
+ * code => MongoCode
+ * binary => MongoBinData
+ * }}}
+ *
* @see lithium\data\source\MongoDb::$_schema
* @var array
*/
@@ -318,8 +331,9 @@ public static function __init() {
* attributes, as well as obtain a handle to the configured persistent storage connection.
*
* @param array $options Possible options are:
- * - `meta`: Meta-information for this model, such as the connection.
- * - `finders`: Custom finders for this model.
+ * - `meta`: Meta-information for this model, such as the connection.
+ * - `finders`: Custom finders for this model.
+ *
* @return void
*/
public static function config(array $options = array()) {
@@ -482,7 +496,7 @@ public static function finder($name, $options = null) {
}
/**
- * Set/get method for `Model` metadata.
+ * Gets or sets Model's metadata.
*
* @see lithium\data\Model::$_meta
* @param string $key Model metadata key.
@@ -646,8 +660,8 @@ public static function hasField($field) {
* example:
*
* {{{
- * $post = Posts::create(array("title" => "New post"));
- * echo $post->title; // echoes "New post"
+ * $post = Posts::create(array('title' => 'New post'));
+ * echo $post->title; // echoes 'New post'
* $success = $post->save();
* }}}
*
@@ -658,8 +672,8 @@ public static function hasField($field) {
* database, without actually querying the database:
*
* {{{
- * $post = Posts::create(array("id" => $id, "moreData" => "foo"), array("exists" => true));
- * $post->title = "New title";
+ * $post = Posts::create(array('id' => $id, 'moreData' => 'foo'), array('exists' => true));
+ * $post->title = 'New title';
* $success = $post->save();
* }}}
*
@@ -273,6 +273,20 @@ public function find($filter, array $options = array()) {
}
/**
+ * Reduce, or fold, a collection down to a single value
+ *
+ * Overriden to load any data that has not yet been loaded.
+ *
+ * @param callback $filter The filter to apply.
+ * @param mixed $initial Initial value
+ * @return mixed A single reduced value
+ */
+ public function reduce($filter, $initial = false) {
+ $this->offsetGet(null);
+ return parent::reduce($filter, $initial);
+ }
+
+ /**
* Applies a callback to a copy of all data in the collection
* and returns the result.
*
View
@@ -196,14 +196,6 @@ public function value($value, array $schema = array()) {
return floatval($value);
case 'integer':
return intval($value);
- case 'timestamp':
- if ($value === 'CURRENT_TIMESTAMP') {
- return 'NULL';
- } else if (is_numeric($value)) {
- return date('Y-m-d H:i:s', $value);
- } else {
- return strtotime($value);
- }
}
}
View
@@ -196,7 +196,7 @@ public static function lookup($locales, $locale) {
if (($key = array_search(static::compose($tags), $locales)) !== false) {
return $locales[$key];
} elseif ($count == 1) {
- foreach($locales as $currentLocale) {
+ foreach ($locales as $currentLocale) {
if (strpos($currentLocale, current($tags) . '_') === 0) {
return $currentLocale;
}
View
@@ -0,0 +1,161 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+namespace lithium\g11n;
+use lithium\core\Libraries;
+
+/**
+ * The `Multibyte` class helps operating with UTF-8 encoded strings. Here
+ * multibyte is synonymous to UTF-8 which is probably the most widespread
+ * multibyte encoding in recent web application development.
+ *
+ * Over time - as the importance of multibyte encoding support grew - a variety
+ * of extensions appeared. While each achieves its goal somewhat differently
+ * and might be preferred over the other, they still all do that one thing.
+ *
+ * What can a framework provide, those extensions aren't? It can provide
+ * abstractions that allow portable code. While this might not be a requirement
+ * for application code, it's a definite must for the framework's core code.
+ *
+ * As previously mentioned extensions appeared in a semi-evolutionary way. This
+ * leaves us with the situation where extensions are heterogeneously spread out
+ * over environments. There certainly is no clear winner and we're left with
+ * the situation of "supporting them all".
+ *
+ * Technically this class does very little in terms of abstraction. Its main
+ * purpose is to allow adapting to changing environments: virtually creating
+ * something you can rely on, something that's always there while it actually
+ * is there only in one way or the other. And - yes - some convenience methods
+ * are also on board.
+ */
+class Multibyte extends \lithium\core\Adaptable {
+
+ /**
+ * `Libraries::locate()`-compatible path to adapters for this class.
+ *
+ * @see lithium\core\Libraries::locate()
+ * @var string Dot-delimited path.
+ */
+ protected static $_adapters = 'adapter.g11n.multibyte';
+
+ /**
+ * Checks if a given string is UTF-8 encoded and is valid UTF-8.
+ *
+ * In _quick_ mode it will check only for non ASCII characters being used
+ * indicating any multibyte encoding. Don't use quick mode for integrity
+ * validation of UTF-8 encoded strings.
+ *
+ * @link http://www.w3.org/International/questions/qa-forms-utf-8.en
+ * @param string $string The string to analyze.
+ * @param array $options Allows to toggle mode via the `'quick'` option, defaults to `false`.
+ * @return boolean Returns `true` if the string is UTF-8.
+ */
+ public static function is($string, array $options = array()) {
+ $defaults = array('quick' => false);
+ $options += $defaults;
+
+ if ($options['quick']) {
+ $regex = '/[^\x09\x0A\x0D\x20-\x7E]/m';
+ } else {
+ $regex = '/\A(';
+ $regex .= '[\x09\x0A\x0D\x20-\x7E]'; // ASCII
+ $regex .= '|[\xC2-\xDF][\x80-\xBF]'; // non-overlong 2-byte
+ $regex .= '|\xE0[\xA0-\xBF][\x80-\xBF]'; // excluding overlongs
+ $regex .= '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'; // straight 3-byte
+ $regex .= '|\xED[\x80-\x9F][\x80-\xBF]'; // excluding surrogates
+ $regex .= '|\xF0[\x90-\xBF][\x80-\xBF]{2}'; // planes 1-3
+ $regex .= '|[\xF1-\xF3][\x80-\xBF]{3}'; // planes 4-15
+ $regex .= '|\xF4[\x80-\x8F][\x80-\xBF]{2}'; // plane 16
+ $regex .= ')*\z/m';
+ }
+ return (boolean) preg_match($regex, $string);
+ }
+
+ /**
+ * Gets the string length. Multibyte enabled version of `strlen()`.
+ *
+ * @link http://php.net/manual/en/function.strlen.php
+ * @param string $string The string being measured for length.
+ * @param array $options Allows for selecting the adapter to use via the
+ * `name` options. Will use the `'default'` adapter by default.
+ * @return integer The length of the string on success.
+ */
+ public static function strlen($string, array $options = array()) {
+ $defaults = array('name' => 'default');
+ $options += $defaults;
+ return static::adapter($options['name'])->strlen($string);
+ }
+
+ /**
+ * Finds the position of the _first_ occurrence of a string within a string.
+ * Multibyte enabled version of `strpos()`.
+ *
+ * Not all adapters must support interpreting - thus applying - passed
+ * numeric values as ordinal values of a character.
+ *
+ * @link http://php.net/manual/en/function.strpos.php
+ * @param string $haystack The string being checked.
+ * @param string $needle The string to find in the haystack.
+ * @param integer $offset If specified, search will start this number of
+ * characters counted from the beginning of the string. The
+ * offset cannot be negative.
+ * @param array $options Allows for selecting the adapter to use via the
+ * `name` options. Will use the `'default'` adapter by default.
+ * @return integer Returns the numeric position of the first occurrence of
+ * the needle in the haystack string. If needle is not found,
+ * it returns `false`.
+ */
+ public static function strpos($haystack, $needle, $offset = 0, array $options = array()) {
+ $defaults = array('name' => 'default');
+ $options += $defaults;
+ return static::adapter($options['name'])->strpos($haystack, $needle, $offset);
+ }
+
+ /**
+ * Finds the position of the _last_ occurrence of a string within a string.
+ * Multibyte enabled version of `strrpos()`.
+ *
+ * Not all adapters must support interpreting - thus applying - passed
+ * numeric values as ordinal values of a character. The `Iconv` adapter
+ * doesn't support an offset as `strpos()` does - this constitutes the
+ * lowest common denominator here.
+ *
+ * @link http://php.net/manual/en/function.strrpos.php
+ * @param string $haystack The string being checked.
+ * @param string $needle The string to find in the haystack.
+ * @param array $options Allows for selecting the adapter to use via the
+ * `name` options. Will use the `'default'` adapter by default.
+ * @return integer Returns the numeric position of the last occurrence of
+ * the needle in the haystack string. If needle is not found,
+ * it returns `false`.
+ */
+ public static function strrpos($haystack, $needle, array $options = array()) {
+ $defaults = array('name' => 'default');
+ $options += $defaults;
+ return static::adapter($options['name'])->strrpos($haystack, $needle);
+ }
+
+ /**
+ * Returns the portion of string specified by the start and length parameters.
+ * Multibyte enabled version of `substr()`.
+ *
+ * @link http://php.net/manual/en/function.substr.php
+ * @param string $string The string to extract the substring from.
+ * @param integer $start Position of first character in string (offset).
+ * @param integer $length Maximum numbers of characters to use from string.
+ * @param array $options Allows for selecting the adapter to use via the
+ * `name` options. Will use the `'default'` adapter by default.
+ * @return string The substring extracted from given string.
+ */
+ public static function substr($string, $start, $length = null, array $options = array()) {
+ $defaults = array('name' => 'default');
+ $options += $defaults;
+ return static::adapter($options['name'])->substr($string, $start, $length);
+ }
+}
+
+?>
Oops, something went wrong.

0 comments on commit dd0189f

Please sign in to comment.