/**
  * @param $key
  * @param $value
  *
  * @return static
  */
 public static function build($key, $value)
 {
     $EnvironmentVariable = new static();
     $EnvironmentVariable->setKey($key);
     $EnvironmentVariable->setValue($value);
     return $EnvironmentVariable;
 }
 public static function create($field, $value = null)
 {
     $expression = new static();
     $expression->setField($field);
     $expression->setValue($value);
     return $expression;
 }
Example #3
0
 /**
  * Factory for creating properties
  *
  * @param  array $spec
  * @return self
  * @throws Exception\InvalidArgumentException if missing a "key" or invalid route specifications
  */
 public static function factory(array $spec)
 {
     if (!isset($spec['key'])) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the specification array contain a "key" element; none found', __METHOD__));
     }
     $property = new static($spec['key']);
     if (isset($spec['value'])) {
         $property->setValue($spec['value']);
         return $property;
     }
     if (isset($spec['url'])) {
         $property->setUrl($spec['url']);
         return $property;
     }
     if (isset($spec['route'])) {
         $routeInfo = $spec['route'];
         if (is_string($routeInfo)) {
             $property->setRoute($routeInfo);
             return $property;
         }
         if (!is_array($routeInfo)) {
             throw new Exception\InvalidArgumentException(sprintf('%s requires that the specification array\'s "route" element be a string or array; received "%s"', __METHOD__, is_object($routeInfo) ? get_class($routeInfo) : gettype($routeInfo)));
         }
         if (!isset($routeInfo['name'])) {
             throw new Exception\InvalidArgumentException(sprintf('%s requires that the specification array\'s "route" array contain a "name" element; none found', __METHOD__));
         }
         $name = $routeInfo['name'];
         $params = isset($routeInfo['params']) && is_array($routeInfo['params']) ? $routeInfo['params'] : [];
         $options = isset($routeInfo['options']) && is_array($routeInfo['options']) ? $routeInfo['options'] : [];
         $property->setRoute($name, $params, $options);
         return $property;
     }
     return $property;
 }
 /**
  * @param FieldExpression $field
  * @param IExpression     $value
  *
  * @return static
  */
 public static function create(FieldExpression $field, IExpression $value)
 {
     $expression = new static();
     $expression->addField($field);
     $expression->setValue($value);
     return $expression;
 }
Example #5
0
 /**
  * Creates an instance wrapping the given entity.
  *
  * @param \Drupal\Core\Entity\EntityInterface|null $entity
  *   The entity object to wrap.
  *
  * @return static
  */
 public static function createFromEntity(EntityInterface $entity)
 {
     $definition = EntityDataDefinition::create()->setEntityTypeId($entity->getEntityTypeId())->setBundles([$entity->bundle()]);
     $instance = new static($definition);
     $instance->setValue($entity);
     return $instance;
 }
Example #6
0
 /**
  * @param string $property
  * @param string $value
  *
  * @return static
  */
 public static function create($property, $value)
 {
     $obj = new static();
     $obj->setProperty($property);
     $obj->setValue($value);
     return $obj;
 }
Example #7
0
 /**
  * @param float $value
  * @param string $currency
  * @return Price
  */
 public static function create($value, $currency)
 {
     /* @var $price self */
     $price = new static();
     $price->setValue($value)->setCurrency($currency);
     return $price;
 }
 /**
  * Creates a PHP parameter from reflection
  *
  * @deprecated will be removed in version 0.5
  * @param \ReflectionParameter $ref
  * @return PhpParameter
  */
 public static function fromReflection(\ReflectionParameter $ref)
 {
     $parameter = new static();
     $parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference());
     if ($ref->isDefaultValueAvailable()) {
         $value = $ref->getDefaultValue();
         if (is_string($value) || is_int($value) || is_float($value) || is_bool($value) || is_null($value) || $value instanceof PhpConstant) {
             $parameter->setValue($value);
         } else {
             $parameter->setExpression($value);
         }
     }
     // find type and description in docblock
     $docblock = new Docblock($ref->getDeclaringFunction());
     $params = $docblock->getTags('param');
     $tag = $params->find($ref->name, function (ParamTag $t, $name) {
         return $t->getVariable() == '$' . $name;
     });
     if ($tag !== null) {
         $parameter->setType($tag->getType(), $tag->getDescription());
     }
     // set type if not found in comment
     if ($parameter->getType() === null) {
         if ($ref->isArray()) {
             $parameter->setType('array');
         } elseif ($class = $ref->getClass()) {
             $parameter->setType($class->getName());
         } elseif (method_exists($ref, 'isCallable') && $ref->isCallable()) {
             $parameter->setType('callable');
         }
     }
     return $parameter;
 }
Example #9
0
 /**
  * @param string $value
  * @param string $text
  *
  * @return void|static
  */
 public static function make($value, $text = null)
 {
     $tag = new static();
     $tag->setValue($value);
     if ($text) {
         $tag->setContents($text);
     }
     return $tag;
 }
Example #10
0
 /**
  * Create process argument object from string
  *
  * @param string $argument
  *
  * @return $this
  */
 public static function fromString($argument)
 {
     $argument = explode('=', $argument, 2);
     $instance = new static(array_shift($argument));
     if (count($argument) > 0) {
         $instance->setValue(array_shift($argument));
     }
     return $instance;
 }
Example #11
0
 /**
  * @param $headerLine
  * @return Connection
  * @throws Exception\InvalidArgumentException
  */
 public static function fromString($headerLine)
 {
     $header = new static();
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'connection') {
         throw new Exception\InvalidArgumentException('Invalid header line for Connection string: "' . $name . '"');
     }
     $header->setValue(trim($value));
     return $header;
 }
Example #12
0
 /**
  * @static
  * @param $field
  * @param $value
  * @param EventDispatcherInterface $dispatcher
  * @return AbstractCondition
  */
 public static function create($field, $value, EventDispatcherInterface $dispatcher = null)
 {
     $instance = new static();
     $instance->setField($field);
     $instance->setValue($value);
     $instance->setDispatcher($dispatcher);
     if ($dispatcher) {
         $dispatcher->dispatch(ConditionEvent::EVENT_NAME, new ConditionEvent($instance));
     }
     return $instance->build();
 }
 /**
  * @param string $data
  *
  * @return null|CacheItem
  */
 public static function decode($data)
 {
     if (null === $data) {
         return null;
     }
     $data = unserialize($data);
     $obj = new static();
     $obj->setValue($data[self::IDX_RAW_VALUE]);
     $obj->setExpires($data[self::IDX_EXPIRES]);
     $obj->setTags($data[self::IDX_TAGS]);
     return $obj;
 }
Example #14
0
 /**
  * Creates object instance.
  *
  * @param int|null $type
  * @param string|null $text
  * @param int|null $length
  * @param string|null $value
  * @return static
  */
 public static function factory($type = null, $text = null, $length = null, $value = null)
 {
     $token = new static();
     if (null !== $type) {
         $token->setType($type);
     }
     if (null !== $text) {
         $token->setText($text);
     }
     if (null !== $length) {
         $token->setLength($length);
     }
     if (null !== $value) {
         $token->setValue($value);
     }
     return $token;
 }
Example #15
0
 public static function getField($value)
 {
     $field = new static();
     $field->setValue($value);
     return $field;
 }
Example #16
0
 public static function create($value)
 {
     $expression = new static();
     $expression->setValue($value);
     return $expression;
 }
Example #17
0
 /**
  * Create notification type from URN
  *
  * @param Urn $urn
  *
  * @throws InvalidArgumentException
  * @return $this
  */
 public static function fromUrn(Urn $urn)
 {
     $notificationType = new static();
     $notificationType->setToken(self::URN_TOKEN);
     $notificationType->setValue($urn);
     return $notificationType;
 }
Example #18
0
 /**
  * Create a new Enum instance by constant.
  * ie Enum::CONSTANT() will return a valid Enum instance with the value of
  * the constant.
  * @param string $name Enum constant
  * @param mixed $arguments unused
  * @return \Enum instance
  * @throws InvalidArgumentException
  * @static
  */
 public static function __callStatic($name, $arguments)
 {
     if (!defined('static::' . $name)) {
         throw new InvalidArgumentException(__CLASS__ . '::' . $name . ' is not a valid member of this enum');
     }
     $obj = new static();
     $obj->setValue(constant('static::' . $name));
     return $obj;
 }
 /**
  * Static helper to quickly create a new document
  *
  * @param integer $parentId
  * @param array $data
  * @return Document
  */
 public static function create($parentId, $data = array(), $save = true)
 {
     $document = new static();
     $document->setParentId($parentId);
     foreach ($data as $key => $value) {
         $document->setValue($key, $value);
     }
     if ($save) {
         $document->save();
     }
     return $document;
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public static function create($namespace, $name, $value = null)
 {
     $parameter = new static();
     $parameter->setNamespace($namespace);
     $parameter->setName($name);
     $parameter->setValue($value);
     return $parameter;
 }
Example #21
0
 /**
  * Returns a new VCardLine initialized from the given line text, parsing
  * it according to the specified VCard version.
  * @param string $rawLine The raw VCard line (line break removed).
  * @param string $version The target VCard version.
  * @return self
  * @throws \DomainException If the line is malformed.
  */
 public static function fromLineText($rawLine, $version)
 {
     // Lines with only whitespace are skipped
     if (empty(trim($rawLine))) {
         return null;
     }
     $parsed = [];
     // https://regex101.com/r/uY5tY2/5
     $re = "/\n#Parse a VCard 4.0 (RFC6350) property line into\n#group, name, params, value components\n#VCard 2.1 allowed NSWSP ([:blank]) in some places\n#Match the property name which starts with an optional\n#group name followed by a dot\n(?:\n  (?>(?P<group>[[:alnum:]-]+))\n  \\.\n)?\n(?P<name>[[:alnum:]-]+)\n[[:blank:]]*\n#The optional params section: each repeating group\n#starts with a semicolon and parameter name.\n#Value starts with '=' and may be quoted.\n#Unquoted must be SAFE-CHAR, otherwise QSAFE-CHAR\n#Vcard 2.1 may omit parameter value\n(?P<params>\n  (?:; [[:blank:]]*[[:alnum:]-]+[[:blank:]]*\n    (?:= [[:blank:]]*\n      (?>\n        (?:\\\"[[:blank:]\\!\\x23-\\x7E[:^ascii:]]*\\\")\n        | (?:[[:blank:]\\!\\x23-\\x39\\x3c-\\x7e[:^ascii:]]*)\n      )\n    )?\n  )*\n)\n#Unescaped colon starts value section\n[[:blank:]]*\n(?<![^\\\\]\\\\):\n[[:blank:]]*\n#Value itself contains VALUE-CHAR and anything\n#not permitted expected to be removed before regex\n#is run.\n(?P<value>.+)\n/x";
     $matches = \preg_match($re, $rawLine, $parsed);
     if (1 !== $matches) {
         throw new Exceptions\MalformedPropertyException('Malformed property entry: ' . $rawLine);
     }
     $vcardLine = new static($version);
     $vcardLine->setValue($parsed['value'])->setName(\trim(\strtolower($parsed['name'])))->setGroup(\trim(\strtolower($parsed['group'])));
     if (!empty($parsed['params'])) {
         // NOTE: params string always starts with a semicolon we don't need
         $parameters = \preg_split(self::SEMICOLON_SPLIT, \substr($parsed['params'], 1));
         $vcardLine->parseParameters($parameters);
     }
     $vcardLine->handleEncoding();
     $vcardLine->handleCharset();
     return $vcardLine;
 }
 /**
  * Factory create header.
  *
  * @param string $fieldValue
  *
  * @return $this
  */
 private static function create($fieldValue)
 {
     $header = new static();
     foreach (explode(';', $fieldValue) as $index => $item) {
         $parts = explode('=', $item, 2);
         if (0 === $index) {
             $header->setName($parts[0]);
             $header->setValue($parts[1]);
             continue;
         }
         $header->setDirective($parts[0], isset($parts[1]) ? $parts[1] : null);
     }
     return $header;
 }