Skip to content

Commit

Permalink
Updated Model folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed May 25, 2012
1 parent 7ecadea commit 456e67a
Show file tree
Hide file tree
Showing 27 changed files with 263 additions and 209 deletions.
7 changes: 5 additions & 2 deletions lib/Cake/Model/AclNode.php
Expand Up @@ -16,7 +16,10 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('Model', 'Model');
namespace Cake\Model;
use Cake\Core\Configure,
Cake\Utility\Inflector,
Cake\Utility\ClassRegistry;

/**
* ACL Node
Expand Down Expand Up @@ -56,7 +59,7 @@ public function __construct() {
*
* @param string|array|Model $ref Array with 'model' and 'foreign_key', model object, or string value
* @return array Node found in database
* @throws CakeException when binding to a model that doesn't exist.
* @throws Cake\Error\Exception when binding to a model that doesn't exist.
*/
public function node($ref = null) {
$db = $this->getDataSource();
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Aco.php
Expand Up @@ -16,7 +16,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('AclNode', 'Model');
namespace Cake\Model;

/**
* Access Control Object
Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/Model/AcoAction.php
Expand Up @@ -15,15 +15,14 @@
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('AppModel', 'Model');
namespace Cake\Model;

/**
* Action for Access Control Object
*
* @package Cake.Model
*/
class AcoAction extends AppModel {
class AcoAction extends Model {

/**
* Model name
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Aro.php
Expand Up @@ -16,7 +16,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('AclNode', 'Model');
namespace Cake\Model;

/**
* Access Request Object
Expand Down
8 changes: 6 additions & 2 deletions lib/Cake/Model/Behavior/AclBehavior.php
Expand Up @@ -18,8 +18,12 @@
* @since CakePHP v 1.2.0.4487
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AclNode', 'Model');
App::uses('Hash', 'Utility');

namespace Cake\Model\Behavior;
use Cake\Model\ModelBehavior,
Cake\Model\Model,
Cake\Utility\ClassRegistry,
Cake\Utility\Hash;

/**
* ACL behavior
Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/Model/Behavior/ContainableBehavior.php
Expand Up @@ -18,6 +18,10 @@
* @since CakePHP(tm) v 1.2.0.5669
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Behavior;
use Cake\Model\ModelBehavior,
Cake\Model\Model,
Cake\Utility\Set;

/**
* Behavior to allow for dynamic and atomic manipulation of a Model's associations
Expand Down
12 changes: 8 additions & 4 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -12,9 +12,13 @@
* @since CakePHP(tm) v 1.2.0.4525
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('I18n', 'I18n');
App::uses('I18nModel', 'Model');
namespace Cake\Model\Behavior;
use Cake\Model\ModelBehavior,
Cake\Model\Model,
Cake\Model\ConnectionManager,
Cake\I18n\I18n,
Cake\Core\Configure,
Cake\Utility\ClassRegistry;

/**
* Translate behavior
Expand Down Expand Up @@ -111,7 +115,7 @@ public function beforeFind(Model $model, $query) {
} else {
$tablePrefix = $db->config['prefix'];
}
$joinTable = new StdClass();
$joinTable = new \StdClass();
$joinTable->tablePrefix = $tablePrefix;
$joinTable->table = $RuntimeModel->table;
$joinTable->schemaName = $RuntimeModel->getDataSource()->getSchemaName();
Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -18,6 +18,10 @@
* @since CakePHP v 1.2.0.4487
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Behavior;
use Cake\Model\ModelBehavior,
Cake\Model\Model,
Cake\Model\ConnectionManager;

/**
* Tree Behavior.
Expand Down
25 changes: 13 additions & 12 deletions lib/Cake/Model/BehaviorCollection.php
Expand Up @@ -18,9 +18,12 @@
* @since CakePHP(tm) v 1.2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('ObjectCollection', 'Utility');
App::uses('CakeEventListener', 'Event');
namespace Cake\Model;
use Cake\Utility\ObjectCollection,
Cake\Utility\ClassRegistry,
Cake\Core\App,
Cake\Event\EventListener,
Cake\Error;

/**
* Model behavior collection class.
Expand All @@ -29,7 +32,7 @@
*
* @package Cake.Model
*/
class BehaviorCollection extends ObjectCollection implements CakeEventListener {
class BehaviorCollection extends ObjectCollection implements EventListener {

/**
* Stores a reference to the attached name
Expand Down Expand Up @@ -114,13 +117,10 @@ public function load($behavior, $config = array()) {
if (!isset($alias)) {
$alias = $name;
}

$class = $name . 'Behavior';

App::uses($class, $plugin . 'Model/Behavior');
if (!class_exists($class)) {
throw new MissingBehaviorException(array(
'class' => $class,
$class = App::classname($behavior, 'Model/Behavior', 'Behavior');
if (!$class) {
throw new Error\MissingBehaviorException(array(
'class' => $name . 'Behavior',
'plugin' => substr($plugin, 0, -1)
));
}
Expand Down Expand Up @@ -151,7 +151,8 @@ public function load($behavior, $config = array()) {
$this->_mappedMethods[$method] = array($alias, $methodAlias);
}
$methods = get_class_methods($this->_loaded[$alias]);
$parentMethods = array_flip(get_class_methods('ModelBehavior'));
$x = new \Cake\Model\ModelBehavior();
$parentMethods = array_flip(get_class_methods('Cake\Model\ModelBehavior'));
$callbacks = array(
'setup', 'cleanup', 'beforeFind', 'afterFind', 'beforeSave', 'afterSave',
'beforeDelete', 'afterDelete', 'onError'
Expand Down
32 changes: 16 additions & 16 deletions lib/Cake/Model/ConnectionManager.php
Expand Up @@ -18,8 +18,10 @@
* @since CakePHP(tm) v 0.10.x.1402
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('DataSource', 'Model/Datasource');
namespace Cake\Model;
use Cake\Core\App,
Cake\Core\Configure,
Cake\Error;

/**
* Manages loaded instances of DataSource objects
Expand Down Expand Up @@ -66,8 +68,9 @@ class ConnectionManager {
*/
protected static function _init() {
include_once APP . 'Config' . DS . 'database.php';
if (class_exists('DATABASE_CONFIG')) {
self::$config = new DATABASE_CONFIG();
$class = Configure::read('App.namespace') . '\Config\DATABASE_CONFIG';
if (class_exists($class)) {
self::$config = new $class();
}
self::$_init = true;
}
Expand All @@ -94,10 +97,7 @@ public static function getDataSource($name) {
self::_getConnectionObject($name);
}

self::loadDataSource($name);
$conn = self::$_connectionsEnum[$name];
$class = $conn['classname'];

$class = self::loadDataSource($name);
self::$_dataSources[$name] = new $class(self::$config->{$name});
self::$_dataSources[$name]->configKeyName = $name;

Expand Down Expand Up @@ -143,8 +143,8 @@ public static function getSourceName($source) {
* @param string|array $connName A string name of the connection, as defined in app/Config/database.php,
* or an array containing the filename (without extension) and class name of the object,
* to be found in app/Model/Datasource/ or lib/Cake/Model/Datasource/.
* @return boolean True on success, null on failure or false if the class is already loaded
* @throws MissingDatasourceException
* @return string
* @throws Cake\Error\MissingDatasourceException
*/
public static function loadDataSource($connName) {
if (empty(self::$_init)) {
Expand All @@ -158,7 +158,7 @@ public static function loadDataSource($connName) {
}

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

$plugin = $package = null;
Expand All @@ -169,14 +169,14 @@ public static function loadDataSource($connName) {
$package = '/' . $conn['package'];
}

App::uses($conn['classname'], $plugin . 'Model/Datasource' . $package);
if (!class_exists($conn['classname'])) {
throw new MissingDatasourceException(array(
$class = App::classname($plugin . $conn['classname'], 'Model/Datasource' . $package);
if (!class_exists($class)) {
throw new Error\MissingDatasourceException(array(
'class' => $conn['classname'],
'plugin' => substr($plugin, 0, -1)
));
}
return true;
return $class;
}

/**
Expand Down Expand Up @@ -242,7 +242,7 @@ protected static function _getConnectionObject($name) {
if (!empty(self::$config->{$name})) {
self::$_connectionsEnum[$name] = self::_connectionData(self::$config->{$name});
} else {
throw new MissingDatasourceConfigException(array('config' => $name));
throw new Error\MissingDatasourceConfigException(array('config' => $name));
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/Cake/Model/Datasource/DataSource.php
Expand Up @@ -16,6 +16,11 @@
* @since CakePHP(tm) v 0.10.5.1790
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Model\Datasource;
use Cake\Core\Object,
Cake\Cache\Cache,
Cake\Model\ConnectionManager,
Cake\Model\Model;

/**
* DataSource base class
Expand Down
22 changes: 13 additions & 9 deletions lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -16,8 +16,12 @@
* @since CakePHP(tm) v 0.10.5.1790
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('DboSource', 'Model/Datasource');
namespace Cake\Model\Datasource\Database;
use Cake\Model\Datasource\DboSource,
Cake\Model\Model,
Cake\Model\Schema,
Cake\Error,
\PDO;

/**
* MySQL DBO driver object
Expand Down Expand Up @@ -148,8 +152,8 @@ public function connect() {
$flags
);
$this->connected = true;
} catch (PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
} catch (\PDOException $e) {
throw new Error\MissingConnectionException(array('class' => $e->getMessage()));
}

$this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
Expand Down Expand Up @@ -274,7 +278,7 @@ public function getCharsetName($name) {
*
* @param Model|string $model Name of database table to inspect or model instance
* @return array Fields in table. Keys are name and type
* @throws CakeException
* @throws Cake\Error\Exception
*/
public function describe($model) {
$key = $this->fullTableName($model, false);
Expand All @@ -287,7 +291,7 @@ public function describe($model) {
$fields = false;
$cols = $this->_execute('SHOW FULL COLUMNS FROM ' . $table);
if (!$cols) {
throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $table));
throw new Error\Exception(__d('cake_dev', 'Could not describe table for %s', $table));
}

while ($column = $cols->fetch(PDO::FETCH_OBJ)) {
Expand Down Expand Up @@ -450,7 +454,7 @@ public function index($model) {
/**
* Generate a MySQL Alter Table syntax for the given Schema comparison
*
* @param array $compare Result of a CakeSchema::compare()
* @param array $compare Result of a Cake\Model\Schema::compare()
* @param string $table
* @return array Array of alter statements to make.
*/
Expand Down Expand Up @@ -511,12 +515,12 @@ public function alterSchema($compare, $table = null) {
/**
* Generate a MySQL "drop table" statement for the given Schema object
*
* @param CakeSchema $schema An instance of a subclass of CakeSchema
* @param Cake\Model\Schema $schema An instance of a subclass of Cake\Model\Schema
* @param string $table Optional. If specified only the table name given will be generated.
* Otherwise, all tables defined in the schema are generated.
* @return string
*/
public function dropSchema(CakeSchema $schema, $table = null) {
public function dropSchema(Schema $schema, $table = null) {
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table === $curTable) {
Expand Down
12 changes: 7 additions & 5 deletions lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -16,8 +16,10 @@
* @since CakePHP(tm) v 0.9.1.114
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('DboSource', 'Model/Datasource');
namespace Cake\Model\Datasource\Database;
use Cake\Model\Datasource\DboSource,
Cake\Error,
\PDO;

/**
* PostgreSQL layer for DBO.
Expand Down Expand Up @@ -120,8 +122,8 @@ public function connect() {
if (!empty($config['schema'])) {
$this->_execute('SET search_path TO ' . $config['schema']);
}
} catch (PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
} catch (\PDOException $e) {
throw new Error\MissingConnectionException(array('class' => $e->getMessage()));
}

return $this->connected;
Expand Down Expand Up @@ -458,7 +460,7 @@ public function index($model) {
/**
* Alter the Schema of a table.
*
* @param array $compare Results of CakeSchema::compare()
* @param array $compare Results of Cake\Model\Schema::compare()
* @param string $table name of the table
* @return array
*/
Expand Down

0 comments on commit 456e67a

Please sign in to comment.