MockDocumentSource.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\mocks\data\model;
  9. class MockDocumentSource extends \lithium\data\Source {
  10. protected $_classes = array(
  11. 'entity' => 'lithium\data\entity\Document',
  12. 'set' => 'lithium\data\collection\DocumentSet',
  13. 'relationship' => 'lithium\data\model\Relationship',
  14. 'schema' => 'lithium\data\source\mongo_db\Schema'
  15. );
  16. public function connect() {}
  17. public function disconnect() {}
  18. public function sources($class = null) {}
  19. public function describe($entity, $schema = array(), array $meta = array()) {
  20. return $this->_instance('schema');
  21. }
  22. public function create($query, array $options = array()) {}
  23. public function update($query, array $options = array()) {}
  24. public function delete($query, array $options = array()) {}
  25. public $point = 0;
  26. public $result = null;
  27. public function read($query = null, array $options = array()) {
  28. $this->point = 0;
  29. $this->result = array(
  30. array('id' => 1, 'name' => 'Joe'),
  31. array('id' => 2, 'name' => 'Moe'),
  32. array('id' => 3, 'name' => 'Roe')
  33. );
  34. }
  35. public function getNext() {
  36. return $this->result[$this->point++];
  37. }
  38. public function result($type, $resource, $context) {
  39. switch ($type) {
  40. case 'next':
  41. $result = $resource->hasNext() ? $resource->getNext() : null;
  42. break;
  43. case 'close':
  44. unset($resource);
  45. $result = null;
  46. break;
  47. }
  48. return $result;
  49. }
  50. public function relationship($class, $type, $name, array $options = array()) {
  51. $key = Inflector::camelize($type === 'belongsTo' ? $name : $class::meta('name'));
  52. $options += compact('name', 'type', 'key');
  53. $options['from'] = $class;
  54. $relationship = $this->_classes['relationship'];
  55. return new $relationship($options);
  56. }
  57. }
  58. ?>