Modifiche ai model Rimossa la constrained interface in quanto inefficace e troppo pesante
67 lines
1.3 KiB
PHP
67 lines
1.3 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 08/gen/2016
|
|
*/
|
|
|
|
class ConstrainedArrayObject extends Constrained implements ArrayAccess {
|
|
private $base = array();
|
|
|
|
public function __construct(array $base){
|
|
parent::__construct();
|
|
$this->setBase($base);
|
|
}
|
|
|
|
protected function setBase($base){
|
|
foreach ($base as $key=>$value){
|
|
$this->base[$key] = ConstrainedFactory::build($value);
|
|
}
|
|
}
|
|
|
|
public function getBase(){
|
|
return $this->base;
|
|
}
|
|
|
|
protected function addPathToChildException($myKey, ConstraintException $ex){
|
|
$newKey = $myKey."[".$ex->getRelatedKey()."]";
|
|
return new ConstraintException($ex->getRelatedOperation(), $newKey, $ex->getRelatedValue());
|
|
}
|
|
|
|
protected function setInternal($key,$value){
|
|
if (is_null($key)) {
|
|
$this->base[] = $value;
|
|
}
|
|
else {
|
|
$this->base[$key] = $value;
|
|
}
|
|
}
|
|
|
|
protected function getInternal($key){
|
|
return $this->offsetExists($key) ? $this->base[$key] : null;
|
|
}
|
|
|
|
protected function unsetInternal($key){
|
|
unset($this->base[$key]);
|
|
}
|
|
|
|
|
|
// ArrayAccess methods
|
|
public function offsetExists($key) {
|
|
return array_key_exists($key, $this->base);
|
|
}
|
|
|
|
public function offsetSet($key, $value) {
|
|
$this->setConstrained($key, $value);
|
|
}
|
|
|
|
public function offsetUnset($key) {
|
|
$this->unsetConstrained($key);
|
|
}
|
|
|
|
public function offsetGet($key) {
|
|
$this->getConstrained($key);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|