From 82e3f94e428db709e87ecc337cdcbd1661d04dec Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 23 Apr 2013 22:52:20 +0200 Subject: [PATCH] replaced CRLF with LF line endings --- ActiveRecord.php | 98 ++++++------ lib/Column.php | 308 ++++++++++++++++++------------------ lib/Expressions.php | 370 ++++++++++++++++++++++---------------------- lib/Inflector.php | 240 ++++++++++++++-------------- 4 files changed, 508 insertions(+), 508 deletions(-) diff --git a/ActiveRecord.php b/ActiveRecord.php index dda0ff632..742a78cc6 100644 --- a/ActiveRecord.php +++ b/ActiveRecord.php @@ -1,49 +1,49 @@ -get_model_directory(); - $root = realpath(isset($path) ? $path : '.'); - - if (($namespaces = ActiveRecord\get_namespaces($class_name))) - { - $class_name = array_pop($namespaces); - $directories = array(); - - foreach ($namespaces as $directory) - $directories[] = $directory; - - $root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR); - } - - $file = "$root/$class_name.php"; - - if (file_exists($file)) - require_once $file; -} -?> +get_model_directory(); + $root = realpath(isset($path) ? $path : '.'); + + if (($namespaces = ActiveRecord\get_namespaces($class_name))) + { + $class_name = array_pop($namespaces); + $directories = array(); + + foreach ($namespaces as $directory) + $directories[] = $directory; + + $root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR); + } + + $file = "$root/$class_name.php"; + + if (file_exists($file)) + require_once $file; +} +?> \ No newline at end of file diff --git a/lib/Column.php b/lib/Column.php index d73bd1b75..ae9c893c0 100644 --- a/lib/Column.php +++ b/lib/Column.php @@ -1,155 +1,155 @@ - self::DATETIME, - 'timestamp' => self::DATETIME, - 'date' => self::DATE, - 'time' => self::TIME, - - 'int' => self::INTEGER, - 'tinyint' => self::INTEGER, - 'smallint' => self::INTEGER, - 'mediumint' => self::INTEGER, - 'bigint' => self::INTEGER, - - 'float' => self::DECIMAL, - 'double' => self::DECIMAL, - 'numeric' => self::DECIMAL, - 'decimal' => self::DECIMAL, - 'dec' => self::DECIMAL); - - /** - * The true name of this column. - * @var string - */ - public $name; - - /** - * The inflected name of this columns .. hyphens/spaces will be => _. - * @var string - */ - public $inflected_name; - - /** - * The type of this column: STRING, INTEGER, ... - * @var integer - */ - public $type; - - /** - * The raw database specific type. - * @var string - */ - public $raw_type; - - /** - * The maximum length of this column. - * @var int - */ - public $length; - - /** - * True if this column allows null. - * @var boolean - */ - public $nullable; - - /** - * True if this column is a primary key. - * @var boolean - */ - public $pk; - - /** - * The default value of the column. - * @var mixed - */ - public $default; - - /** - * True if this column is set to auto_increment. - * @var boolean - */ - public $auto_increment; - - /** - * Name of the sequence to use for this column if any. - * @var boolean - */ - public $sequence; - - /** - * Casts a value to the column's type. - * - * @param mixed $value The value to cast - * @param Connection $connection The Connection this column belongs to - * @return mixed type-casted value - */ - public function cast($value, $connection) - { - if ($value === null) - return null; - - switch ($this->type) - { - case self::STRING: return (string)$value; - case self::INTEGER: return (int)$value; - case self::DECIMAL: return (double)$value; - case self::DATETIME: - case self::DATE: - if (!$value) - return null; - - if ($value instanceof DateTime) - return $value; - - if ($value instanceof \DateTime) - return new DateTime($value->format('Y-m-d H:i:s T')); - - return $connection->string_to_datetime($value); - } - return $value; - } - - /** - * Sets the $type member variable. - * @return mixed - */ - public function map_raw_type() - { - if ($this->raw_type == 'integer') - $this->raw_type = 'int'; - - if (array_key_exists($this->raw_type,self::$TYPE_MAPPING)) - $this->type = self::$TYPE_MAPPING[$this->raw_type]; - else - $this->type = self::STRING; - - return $this->type; - } -} + self::DATETIME, + 'timestamp' => self::DATETIME, + 'date' => self::DATE, + 'time' => self::TIME, + + 'int' => self::INTEGER, + 'tinyint' => self::INTEGER, + 'smallint' => self::INTEGER, + 'mediumint' => self::INTEGER, + 'bigint' => self::INTEGER, + + 'float' => self::DECIMAL, + 'double' => self::DECIMAL, + 'numeric' => self::DECIMAL, + 'decimal' => self::DECIMAL, + 'dec' => self::DECIMAL); + + /** + * The true name of this column. + * @var string + */ + public $name; + + /** + * The inflected name of this columns .. hyphens/spaces will be => _. + * @var string + */ + public $inflected_name; + + /** + * The type of this column: STRING, INTEGER, ... + * @var integer + */ + public $type; + + /** + * The raw database specific type. + * @var string + */ + public $raw_type; + + /** + * The maximum length of this column. + * @var int + */ + public $length; + + /** + * True if this column allows null. + * @var boolean + */ + public $nullable; + + /** + * True if this column is a primary key. + * @var boolean + */ + public $pk; + + /** + * The default value of the column. + * @var mixed + */ + public $default; + + /** + * True if this column is set to auto_increment. + * @var boolean + */ + public $auto_increment; + + /** + * Name of the sequence to use for this column if any. + * @var boolean + */ + public $sequence; + + /** + * Casts a value to the column's type. + * + * @param mixed $value The value to cast + * @param Connection $connection The Connection this column belongs to + * @return mixed type-casted value + */ + public function cast($value, $connection) + { + if ($value === null) + return null; + + switch ($this->type) + { + case self::STRING: return (string)$value; + case self::INTEGER: return (int)$value; + case self::DECIMAL: return (double)$value; + case self::DATETIME: + case self::DATE: + if (!$value) + return null; + + if ($value instanceof DateTime) + return $value; + + if ($value instanceof \DateTime) + return new DateTime($value->format('Y-m-d H:i:s T')); + + return $connection->string_to_datetime($value); + } + return $value; + } + + /** + * Sets the $type member variable. + * @return mixed + */ + public function map_raw_type() + { + if ($this->raw_type == 'integer') + $this->raw_type = 'int'; + + if (array_key_exists($this->raw_type,self::$TYPE_MAPPING)) + $this->type = self::$TYPE_MAPPING[$this->raw_type]; + else + $this->type = self::STRING; + + return $this->type; + } +} ?> \ No newline at end of file diff --git a/lib/Expressions.php b/lib/Expressions.php index f023d5aba..8dea22bc7 100644 --- a/lib/Expressions.php +++ b/lib/Expressions.php @@ -1,185 +1,185 @@ -connection = $connection; - - if (is_array($expressions)) - { - $glue = func_num_args() > 2 ? func_get_arg(2) : ' AND '; - list($expressions,$values) = $this->build_sql_from_hash($expressions,$glue); - } - - if ($expressions != '') - { - if (!$values) - $values = array_slice(func_get_args(),2); - - $this->values = $values; - $this->expressions = $expressions; - } - } - - /** - * Bind a value to the specific one based index. There must be a bind marker - * for each value bound or to_s() will throw an exception. - */ - public function bind($parameter_number, $value) - { - if ($parameter_number <= 0) - throw new ExpressionsException("Invalid parameter index: $parameter_number"); - - $this->values[$parameter_number-1] = $value; - } - - public function bind_values($values) - { - $this->values = $values; - } - - /** - * Returns all the values currently bound. - */ - public function values() - { - return $this->values; - } - - /** - * Returns the connection object. - */ - public function get_connection() - { - return $this->connection; - } - - /** - * Sets the connection object. It is highly recommended to set this so we can - * use the adapter's native escaping mechanism. - * - * @param string $connection a Connection instance - */ - public function set_connection($connection) - { - $this->connection = $connection; - } - - public function to_s($substitute=false, &$options=null) - { - if (!$options) $options = array(); - - $values = array_key_exists('values',$options) ? $options['values'] : $this->values; - - $ret = ""; - $replace = array(); - $num_values = count($values); - $len = strlen($this->expressions); - $quotes = 0; - - for ($i=0,$n=strlen($this->expressions),$j=0; $i<$n; ++$i) - { - $ch = $this->expressions[$i]; - - if ($ch == self::ParameterMarker) - { - if ($quotes % 2 == 0) - { - if ($j > $num_values-1) - throw new ExpressionsException("No bound parameter for index $j"); - - $ch = $this->substitute($values,$substitute,$i,$j++); - } - } - elseif ($ch == '\'' && $i > 0 && $this->expressions[$i-1] != '\\') - ++$quotes; - - $ret .= $ch; - } - return $ret; - } - - private function build_sql_from_hash(&$hash, $glue) - { - $sql = $g = ""; - - foreach ($hash as $name => $value) - { - if ($this->connection) - $name = $this->connection->quote_name($name); - - if (is_array($value)) - $sql .= "$g$name IN(?)"; - elseif (is_null($value)) - $sql .= "$g$name IS ?"; - else - $sql .= "$g$name=?"; - - $g = $glue; - } - return array($sql,array_values($hash)); - } - - private function substitute(&$values, $substitute, $pos, $parameter_index) - { - $value = $values[$parameter_index]; - - if (is_array($value)) - { - if ($substitute) - { - $ret = ''; - - for ($i=0,$n=count($value); $i<$n; ++$i) - $ret .= ($i > 0 ? ',' : '') . $this->stringify_value($value[$i]); - - return $ret; - } - return join(',',array_fill(0,count($value),self::ParameterMarker)); - } - - if ($substitute) - return $this->stringify_value($value); - - return $this->expressions[$pos]; - } - - private function stringify_value($value) - { - if (is_null($value)) - return "NULL"; - - return is_string($value) ? $this->quote_string($value) : $value; - } - - private function quote_string($value) - { - if ($this->connection) - return $this->connection->escape($value); - - return "'" . str_replace("'","''",$value) . "'"; - } -} -?> +connection = $connection; + + if (is_array($expressions)) + { + $glue = func_num_args() > 2 ? func_get_arg(2) : ' AND '; + list($expressions,$values) = $this->build_sql_from_hash($expressions,$glue); + } + + if ($expressions != '') + { + if (!$values) + $values = array_slice(func_get_args(),2); + + $this->values = $values; + $this->expressions = $expressions; + } + } + + /** + * Bind a value to the specific one based index. There must be a bind marker + * for each value bound or to_s() will throw an exception. + */ + public function bind($parameter_number, $value) + { + if ($parameter_number <= 0) + throw new ExpressionsException("Invalid parameter index: $parameter_number"); + + $this->values[$parameter_number-1] = $value; + } + + public function bind_values($values) + { + $this->values = $values; + } + + /** + * Returns all the values currently bound. + */ + public function values() + { + return $this->values; + } + + /** + * Returns the connection object. + */ + public function get_connection() + { + return $this->connection; + } + + /** + * Sets the connection object. It is highly recommended to set this so we can + * use the adapter's native escaping mechanism. + * + * @param string $connection a Connection instance + */ + public function set_connection($connection) + { + $this->connection = $connection; + } + + public function to_s($substitute=false, &$options=null) + { + if (!$options) $options = array(); + + $values = array_key_exists('values',$options) ? $options['values'] : $this->values; + + $ret = ""; + $replace = array(); + $num_values = count($values); + $len = strlen($this->expressions); + $quotes = 0; + + for ($i=0,$n=strlen($this->expressions),$j=0; $i<$n; ++$i) + { + $ch = $this->expressions[$i]; + + if ($ch == self::ParameterMarker) + { + if ($quotes % 2 == 0) + { + if ($j > $num_values-1) + throw new ExpressionsException("No bound parameter for index $j"); + + $ch = $this->substitute($values,$substitute,$i,$j++); + } + } + elseif ($ch == '\'' && $i > 0 && $this->expressions[$i-1] != '\\') + ++$quotes; + + $ret .= $ch; + } + return $ret; + } + + private function build_sql_from_hash(&$hash, $glue) + { + $sql = $g = ""; + + foreach ($hash as $name => $value) + { + if ($this->connection) + $name = $this->connection->quote_name($name); + + if (is_array($value)) + $sql .= "$g$name IN(?)"; + elseif (is_null($value)) + $sql .= "$g$name IS ?"; + else + $sql .= "$g$name=?"; + + $g = $glue; + } + return array($sql,array_values($hash)); + } + + private function substitute(&$values, $substitute, $pos, $parameter_index) + { + $value = $values[$parameter_index]; + + if (is_array($value)) + { + if ($substitute) + { + $ret = ''; + + for ($i=0,$n=count($value); $i<$n; ++$i) + $ret .= ($i > 0 ? ',' : '') . $this->stringify_value($value[$i]); + + return $ret; + } + return join(',',array_fill(0,count($value),self::ParameterMarker)); + } + + if ($substitute) + return $this->stringify_value($value); + + return $this->expressions[$pos]; + } + + private function stringify_value($value) + { + if (is_null($value)) + return "NULL"; + + return is_string($value) ? $this->quote_string($value) : $value; + } + + private function quote_string($value) + { + if ($this->connection) + return $this->connection->escape($value); + + return "'" . str_replace("'","''",$value) . "'"; + } +} +?> diff --git a/lib/Inflector.php b/lib/Inflector.php index 56f990601..e2b788e13 100644 --- a/lib/Inflector.php +++ b/lib/Inflector.php @@ -1,120 +1,120 @@ - 0) - $camelized[0] = strtolower($camelized[0]); - - return $camelized; - } - - /** - * Determines if a string contains all uppercase characters. - * - * @param string $s string to check - * @return bool - */ - public static function is_upper($s) - { - return (strtoupper($s) === $s); - } - - /** - * Determines if a string contains all lowercase characters. - * - * @param string $s string to check - * @return bool - */ - public static function is_lower($s) - { - return (strtolower($s) === $s); - } - - /** - * Convert a camelized string to a lowercase, underscored string. - * - * @param string $s string to convert - * @return string - */ - public function uncamelize($s) - { - $normalized = ''; - - for ($i=0,$n=strlen($s); $i<$n; ++$i) - { - if (ctype_alpha($s[$i]) && self::is_upper($s[$i])) - $normalized .= '_' . strtolower($s[$i]); - else - $normalized .= $s[$i]; - } - return trim($normalized,' _'); - } - - /** - * Convert a string with space into a underscored equivalent. - * - * @param string $s string to convert - * @return string - */ - public function underscorify($s) - { - return preg_replace(array('/[_\- ]+/','/([a-z])([A-Z])/'),array('_','\\1_\\2'),trim($s)); - } - - public function keyify($class_name) - { - return strtolower($this->underscorify(denamespace($class_name))) . '_id'; - } - - abstract function variablize($s); -} - -/** - * @package ActiveRecord - */ -class StandardInflector extends Inflector -{ - public function tableize($s) { return Utils::pluralize(strtolower($this->underscorify($s))); } - public function variablize($s) { return str_replace(array('-',' '),array('_','_'),strtolower(trim($s))); } -} -?> + 0) + $camelized[0] = strtolower($camelized[0]); + + return $camelized; + } + + /** + * Determines if a string contains all uppercase characters. + * + * @param string $s string to check + * @return bool + */ + public static function is_upper($s) + { + return (strtoupper($s) === $s); + } + + /** + * Determines if a string contains all lowercase characters. + * + * @param string $s string to check + * @return bool + */ + public static function is_lower($s) + { + return (strtolower($s) === $s); + } + + /** + * Convert a camelized string to a lowercase, underscored string. + * + * @param string $s string to convert + * @return string + */ + public function uncamelize($s) + { + $normalized = ''; + + for ($i=0,$n=strlen($s); $i<$n; ++$i) + { + if (ctype_alpha($s[$i]) && self::is_upper($s[$i])) + $normalized .= '_' . strtolower($s[$i]); + else + $normalized .= $s[$i]; + } + return trim($normalized,' _'); + } + + /** + * Convert a string with space into a underscored equivalent. + * + * @param string $s string to convert + * @return string + */ + public function underscorify($s) + { + return preg_replace(array('/[_\- ]+/','/([a-z])([A-Z])/'),array('_','\\1_\\2'),trim($s)); + } + + public function keyify($class_name) + { + return strtolower($this->underscorify(denamespace($class_name))) . '_id'; + } + + abstract function variablize($s); +} + +/** + * @package ActiveRecord + */ +class StandardInflector extends Inflector +{ + public function tableize($s) { return Utils::pluralize(strtolower($this->underscorify($s))); } + public function variablize($s) { return str_replace(array('-',' '),array('_','_'),strtolower(trim($s))); } +} +?>