Пример #1
0
 /**
  * Add a value to the set as a reference
  * 
  * Runs the value by the restrictions, only triggering if set is strict
  * otherwise doing nothing and exiting the function
  * 
  * @param mixed $value Value to add to the set, must be of allowed type
  * 
  * @return string|false The datum identifier, false otherwise
  * 
  * @throws Exception\InvalidArgumentException if 'strict' option is set
  *             and type is not in Restrictions
  * 
  */
 public function addReference(&$value)
 {
     try {
         $valid = Restrictions::checkElements(array($value), $this->restrictions, $this->conf->strict);
     } catch (Exception\InvalidArgumentException $e) {
         if ($this->conf->strict) {
             throw new Exception\InvalidArgumentException('RestrictedSet->addReference: Restricted Value');
         } else {
             return false;
         }
     }
     // Passes restrictions, but safety check
     if ($valid) {
         return parent::addReference($value);
     }
 }
Пример #2
0
 /**
  * Checks a value to see if it is in restrictions
  * 
  * @param mixed $values,.. The values to check
  * 
  * @return boolean Allowed or not?
  * 
  * @throws Exception\InvalidArgumentException if value not in
  *             restrictions, and strict option is set
  * 
  */
 private function check()
 {
     if (!Types\Restrictions::checkElements(func_get_args(), $this->restrictions, $this->conf->strict)) {
         if ($this->conf->strict) {
             throw new Exception\InvalidArgumentException('AbstractRestrictedList->check: Value not in ' . 'restrictions');
         } else {
             return false;
         }
     }
     return true;
 }
Пример #3
0
 /**
  * Set the offset in the list to the provided value
  * 
  * @param int $key The index to the list item
  * @param mixed $value The value to set to
  * 
  * @return int|Falcraft\Data\Types\Null New number of list elements,
  *              or Null otherwise
  * 
  * @throws Exception\InvalidArgumentException if the value doesn't meet
  *              restrictions
  * 
  */
 public function offsetSet($key, $value)
 {
     if (Restrictions::checkElements(array($value), $this->restrictions, $this->conf->strict)) {
         $this->list->offsetSet($key, $value);
     } else {
         if ($this->conf->strict) {
             throw new Exception\InvalidArgumentException('RestrictedStack->offsetSet: type not allowed');
         } else {
             return;
         }
     }
 }
Пример #4
0
 /**
  * The Leaf Constructor
  * 
  * This accepts an array of leaves (LeafInterface)
  * 
  * Options - identifier: Instantiate the leaf with a specific identifier
  *           prefix: set the identifier prefix
  *           strict: throw errors
  *           NOTE: There is no check for duplicate identifiers
  * 
  * @param array $leaves A plain array of LeafInterface compatible objects
  * @param array $options StandardObject options, see above
  * 
  */
 public function __construct(array $leaves = array(), $options = array())
 {
     // Set default options
     if (is_array($options)) {
         $options = array_change_key_case($options);
     }
     // default values
     $options = array_merge(array('identifier' => false, 'prefix' => 'Leaf', 'strict' => false), $options);
     $this->configure($options);
     if ($this->conf->identifier) {
         $this->identifier = $this->conf->identifier;
     }
     if ($this->conf->prefix) {
         $this->identityPrefix = $this->conf->prefix;
     }
     $leafRestrictions = new Types\Restrictions(array(Type::TYPED_OBJECT), array('Falcraft\\Data\\Types\\Resource\\LeafInterface'), array('strict' => true));
     $allowed = Types\Restrictions::checkElements($leaves, $leafRestrictions, array('strict' => true));
     if ($allowed) {
         $this->leaves = new Types\RestrictedList(array(), $leafRestrictions, array('strict' => true));
         foreach ($leaves as $leaf) {
             $this->leaves[$leaf->getIdentifier()] = $leaf;
         }
     } else {
         if ($this->conf->strict) {
             throw new Exception\InvalidArgumentException('AbstractLeaf->__construct(): Illegal Value');
         }
     }
 }