/** * Restrictions Class Constructor * * Takes the allowed types ($allowed), the allowed classes (optional), * and the options pertinent to the Restrictions class. Normalizes and * sets up the predicate structures necessary to evaluate data types * from the input data. * * Options: autoload - Do we autoload classes when checking for * their existence? * allowed - Set Interface Dependency Injection (optional) * classes - Set Interface Dependency Injection (optional) * type_class - The class to instantiate for type checking * * @param array $allowed (Required) the allowed data types as defined * in Type::enumerator * @param array $classes The classes to be allowed if $allowed * contains Type::TYPED_OBJECT * @param array $options The options ('autoload') for the given * Restrictions object * * @throws Exception\RangeException if data type doesn't match * any Type:: constants * @throws Exception\RuntimeException if a class doesn't exist to match * a class in the $classes member */ public function __construct(array $allowed, array $classes = array(), $options = array()) { if (is_array($options)) { $options = array_change_key_case($options); } $options = array_merge(array('autoload' => false, 'type_class' => 'Falcraft\\Data\\Types\\Type', 'allowed' => null, 'classes' => null), $options); $this->configure($options); $allowed = array_unique($allowed); $classes = array_unique($classes); $type_class = $this->conf->type_class; /* Check to see if the allowed types are in the 'allowed types' Type::constants */ $consts = $type_class::getConstants(); foreach ($allowed as $type) { if (!in_array($type, $consts)) { throw new Exception\RangeException('Restrictions->__construct: Cannot Construct New ' . 'Predicate With Enumerator Value ' . $type); } } /* Make allowed types into a set, strictly, guaranteeing no duplicate types */ if ($this->conf->allowed) { if ($this->conf->allowed instanceof Resource\SetInterface) { $this->allowed =& $this->conf->allowed; } } else { $this->allowed = new Set($allowed, array('strict' => true, 'unique' => true)); } /* If there are classes passed to the constructor automatically enable Type::TYPED_OBJECT */ if (!$this->allowed->in($type_class::TYPED_OBJECT) && !empty($classes)) { $this->allowed->add($type_class::TYPED_OBJECT); } /* If Type::TYPED_OBJECT is available and Type::BASIC_OBJECT is present, it messes up the predicate logic */ if ($this->allowed->in($type_class::TYPED_OBJECT) && $this->allowed->in($type_class::BASIC_OBJECT)) { $this->allowed->remove($type_class::BASIC_OBJECT); } /* Check that each class defined in the classes input actually exists, does NOT autoload by default */ foreach ($classes as $class) { if (!class_exists($class, $this->conf->autoload)) { if (!interface_exists($class, $this->conf->autoload)) { throw new Exception\RuntimeException('Restrictions->__construct: Undefined Class ' . 'Classification: ' . $class); } } } /* Make allowed classes into a set, strictly, gauranteeing no duplicate classes */ if ($this->conf->classes) { if ($this->conf->classes instanceof Resource\SetInterface) { $this->classes =& $this->conf->classes; } } else { $this->classes = new Set($classes, array('strict' => true, 'unique' => true)); } }
/** * Remove a category from the event * * @param string $cat * */ public function removeCategory($cat) { $this->categories->remove($cat); }
/** * Remove a method from the method list * * This method removes a method from the method list only if the class * has not been generated, otherwise it throws an error * * Remember: NOT makeMethod, just method * * @param string $method Name of the method * * @throws \RuntimeException if the class has already been baked * */ public function removeMethod($method) { if (!$this->baked) { $this->methods->remove($method); } else { throw new TypesException\RuntimeException('AbstractFactory->removeMethod: ' . $this->namespace . '\\Abstract' . $factoryName . 'Factory already defined'); } }