Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Remove unused/deprecated stuff #472

Merged
merged 2 commits into from

2 participants

@jails
Collaborator

Maybe i'm wrong but after some investigations it looks likes some code is unnecessary and/or deprecated or simply can't work in the current state of the framework.

@jails
Collaborator

I re-commit the PR in data branch. You need my old comments on files ?

@nateabele nateabele commented on the diff
data/Model.php
@@ -310,9 +296,8 @@ class Model extends \lithium\core\StaticObject {
* @param array $options Meta-information for this model, such as the connection.
*/
public static function config(array $options = array()) {
- if (static::_isBase($class = get_called_class())) {
@nateabele Owner

Instead of dropping the if block entirely, it should probably be changed to if (($class = get_called_class()) === __CLASS__) {.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jails
Collaborator

you're right.

@nateabele nateabele merged commit fffaa53 into UnionOfRAD:data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 22, 2012
  1. @jails

    Remove unused/deprecated stuff

    jails authored
  2. @jails

    Remove unused/deprecated stuff

    jails authored
This page is out of date. Refresh to see the latest.
View
31 data/Model.php
@@ -282,20 +282,6 @@ class Model extends \lithium\core\StaticObject {
protected $_finders = array();
/**
- * List of base model classes. Any classes which are declared to be base model classes (i.e.
- * extended but not directly interacted with) must be present in this list. Models can declare
- * themselves as base models using the following code:
- * {{{
- * public static function __init() {
- * static::_isBase(__CLASS__, true);
- * }
- * }}}
- *
- * @var array
- */
- protected static $_baseClasses = array(__CLASS__ => true);
-
- /**
* Stores all custom instance methods created by `Model::instanceMethods`.
*
* @var array
@@ -310,9 +296,10 @@ class Model extends \lithium\core\StaticObject {
* @param array $options Meta-information for this model, such as the connection.
*/
public static function config(array $options = array()) {
- if (static::_isBase($class = get_called_class())) {
@nateabele Owner

Instead of dropping the if block entirely, it should probably be changed to if (($class = get_called_class()) === __CLASS__) {.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if (($class = get_called_class()) === __CLASS__) {
return;
}
+
if (!isset(static::$_instances[$class])) {
static::$_instances[$class] = new $class();
}
@@ -1105,20 +1092,6 @@ protected static function _relations() {
}
/**
- * Helper function for setting/getting base class settings.
- *
- * @param string $class Classname.
- * @param boolean $set If `true`, then the `$class` will be set.
- * @return boolean Success.
- */
- protected static function _isBase($class = null, $set = false) {
- if ($set) {
- static::$_baseClasses[$class] = true;
- }
- return isset(static::$_baseClasses[$class]);
- }
-
- /**
* Exports an array of custom finders which use the filter system to wrap around `find()`.
*
* @return void
View
64 data/collection/DocumentSet.php
@@ -11,70 +11,6 @@
class DocumentSet extends \lithium\data\Collection {
/**
- * PHP magic method used when setting properties on the `Document` instance, i.e.
- * `$document->title = 'Lorem Ipsum'`. If `$value` is a complex data type (i.e. associative
- * array), it is wrapped in a sub-`Document` object before being appended.
- *
- * @param $name The name of the field/property to write to, i.e. `title` in the above example.
- * @param $value The value to write, i.e. `'Lorem Ipsum'`.
- * @return void
- */
- public function __set($name, $value = null) {
- if (is_array($name) && !$value) {
- foreach ($name as $key => $value) {
- $this->__set($key, $value);
- }
- return;
- }
-
- if (is_string($name) && strpos($name, '.')) {
- $current = $this;
- $path = explode('.', $name);
- $length = count($path) - 1;
-
- for ($i = 0; $i < $length; $i++) {
- $key = $path[$i];
- $next = $current->__get($key);
-
- if ($schema = $this->schema()) {
- $next = $schema->cast($this, $next);
- $current->_data[$key] = $next;
- }
- $current = $next;
- }
- $current->__set(end($path), $value);
- }
-
- if (is_array($value)) {
- $value = $this->_relation('set', $name, $value);
- }
- $this->_data[$name] = $value;
- }
-
- /**
- * PHP magic method used to check the presence of a field as document properties, i.e.
- * `$document->_id`.
- *
- * @param $name The field name, as specified with an object property.
- * @return boolean True if the field specified in `$name` exists, false otherwise.
- */
- public function __isset($name) {
- return isset($this->_data[$name]);
- }
-
- /**
- * PHP magic method used when unset() is called on a `Document` instance.
- * Use case for this would be when you wish to edit a document and remove a field, ie. :
- * {{{ $doc = Post::find($id); unset($doc->fieldName); $doc->save(); }}}
- *
- * @param unknown_type $name
- * @return unknown_type
- */
- public function __unset($name) {
- unset($this->_data[$name]);
- }
-
- /**
* Allows several properties to be assigned at once.
*
* For example:
View
37 tests/integration/data/SourceTest.php
@@ -239,43 +239,6 @@ public function testDefaultRelationshipInfo() {
$this->assertEqual($this->_classes['employees'], $result->data('to'));
}
- public function testRelationshipQuerying() {
- $connection = $this->_connection;
- $message = "Relationships are not supported by this adapter.";
- $this->skipIf(!$connection::enabled('relationships'), $message);
-
- foreach ($this->companiesData as $data) {
- Companies::create($data)->save();
- }
- $stuffMart = Companies::findFirstByName('StuffMart');
- $maAndPas = Companies::findFirstByName('Ma \'n Pa\'s Data Warehousing & Bait Shop');
-
- $this->assertEqual($this->_classes['employees'], $stuffMart->employees->model());
- $this->assertEqual($this->_classes['employees'], $maAndPas->employees->model());
-
- foreach (array('Mr. Smith', 'Mr. Jones', 'Mr. Brown') as $name) {
- $stuffMart->employees[] = Employees::create(compact('name'));
- }
- $expected = Companies::key($stuffMart) + array(
- 'name' => 'StuffMart', 'active' => true, 'employees' => array(
- array('name' => 'Mr. Smith'),
- array('name' => 'Mr. Jones'),
- array('name' => 'Mr. Brown')
- )
- );
- $this->assertEqual($expected, $stuffMart->data());
- $this->assertTrue($stuffMart->save());
- $this->assertEqual('Smith', $stuffMart->employees[0]->lastName());
-
- $stuffMartReloaded = Companies::findFirstByName('StuffMart');
- $this->assertEqual('Smith', $stuffMartReloaded->employees[0]->lastName());
-
- foreach (array('Ma', 'Pa') as $name) {
- $maAndPas->employees[] = Employees::create(compact('name'));
- }
- $maAndPas->save();
- }
-
public function testAbstractTypeHandling() {
$key = Companies::meta('key');
View
4 tests/mocks/data/MockBase.php
@@ -17,10 +17,6 @@ class MockBase extends \lithium\data\Model {
public static $connection = null;
- public static function __init() {
- static::_isBase(__CLASS__, true);
- }
-
public static function resetSchema($array = false) {
if ($array) {
return static::_object()->_schema = array();
View
84 tests/mocks/data/model/MockDocumentSource.php
@@ -47,90 +47,6 @@ public function getNext() {
return $this->result[$this->point++];
}
- public function cast($entity, array $data, array $options = array()) {
- $defaults = array('schema' => null, 'first' => false, 'pathKey' => null, 'arrays' => true);
- $options += $defaults;
- $model = null;
- $exists = false;
-
- if (!$data) {
- return $data;
- }
-
- if ($entity && !$options['schema']) {
- $options['schema'] = $entity->schema() ?: array('_id' => array('type' => 'id'));
- }
- if ($entity) {
- if (!($entity instanceof $this->_classes['set'])) {
- $exists = $entity->exists();
- }
- $model = $entity->model();
- }
- $options['exists'] = $exists;
- $schema = $options['schema'];
- unset($options['schema']);
-
- $handlers = array(
- 'id' => function($v) {
- return is_string($v) && preg_match('/^[0-9a-f]{24}$/', $v) ? new MongoId($v) : $v;
- },
- 'date' => function($v) {
- $v = is_numeric($v) ? intval($v) : strtotime($v);
- return (time() == $v) ? new MongoDate() : new MongoDate($v);
- },
- 'regex' => function($v) { return new MongoRegex($v); },
- 'integer' => function($v) { return (integer) $v; },
- 'float' => function($v) { return (float) $v; },
- 'boolean' => function($v) { return (boolean) $v; },
- 'code' => function($v) { return new MongoCode($v); },
- 'binary' => function($v) { return new MongoBinData($v); }
- );
-
- $typeMap = array(
- 'MongoId' => 'id',
- 'MongoDate' => 'date',
- 'MongoCode' => 'code',
- 'MongoBinData' => 'binary',
- 'datetime' => 'date',
- 'timestamp' => 'date',
- 'int' => 'integer'
- );
-
- foreach ($data as $key => $value) {
- if (is_object($value)) {
- continue;
- }
- $path = is_int($key) ? null : $key;
- $path = $options['pathKey'] ? trim("{$options['pathKey']}.{$path}", '.') : $path;
- $field = (isset($schema[$path]) ? $schema[$path] : array());
- $field += array('type' => null, 'array' => null);
- $type = isset($typeMap[$field['type']]) ? $typeMap[$field['type']] : $field['type'];
- $isObject = ($type == 'object');
- $isArray = (is_array($value) && $field['array'] !== false && !$isObject);
-
- if (isset($handlers[$type])) {
- $handler = $handlers[$type];
- $value = $isArray ? array_map($handler, $value) : $handler($value);
- }
- if (!$options['arrays']) {
- $data[$key] = $value;
- continue;
- }
- $pathKey = $path;
-
- if (is_array($value)) {
- $arrayType = !$isObject && (array_keys($value) === range(0, count($value) - 1));
- $opts = $arrayType ? array('class' => 'array') + $options : $options;
- $value = $this->item($model, $value, compact('pathKey') + $opts);
- } elseif ($field['array']) {
- $opts = array('class' => 'array') + $options;
- $value = $this->item($model, array($value), compact('pathKey') + $opts);
- }
- $data[$key] = $value;
- }
- return $options['first'] ? reset($data) : $data;
- }
-
public function result($type, $resource, $context) {
switch ($type) {
case 'next':
Something went wrong with that request. Please try again.