Skip to content

Commit

Permalink
Removing code that we won't need based on recent discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 9, 2013
1 parent 50ff957 commit 3103225
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 550 deletions.
16 changes: 1 addition & 15 deletions Cake/ORM/Association.php
Expand Up @@ -127,14 +127,6 @@ abstract class Association {
*/
protected $_strategy = self::STRATEGY_JOIN;

/**
* The name of the entity class associated to the targetTable, used to load an
* instance of this table in case it is present
*
* @return void
*/
protected $_entityClass;

/**
* Constructor. Subclasses can override _options function to get the original
* list of passed options if expecting any other special key
Expand All @@ -152,8 +144,7 @@ public function __construct($name, array $options = []) {
'sourceTable',
'targetTable',
'joinType',
'property',
'entityClass'
'property'
];
foreach ($defaults as $property) {
if (isset($options[$property])) {
Expand Down Expand Up @@ -213,11 +204,6 @@ public function target(Table $table = null) {
return $this->_targetTable;
}

if ($table === null && $this->_entityClass) {
$entity = $this->_entityClass;
$table = $entity::repository();
}

if ($table !== null) {
return $this->_targetTable = $table;
}
Expand Down
168 changes: 0 additions & 168 deletions Cake/ORM/Entity.php
Expand Up @@ -2,7 +2,6 @@

namespace Cake\ORM;

use Cake\Core\App;
use Cake\ORM\Table;

class Entity implements \ArrayAccess {
Expand All @@ -14,52 +13,6 @@ class Entity implements \ArrayAccess {
*/
protected $_properties = [];

/**
* Holds a reference to the objects acting as a repository for this type
* of entity
*
* @var Cake\ORM\Table
*/
protected static $_repository;

/**
* A list of entity classes pointing to the class name of the repository
* object to use
*
* @var array
*/
protected static $_repositoryClass;

/**
* List of Belongs To associations
*
* ### Basic usage
*
* `public $belongsTo = array('Group', 'Department');`
*
* ### Detailed configuration
*
* {{{
* public $belongsTo = array(
* 'Group',
* 'Department' => array(
* 'className' => 'Department',
* 'foreignKey' => 'department_id'
* )
* );
* }}}
*
* @see \Cake\ORM\Table::belongsTo() for a list of accepted configuration keys
* @var array
*/
protected static $_belongsTo = [];

protected static $_hasOne = [];

protected static $_hasMany = [];

protected static $_belongsToMany = [];

/**
* Initializes the internal properties of this entity out of the
* keys in an array
Expand Down Expand Up @@ -295,125 +248,4 @@ public function offsetUnset($offset) {
$this->unsetProperty($offset);
}

/**
* Returns the instance of the table object associated to this entity.
* If called with a Table object as first argument, it will be set as the default
* repository object to use.
*
* @param \Cake\ORM\Table $table The table object to use as a repository of this
* type of Entity
* @return \Cake\ORM\Table
*/
public static function repository(Table $table = null) {
if ($table === null) {
if (static::$_repository === null) {
$className = static::repositoryClass();
$self = get_called_class();
list($namespace, $alias) = namespaceSplit($self);
static::$_repository = $className::build($alias, [
'entityClass' => $self
]);
}
return static::$_repository;
}
$table->entityClass(get_called_class());
return static::$_repository = $table;
}

/**
* Returns the fully namespaced class name for the repository object associated to
* this entity. If a string is passed as first argument, it will be used to store
* the name of the repository object to use.
*
* Plugin notation can be used to specify the name of the object to load. By
* convention, classes will be loaded from `[PluginName]\Model\Repository\`
* base namespace if a plugin is specified or from `App\Model\Repository` if
* none is passed.
*
* ### Examples:
*
* - ``User::repositoryClass('\App\Model\Repository\SuperUserTable');``
* - ``User::repositoryClass('My.User');`` // Looks inside My plugin
*
* @param string $class Fully namespaced class name or name of the object using
* plugin notation.
* @throws \Cake\ORM\Error\MissingTableClassException when the table class cannot be found
* @return string|boolean the full name of the class or false if the class does not exist
*/
public static function repositoryClass($class = null) {
$self = get_called_class();
if ($class) {
self::$_repositoryClass[$self] = $class;
}

if (empty(static::$_repositoryClass[$self])) {
if (!empty(self::$_repository)) {
return self::$_repositoryClass[$self] = get_class(static::$_repository);
}

$default = '\Cake\ORM\Table';
$self = get_called_class();
$parts = explode('\\', $self);

if ($self === __CLASS__ || count($parts) < 3) {
return self::$_repositoryClass[$self] = $default;
}

$alias = array_pop($parts) . 'Table';
$class = implode('\\', array_slice($parts, 0, -1)) . '\Repository\\' . $alias;
if (!class_exists($class)) {
return self::$_repositoryClass[$self] = $default;
}

self::$_repositoryClass[$self] = $class;
}

$result = App::className(self::$_repositoryClass[$self], 'Model\Repository', 'Table');
if (!$result) {
throw new Error\MissingTableClassException([static::$_repositoryClass[$self]]);
}

return $result;
}

/**
* Returns the BelongsTo associations as statically defined in the $_belongsTo
* property
*
* @return array
*/
public static function belongsTo() {
return static::$_belongsTo;
}

/**
* Returns the HasOne associations as statically defined in the $_hasOne
* property
*
* @return array
*/
public static function hasOne() {
return static::$_hasOne;
}

/**
* Returns the HasMany associations as statically defined in the $_hasMany
* property
*
* @return array
*/
public static function hasMany() {
return static::$_hasMany;
}

/**
* Returns the BelongsToMany associations as statically defined in the
* $_belongsToMany property
*
* @return array
*/
public static function belongsToMany() {
return static::$_belongsToMany;
}

}
54 changes: 0 additions & 54 deletions Cake/ORM/Table.php
Expand Up @@ -127,12 +127,6 @@ class Table {
*/
protected $_entityClass = '\Cake\ORM\Entity';

/**
* Whether associations where copied already from the entity class or not
*
* @var boolean
*/
protected $_associationsInit = false;

/**
* Initializes a new instance
Expand Down Expand Up @@ -410,10 +404,6 @@ public function entityClass($name = null) {
* @return Cake\ORM\Association
*/
public function association($name) {
if (!$this->_associationsInit && $this->entityClass()) {
$this->_associationsInit = true;
$this->_setupAssociations();
}
if (isset($this->_associations[$name])) {
return $this->_associations[$name];
}
Expand Down Expand Up @@ -769,48 +759,4 @@ public function __call($method, $args) {
return $this->callFinder($method, $query, $options);
}

/**
* Copies association configuration from the entity class to the associations
* classes stored in this object
*
* @return void
*/
protected function _setupAssociations() {
$entity = $this->entityClass();
$types = [
'belongsTo' => false,
'hasOne' => false,
'hasMany' => true,
'belongsToMany' => true
];

foreach ($types as $assoc => $plural) {
$associations = $entity::$assoc();
foreach ($associations as $key => $val) {
if (is_integer($key)) {
$entityClass = App::classname($val, 'Model\Entity');
list(,$className) = pluginSplit($val);
list($key, $val) = [$className, compact('entityClass')];
}

if (!empty($val['className'])) {
$val['entityClass'] = App::classname($val['className'], 'Model\Entity');
unset($val['className']);
}

if (empty($val['property'])) {
$name = Inflector::variable($key);
$name = $plural ? Inflector::pluralize($name) : $name;
$val['property'] = $name;
}

$result = $this->{$assoc}($key, $val);
if ($assoc === 'belongsToMany' && !empty($val['with'])) {
$withClass = App::classname($val['with'], 'Model\Entity');
$result->pivot($withClass::repository());
}
}
}
}

}
13 changes: 0 additions & 13 deletions Cake/Test/TestApp/Model/Entity/Article.php

This file was deleted.

0 comments on commit 3103225

Please sign in to comment.