This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add record iterator and simple model implementation.
- Loading branch information
Showing
5 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
// Jivoo Data | ||
// Copyright (c) 2016 Niels Sonnich Poulsen (http://nielssp.dk) | ||
// Licensed under the MIT license. | ||
// See the LICENSE file or http://opensource.org/licenses/MIT for more information. | ||
namespace Jivoo\Data; | ||
|
||
/** | ||
* An iterator that converts associative arrays to {@see Record}s. | ||
*/ | ||
class RecordIterator implements \Iterator | ||
{ | ||
|
||
/** | ||
* @var \Iterator | ||
*/ | ||
private $data; | ||
|
||
/** | ||
* @var Model | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var Query\ReadSelection | ||
*/ | ||
private $selection; | ||
|
||
/** | ||
* Construct iterator. | ||
* | ||
* @param \Iterator $data Data iterator. | ||
* @param \Jivoo\Data\Model $model Model. | ||
* @param \Jivoo\Data\Query\ReadSelection $selection Read selection. | ||
*/ | ||
public function __construct(\Iterator $data, Model $model, \Jivoo\Data\Query\ReadSelection $selection) | ||
{ | ||
$this->data = $data; | ||
$this->model = $model; | ||
$this->selection = $selection; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function current() | ||
{ | ||
return $this->model->open($this->data->current(), $this->selection); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function key() | ||
{ | ||
return $this->data->key(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function next() | ||
{ | ||
$this->data->next(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function rewind() | ||
{ | ||
$this->data->rewind(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function valid() | ||
{ | ||
return $this->data->valid(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
// Jivoo Data | ||
// Copyright (c) 2016 Niels Sonnich Poulsen (http://nielssp.dk) | ||
// Licensed under the MIT license. | ||
// See the LICENSE file or http://opensource.org/licenses/MIT for more information. | ||
namespace Jivoo\Data; | ||
|
||
/** | ||
* A simple {@see Model} implementation. | ||
*/ | ||
class SimpleModel extends ModelBase | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var DataSource | ||
*/ | ||
private $source; | ||
|
||
/** | ||
* @var Definition | ||
*/ | ||
private $definition; | ||
|
||
/** | ||
* Construct simple model. | ||
* | ||
* @param type $name Model name. | ||
* @param \Jivoo\Data\DataSource $source Data source. | ||
* @param \Jivoo\Data\Jivoo\Data\Definition $definition Data definition. | ||
*/ | ||
public function __construct($name, DataSource $source, Jivoo\Data\Definition $definition) | ||
{ | ||
$this->name = $name; | ||
$this->source = $source; | ||
$this->definition = $definition; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function countSelection(Query\ReadSelection $selection) | ||
{ | ||
return $this->source->countSelection($selection); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function deleteSelection(Query\Selection $selection) | ||
{ | ||
return $this->source->deleteSelection($selection); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDefinition() | ||
{ | ||
return $this->definition; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function insert(array $data, $replace = false) | ||
{ | ||
return $this->source->insert($data, $replace); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function insertMultiple(array $records, $replace = false) | ||
{ | ||
return $this->source->insertMultiple($records, $replace); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function joinWith(DataSource $other) | ||
{ | ||
return $this->source->joinWith($other); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function readSelection(Query\ReadSelection $selection) | ||
{ | ||
return $this->source->readSelection($selection); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function updateSelection(Query\UpdateSelection $selection) | ||
{ | ||
return $this->source->updateSelection($selection); | ||
} | ||
} |