Beispiel #1
0
 /**
  * Checks whether a given thrown exception is contained in this collection
  *
  * @param  var $arg Either a string or a type mirror
  * @return bool
  */
 public function contains($arg)
 {
     $search = $arg instanceof TypeMirror ? $arg->name() : strtr($arg, '\\', '.');
     foreach ($this->tags as $tag) {
         if ($search === $tag->name()) {
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
 /**
  * Creates a new iteration
  *
  * @param  var $traversable Either a Traversable instance or an array
  * @param  function(var): var $mapping
  */
 public function __construct($traversable, $mapping)
 {
     if ($traversable instanceof \Iterator) {
         $this->it = $traversable;
     } else {
         if ($traversable instanceof \IteratorAggregate) {
             $this->it = $traversable->getIterator();
         } else {
             $this->it = new \ArrayIterator($traversable);
         }
     }
     $this->mapping = $mapping;
 }
Beispiel #3
0
 /**
  * Creates a new resource-based XML input
  *
  * @param  var $arg Either a lang.reflect.Package, a lang.XPClass or a string referring to a package
  * @param  string $name
  */
 public function __construct($arg, $name)
 {
     if ($arg instanceof XPClass) {
         $this->package = $arg->getPackage();
     } else {
         if ($arg instanceof Package) {
             $this->package = $arg;
         } else {
             $this->package = Package::forName(strtr($arg, '\\', '.'));
         }
     }
     $this->name = $name;
 }
 /**
  * Invocation overloading
  *
  * @param  var $context
  * @return var
  */
 public function __invoke($context)
 {
     $r = $context->lookup($this->name);
     if ($context->isCallable($r)) {
         // Subexpressions are called with their options as arguments,
         // which in turn may be subexpressions or values to be looked up.
         $pass = [];
         foreach ($this->options as $key => $option) {
             $pass[$key] = $option($context);
         }
         return $r(null, $context, $pass);
     } else {
         return $r;
     }
 }
 /**
  * Helper method to retrieve a pointer inside a given data structure
  * using a given segment. Returns null if there is no such segment.
  *
  * @param  var $ptr
  * @param  string $segment
  * @return var
  */
 protected function pointer($ptr, $segment)
 {
     if ($ptr instanceof \ArrayAccess) {
         return $ptr->offsetExists($segment) ? $ptr->offsetGet($segment) : null;
     } else {
         if (is_object($ptr)) {
             $class = typeof($ptr);
             // 1. Try public field named <segment>
             if ($class->hasField($segment)) {
                 $field = $class->getField($segment);
                 if ($field->getModifiers() & MODIFIER_PUBLIC) {
                     return $field->get($ptr);
                 }
             }
             // 2. Try public method named <segment>
             if ($class->hasMethod($segment)) {
                 $method = $class->getMethod($segment);
                 if ($method->getModifiers() & MODIFIER_PUBLIC) {
                     return $method->invoke($ptr);
                 }
             }
             // 3. Try accessor named get<segment>()
             if ($class->hasMethod($getter = 'get' . $segment)) {
                 $method = $class->getMethod($getter);
                 if ($method->getModifiers() & MODIFIER_PUBLIC) {
                     return $method->invoke($ptr);
                 }
             }
             // Non applicable - give up
             return null;
         } else {
             if (isset($ptr[$segment])) {
                 return $ptr[$segment];
             } else {
                 if ('length' === $segment) {
                     return sizeof($ptr);
                 } else {
                     return null;
                 }
             }
         }
     }
 }
Beispiel #6
0
 /**
  * Returns a hash code
  *
  * @param  var $val
  * @return string
  */
 public static function hashOf($val)
 {
     if (null === $val) {
         return 'N;';
     } else {
         if ($val instanceof Generic || $val instanceof Value) {
             return $val->hashCode();
         } else {
             if ($val instanceof \Closure) {
                 return spl_object_hash($val);
             } else {
                 if (is_array($val)) {
                     $s = '';
                     foreach ($val as $key => $value) {
                         $s .= '|' . $key . ':' . self::hashOf($value);
                     }
                     return $s;
                 } else {
                     return serialize($val);
                 }
             }
         }
     }
 }
Beispiel #7
0
 /**
  * Returns whether a given error is equal to this results instance
  *
  * @param  var $cmp
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && $this->message() === $cmp->message();
 }
Beispiel #8
0
 /**
  * Determines whether the specified object is an instance of this
  * type. 
  *
  * @param   var $obj
  * @return  bool
  */
 public function isInstance($obj)
 {
     return $obj instanceof Generic && $this->assignableFromClass($obj->getClass());
 }
Beispiel #9
0
 /**
  * Returns whether this path instance is equal to a given object.
  *
  * @param  var $cmp
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && $this->normalize()->path === $cmp->normalize()->path;
 }
Beispiel #10
0
 /**
  * Compare this date to another date
  *
  * @param   var $cmp
  * @return  int equal: 0, date before $this: less than 0, date after $this: greater than zero
  */
 public function compareTo($cmp)
 {
     return $cmp instanceof self ? $cmp->getTime() - $this->getTime() : -1;
 }
Beispiel #11
0
 /**
  * Invocation overloading
  *
  * @param  var $context
  * @return var
  */
 public function __invoke($context)
 {
     return $context->lookup($this->name);
 }
Beispiel #12
0
 /**
  * Returns whether a given value is equal to this results instance
  *
  * @param  var $cmp
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && $this->__toString() === $cmp->__toString();
 }
 /**
  * Sets a logger to use. Accepts either a closure, a util.log.LogCategory
  * instance or NULL (to unset).
  *
  * @param  var $logger
  * @return self this
  * @throws lang.IllegalArgumentException on argument mismatch
  */
 public function withLogger($logger)
 {
     if ($logger instanceof \Closure) {
         $this->setBuiltin('log', function ($items, $context, $options) use($logger) {
             $logger($options);
             return '';
         });
     } else {
         if ($logger instanceof LogCategory) {
             $this->setBuiltin('log', function ($items, $context, $options) use($logger) {
                 if (sizeof($options) > 1) {
                     $logger->log(LogLevel::named(array_shift($options)), $options);
                 } else {
                     $logger->log(LogLevel::DEBUG, $options);
                 }
                 return '';
             });
         } else {
             if (null === $logger) {
                 $this->setBuiltin('log', null);
             } else {
                 throw new IllegalArgumentException('Expect either a closure, a util.log.LogCategory or NULL, ' . \xp::typeOf($logger) . ' given');
             }
         }
     }
     return $this;
 }
 /**
  * User profile error message
  * @param  var $errors error message depending on what's wrong
  * @param  var $update whether or not to update
  * @param  object $user   user being updated
  * @return error message
  *
  * @since 2.3.0
  */
 public function user_profile_error_message($errors, $update, $user)
 {
     $new_value = (int) $_POST['displayfeaturedimagegenesis'];
     $source = wp_get_attachment_image_src($new_value, 'full');
     $valid = $this->is_valid_img_ext($source[0]);
     $reset = sprintf(__(' The %s Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis'), $user->display_name);
     $error = __('Sorry, your image is too small.', 'display-featured-image-genesis');
     if (!$valid) {
         $error = __('Sorry, that is an invalid file type.', 'display-featured-image-genesis');
     }
     $errors->add('profile_error', $error . $reset);
 }