/** * AbstractRestrictedList Constructor * * Populates the internal member array, as well as the Predicate object * * Note: if no restrictions predicate object is given, a predicate object * inclusive of all types (except Type::TYPED_OBJECT) is generated * * Creates an empty list if no parameter given. * * * Options: strict - Do we raise appropriate exceptions when values * are misaligned? * * @param mixed $data The data to populate the internal member array * @param Falcraft\Data\Types\Resource\AbstractFilter $restrictions * The predicate type object * @param array $options The options for the array * * @throws Exception\InvalidArgumentException If an illegal value is * given to the object (not in restrictions) * */ public function __construct($data = null, AbstractFilter $restrictions = null, $options = array()) { if (is_array($options)) { $options = array_change_key_case($options); } $this->configure($options); // If there are no restrictions given, build basic free form restrictions // Default doesn't allow Type::TYPED_OBJECT if (!$restrictions) { $restrictions = Types\Restrictions::getDefaultRestrictions(); } $this->restrictions = $restrictions; if (is_array($data)) { // Plain Array /* Check input values for any illegal types If false, throw error because this is a constructor and can' really return anything. */ if (!Types\Restrictions::checkElements($data, $this->restrictions, $this->conf->strict)) { throw new Exception\InvalidArgumentException('AbstractRestrictedList->__construct: Illegal Value'); } } else { if ($data instanceof AbstractList) { // Falcraft\Data\Types\FList\AbstractList /* Check input values for any illegal types If false, throw error because this is a constructor and can't really return anything. */ if (!Types\Restrictions::checkElements($data->getList(), $this->restrictions, $this->conf->strict)) { throw new Exception\InvalidArgumentException('AbstractRestrictedList->__construct: Illegal Value'); } } else { if ($data) { // A scalar value /* Check input values for any illegal types If false, throw error because this is a constructor and can't really return nothing */ if (!Types\Restrictions::checkElements(array($data), $this->restrictions, $this->conf->strict)) { throw new Exception\InvalidArgumentException('AbstractRestrictedList->__construct: Illegal Value'); } } } } parent::__construct($data, $options); }
/** * RestrictedSet Class Constructor * * This sets up the restrictions for the values, then provides the * options to the parent set. This is the only place to set the * restrictions for the set. * * @param array $values The values for the RestrictedSet * @param Falcraft\Data\Types\Resource\AbstractFilter $restrictions * The restrictions for the data type * @param array $options The options for the parent set. * */ public function __construct(array $values = array(), DataResource\AbstractFilter $restrictions = null, $options = array()) { if (is_array($options)) { $options = array_change_key_case($options); } $this->configure($options); // If there are no restrictions given, build basic free form restrictions // Default doesn't allow Type::TYPED_OBJECT if (!$restrictions) { $restrictions = Restrictions::getDefaultRestrictions(); } $this->restrictions = $restrictions; /* Check input values for any illegal types If false, throw error because this is a constructor and can't really return nothing */ if (!Restrictions::checkElements($values, $this->restrictions)) { throw new Exception\InvalidArgumentException('RestrictedSet->__construct: Illegal Value'); } // Construct set parent::__construct($values, $options); }
try { $testRestrictions = new Types\Restrictions(array(Type::TYPED_OBJECT), array('Falcraft\\Data\\Types\\Range'), array('autoload' => true)); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n"; } else { echo "Failure...\n"; } echo "--- NOTE: If appropriate autoloader function missing, this fails expectedly\n\n"; echo "Get Default Restrictions -> "; $success = true; $defaultRestrictions = null; try { $defaultRestrictions = Types\Restrictions::getDefaultRestrictions(); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\nAllowed Types -- \n\n"; var_dump($defaultRestrictions->getAllowedTypes()); echo "\n"; } else { echo "Failure...\n"; } echo "Predicate Retrieval -> "; $success = true; $testRestrictions = $allowedTypes = $allowedClasses = null; require_once '../../../Data/Types/Set.php'; require_once '../../../Data/Types/Range.php';