-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from matryoshka-model/develop
v0.5.0
- Loading branch information
Showing
22 changed files
with
1,540 additions
and
112 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,7 @@ matrix: | |
fast_finish: true | ||
allow_failures: | ||
- php: hhvm | ||
|
||
notifications: | ||
email: | ||
- ripaclub@gmail.com |
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
147 changes: 147 additions & 0 deletions
147
library/Matryoshka/Model/Object/AbstractActiveRecord.php
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,147 @@ | ||
<?php | ||
/** | ||
* Matryoshka | ||
* | ||
* @link https://github.com/matryoshka-model/matryoshka | ||
* @copyright Copyright (c) 2014, Copyright (c) 2014, Ripa Club | ||
* @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License | ||
*/ | ||
namespace Matryoshka\Model\Object; | ||
|
||
use Matryoshka\Model\Exception; | ||
use Matryoshka\Model\ModelAwareInterface; | ||
use Matryoshka\Model\ModelInterface; | ||
use Matryoshka\Model\AbstractModel; | ||
use Matryoshka\Model\Criteria\ActiveRecord\AbstractCriteria; | ||
use Matryoshka\Model\ModelAwareTrait; | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
abstract class AbstractActiveRecord extends AbstractObject implements | ||
ModelAwareInterface, | ||
ActiveRecordInterface | ||
{ | ||
|
||
use ModelAwareTrait; | ||
|
||
/** | ||
* @var AbstractCriteria | ||
*/ | ||
protected $activeRecordCriteriaPrototype; | ||
|
||
/** | ||
* Set Active Record Criteria Prototype | ||
* | ||
* @param AbstractCriteria $criteria | ||
* @return $this | ||
*/ | ||
public function setActiveRecordCriteriaPrototype(AbstractCriteria $criteria) | ||
{ | ||
$this->activeRecordCriteriaPrototype = $criteria; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* Set Model | ||
* | ||
* @param ModelInterface $model | ||
* @return $this | ||
*/ | ||
public function setModel(ModelInterface $model) | ||
{ | ||
if (!$model instanceof AbstractModel) { | ||
throw new Exception\InvalidArgumentException( | ||
'AbstractModel required in order to work with ActiveRecord' | ||
); | ||
} | ||
$this->model = $model; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Save | ||
* | ||
* @return null|int | ||
* @throws Exception\RuntimeException | ||
*/ | ||
public function save() | ||
{ | ||
if (!$this->activeRecordCriteriaPrototype) { | ||
throw new Exception\RuntimeException('An Active Record Criteria Prototype must be set prior to calling save()'); | ||
} | ||
|
||
if (!$this->getModel()) { | ||
throw new Exception\RuntimeException('A Model must be set prior to calling save()'); | ||
} | ||
|
||
$criteria = clone $this->activeRecordCriteriaPrototype; | ||
$result = $this->getModel()->save($criteria, $this); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Delete | ||
* | ||
* @return null|int | ||
* @throws Exception\RuntimeException | ||
*/ | ||
public function delete() | ||
{ | ||
if (!$this->getId()) { | ||
throw new Exception\RuntimeException('An ID must be set prior to calling delete()'); | ||
} | ||
|
||
if (!$this->activeRecordCriteriaPrototype) { | ||
throw new Exception\RuntimeException('An Active Record Criteria Prototype must be set prior to calling delete()'); | ||
} | ||
|
||
if (!$this->getModel()) { | ||
throw new Exception\RuntimeException('A Model must be set prior to calling delete()'); | ||
} | ||
|
||
$criteria = clone $this->activeRecordCriteriaPrototype; | ||
$criteria->setId($this->getId()); | ||
$result = $this->getModel()->delete($criteria); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Get | ||
* | ||
* @param $name | ||
* @throws Exception\InvalidArgumentException | ||
* @return void | ||
*/ | ||
public function __get($name) | ||
{ | ||
throw new Exception\InvalidArgumentException('Not a valid field in this object: ' . $name); | ||
} | ||
|
||
/** | ||
* Set | ||
* | ||
* @param string $name | ||
* @param mixed $value | ||
* @throws Exception\InvalidArgumentException | ||
* @return void | ||
*/ | ||
public function __set($name, $value) | ||
{ | ||
throw new Exception\InvalidArgumentException('Not a valid field in this object: ' . $name); | ||
} | ||
|
||
/** | ||
* Unset | ||
* | ||
* @param string $name | ||
* @throws Exception\InvalidArgumentException | ||
* @return void | ||
*/ | ||
public function __unset($name) | ||
{ | ||
throw new Exception\InvalidArgumentException('Not a valid field in this object: ' . $name); | ||
} | ||
} |
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
Oops, something went wrong.