/** * Sets up the namespace to be used when generating the abstract factory class * * This sets the namespace that will be used when the enumerator class is generated * How? Eval statements operate in the global namespace, or basically a clean slate * enabling us to put a namespace statement at the beginning of our generated code * Any namespace will do, if there is no namespace, you must access your abstract factory * using the global namespace. ex: \Months::January, \Colors::Red, ... * * @param string $namespace The namespace specified * * @throws \RangeException when the class/namespace has already been generated via Enum * @throws \RuntimeException if the class has already been generated/baked. * */ public function setNamespace($namespace) { if (!$this->baked) { if (self::$factories->in($namespace . '\\' . $this->className)) { throw new TypesException\RangeException('AbstractFactory->setNamespace: ' . $namespace . '\\' . $this->className . ' Enumeration Already Defined'); } $this->namespace = $namespace; } else { throw new TypesException\RuntimeException('AbstractFactory->setNamespace: ' . $this->namespace . '\\' . $this->className . ' Enumeration Namespace Already Baked'); } }
/** * Is a type allowed in this restriction? * * This steps through a given type, be it Falcraft\Data\Types\Type, * Integer, String, or Array. If it's not a Type object, to specify * a particular typed class you provide array( type [Type, Integer, * String], className) because an array can be passed with one argument * to turn into a Type object it still converts the array[0] to a Type * object * * For flexibility in type checking (if container object is strict * or not) we provide a strict option in the function rather than the * object at constructor time. * * NOTE: if Falcraft\Data\Types\Type throws an \UnexpectedValueException, * we just silently return false, unless param $strict is true * * @param Falcraft\Data\Types\Type|array|int|string $type The type to * check * @param bool $strict Should we throw errors? * * @return bool Allowed or not? * * @throws \UnexpectedValueException if strict rethrows the type * construction error * */ public function isAllowed($type, $strict = false) { $typeClass = $this->conf->type_class; // Is $type an actual enumerated instance? if (!$type instanceof Type) { // No it isn't, groom the $type variable if (is_int($type)) { try { /* construct as number, same as constructing with a constant */ $type = new $typeClass($type); } catch (\UnexpectedValueException $e) { // Remember Type enum eval'd code returns root Exception if ($strict) { throw new Exception\UnexpectedValueException('Restrictions->isAllowed: Incorrect integer ' . 'given for type'); } return false; } } else { if (is_string($type)) { // construct from string (see Type.php) $type = Type\stringToType($type); if ($type == null) { return false; } } else { if (is_array($type)) { // We are dealing with an object type if (count($type) == 2) { /* This allows you to pass the class name of an object or an actualy object itself as elemnt[2], to see if that object would pass */ // Is array[0] (type) actual enumeration instance? if ($type[0] instanceof Type) { if ($type[0]->get() == Type::TYPED_OBJECT) { $obj = $type[1]; // Object is not instance but string of class if (!is_object($obj)) { $obj = new $obj(); } $type = new $typeClass(); // eliminate array // Temporarily store object for use below $type->set($obj); } // Just an integer (constant value) } else { if (is_int($type[0]) && $type[0] == Type::TYPED_OBJECT) { $obj = $type[1]; // Object is not instance but string of class if (!is_object($obj)) { if (class_exists($obj)) { $obj = new $obj(); } else { throw new Exception\UnexpectedValueException('Restrictions->isAllowed: Passed Invalid' . 'Class as String'); } } $type = new $typeClass(); // eliminate array // Temporarily store object for use below $type->set($obj); } else { throw new Exception\UnexpectedValueException('Restrictions->isAllowed: TYPED_OBJECT Not ' . 'present in array'); } } } else { throw new Exception\UnexpectedValueException('Restrictions->isAllowed: Passed array has more ' . 'than two elements.'); } } else { return false; } } } } // Now $type is groomed to be a Type object // check type or class as appropriate if (!is_object($type->get())) { // Not a typed object (post grooming) return $this->allowed->in($type->get()); } else { // 1.3: Modified this code to check not only if the object is // of a class, but a derivation of any classes too. $obj = $type->get(); if (!$this->classes->in(get_class($obj))) { // The object's class is not in the list of allowed classes // But is it a derived class of a class in the list? $classes = $this->classes->getArray(); foreach ($classes as $c) { if ($obj instanceof $c) { return true; } } } else { return true; } } // Default return false; }
/** * Is a tag associated with this particular event * * @param string $tag * * @return bool * */ public function isTag($tag) { return $this->tags->in($tag); }