Beispiel #1
0
 /**
  * Get the tags associated with this event
  * 
  * NOTE: This returns an array
  * 
  * @return array
  * 
  */
 public function getTags()
 {
     return $this->tags->getArray();
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * Gets the abstract factory methods
  * 
  * @return array Array of abstract factory methods
  * 
  */
 public function getMethods()
 {
     return $this->methods->getArray();
 }