Skip to content

Commit

Permalink
Changing some arrays to the new syntax, just for fun
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jul 5, 2012
1 parent 9fee800 commit 8cee7d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions lib/Cake/Model/Datasource/Database/Driver/Mysql.php
Expand Up @@ -12,7 +12,7 @@ class Mysql extends \Cake\Model\Datasource\Database\Driver {
*
* @var array
*/
protected $_baseConfig = array(
protected $_baseConfig = [
'persistent' => true,
'host' => 'localhost',
'login' => 'root',
Expand All @@ -21,7 +21,7 @@ class Mysql extends \Cake\Model\Datasource\Database\Driver {
'port' => '3306',
'flags' => array(),
'encoding' => 'utf8'
);
];

/**
* Establishes a connection to the databse server
Expand All @@ -31,12 +31,12 @@ class Mysql extends \Cake\Model\Datasource\Database\Driver {
**/
public function connect(array $config) {
$config += $this->_baseConfig;
$flags = array(
$flags = [
PDO::ATTR_PERSISTENT => $config['persistent'],
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $config['encoding']
) + $config['flags'];
] + $config['flags'];

if (empty($config['unix_socket'])) {
$dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}";
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Model/Datasource/Database/Statement.php
Expand Up @@ -33,10 +33,10 @@ class Statement implements \IteratorAggregate, \Countable {
*
* @var array
**/
protected $_fetchMap = array(
protected $_fetchMap = [
'num' => PDO::FETCH_NUM,
'assoc' => PDO::FETCH_ASSOC
);
];

/**
* Constructor
Expand Down Expand Up @@ -185,7 +185,7 @@ public function fetch($type = 'num') {
* {{{
* $statement = $connection->prepare('SELECT id, title from articles');
* $statement->execute();
* print_r($statement->fetchAll('assoc')); // will show array(0 => array('id' => 1, 'title' => 'a title'))
* print_r($statement->fetchAll('assoc')); // will show [0 => ['id' => 1, 'title' => 'a title']]
* }}}
*
* @param string $type num for fetching columns as positional keys or assoc for column names as keys
Expand Down Expand Up @@ -263,7 +263,7 @@ protected function _cast($value, $type) {
$value = $type->toDatabase($value, $this->_driver);
$type = $type->toStatement($value, $this->_driver);
}
return array($value, $type);
return [$value, $type];
}

}
22 changes: 11 additions & 11 deletions lib/Cake/Model/Datasource/Database/Type.php
Expand Up @@ -19,33 +19,33 @@ class Type {
*
* @var array
**/
protected static $_types = array(
protected static $_types = [
'boolean' => '\Cake\Model\Datasource\Database\Type\BooleanType',
'binary' => '\Cake\Model\Datasource\Database\Type\BinaryType',
'date' => '\Cake\Model\Datasource\Database\Type\DateType',
'datetime' => '\Cake\Model\Datasource\Database\Type\DateTimeType',
'time' => '\Cake\Model\Datasource\Database\Type\TimeType'
);
];

/**
* List of basic type mappings, used to avoid having to instantiate a class
* for doing conversion on these
*
* @var array
**/
protected static $_basicTypes = array(
'float' => array('php' => 'floatval'),
'integer' => array('php' => 'intval', 'pdo' => PDO::PARAM_INT),
'string' => array('php' => 'strval'),
'text' => array('php' => 'strval'),
);
protected static $_basicTypes = [
'float' => ['php' => 'floatval'],
'integer' => ['php' => 'intval', 'pdo' => PDO::PARAM_INT],
'string' => ['php' => 'strval'],
'text' => ['php' => 'strval'],
];

/**
* Contains a map of type object instances to be reused if needed
*
* @var array
**/
protected static $_builtTypes = array();
protected static $_builtTypes = [];

/**
* Identifier name for this type
Expand Down Expand Up @@ -113,8 +113,8 @@ public static function map($type = null, $className = null) {
* @return void
**/
public static function clear() {
self::$_types = array();
self::$_builtTypes = array();
self::$_types = [];
self::$_builtTypes = [];
}

/**
Expand Down

0 comments on commit 8cee7d1

Please sign in to comment.