/**
  * Creates a PHP parameter from reflection
  * 
  * @param \ReflectionParameter $ref
  * @return PhpParameter
  */
 public static function fromReflection(\ReflectionParameter $ref)
 {
     $parameter = new static();
     $parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference());
     if ($ref->isDefaultValueAvailable()) {
         $parameter->setDefaultValue($ref->getDefaultValue());
     }
     // 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;
 }
 public static function fromReflection(\ReflectionParameter $ref)
 {
     $parameter = new static();
     $parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference());
     if ($ref->isDefaultValueAvailable()) {
         $parameter->setDefaultValue($ref->getDefaultValue());
     }
     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 #3
0
 /**
  * Magic metod for constructor.
  *
  * @param string $type
  * @param string $element
  *
  * @return self
  */
 public static function make($type, $element)
 {
     $chart = new static();
     $chart->setType($type);
     $chart->setElement($element);
     return $chart;
 }
Example #4
0
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'content-type') {
         throw new Exception\InvalidArgumentException('Invalid header line for Content-Type string');
     }
     $value = str_replace(Headers::FOLDING, " ", $value);
     $values = preg_split('#\\s*;\\s*#', $value);
     $type = array_shift($values);
     //Remove empty values
     $values = array_filter($values);
     $header = new static();
     $header->setType($type);
     $values = array_filter($values);
     if (count($values)) {
         foreach ($values as $keyValuePair) {
             list($key, $value) = explode('=', $keyValuePair, 2);
             $value = trim($value, "'\" \t\n\r\v");
             $header->addParameter($key, $value);
         }
     }
     return $header;
 }
Example #5
0
    /**
     * Factory: create Content-Type header object from string
     *
     * @param  string $headerLine
     * @throws Exception\InvalidArgumentException
     * @return ContentType
     */
    public static function fromString($headerLine)
    {
        $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
        list($name, $value) = explode(': ', $headerLine, 2);

        // check to ensure proper header type for this factory
        if (strtolower($name) !== 'content-type') {
            throw new Exception\InvalidArgumentException('Invalid header line for Content-Type string');
        }

        $value  = str_replace("\r\n ", " ", $value);
        $values = preg_split('#\s*;\s*#', $value);
        $type   = array_shift($values);

        $header = new static();
        $header->setType($type);

        if (count($values)) {
            foreach ($values as $keyValuePair) {
                list($key, $value) = explode('=', $keyValuePair);
                $value = trim($value, "\"\' \t\n\r\0\x0B");
                $header->addParameter($key, $value);
            }
        }
        
        return $header;
    }
Example #6
0
 public static function fromArray(string $name, array $data = [])
 {
     $instance = new static($name);
     if (isset($data['Type'])) {
         $instance->setType($data['Type']);
     }
     if (isset($data['type'])) {
         $instance->setType($data['type']);
     }
     if (isset($data['Comment'])) {
         $instance->setComment($data['Comment']);
     }
     if (isset($data['comment'])) {
         $instance->setComment($data['comment']);
     }
     if (isset($data['Null']) && $data['Null'] === 'YES') {
         $instance->setNullable(true);
     }
     if (isset($data['nullable']) && is_bool($data['nullable'])) {
         $instance->setNullable($data['nullable']);
     }
     if (isset($data['Default'])) {
         $instance->setDefault($data['Default']);
     }
     if (isset($data['default'])) {
         $instance->setDefault($data['default']);
     }
     if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) {
         $temp = array_map(function ($v) {
             return str_replace("''", "'", $v);
         }, explode("','", substr($instance->getType(), 6, -2)));
         $instance->setValues($temp);
     }
     if (isset($data['values']) && is_array($data['values'])) {
         $instance->setValues($data['values']);
     }
     if (isset($data['DATA_TYPE'])) {
         $instance->setType($data['DATA_TYPE']);
     }
     if (isset($data['NULLABLE']) && $data['NULLABLE'] !== 'N') {
         $instance->setNullable(true);
     }
     if (isset($data['DATA_DEFAULT'])) {
         $instance->setDefault($data['DATA_DEFAULT']);
     }
     return $instance;
 }
Example #7
0
 public static function createFromConfig($number, array $config)
 {
     $step = new static();
     $step->setNumber($number);
     $step->setLabel(array_key_exists('label', $config) ? $config['label'] : null);
     $step->setType(array_key_exists('type', $config) ? $config['type'] : null);
     $step->setSkip(array_key_exists('skip', $config) ? $config['skip'] : false);
     return $step;
 }
Example #8
0
 /**
  * @param string $text
  * @param string $type
  *
  * @return static
  */
 public static function make($text, $type = null)
 {
     $tag = new static();
     $tag->setContents($text);
     if ($type) {
         $tag->setType($type);
     }
     return $tag;
 }
Example #9
0
 /**
  * Construct the suggestion based on the given result xml.
  * @param SimpleXMLElement $xmlElement
  * @return \CultuurNet\Search\SuggestionItem
  */
 public static function fromXml(SimpleXMLElement $xmlElement)
 {
     $suggestionItem = new static();
     $attributes = $xmlElement->attributes();
     $suggestionItem->setCdbid((string) $attributes['cdbid']);
     $suggestionItem->setType((string) $attributes['type']);
     if (!empty($attributes['location'])) {
         $suggestionItem->setLocation((string) $attributes['location']);
         $suggestionItem->setZipcode((string) $attributes['zipcode']);
     }
     $suggestionItem->setTitle((string) $xmlElement);
     return $suggestionItem;
 }
Example #10
0
 /**
  *
  *
  *
  *
  */
 public static function where($criteria, array $projection)
 {
     $relationship = new static();
     if (!empty($relationship->getType())) {
         $criteria['$type'] = $relationship->getType();
     }
     $query = new RelQuery($criteria);
     $document = $query->execute($projection)->current();
     $relationship->setType($criteria['$type']);
     $data = $document->getProperty(Relationship::REL_PREFIX . $criteria['$type']);
     $relationship->parseData($data[0], $document);
     return $relationship;
 }
 /**
  * @override - uses `static` to instantiate the parameter
  *
  * {@inheritDoc}
  */
 public static function fromReflection(ParameterReflection $reflectionParameter)
 {
     /* @var $param self */
     $param = new static();
     $param->setName($reflectionParameter->getName());
     $param->setPosition($reflectionParameter->getPosition());
     $type = self::extractParameterType($reflectionParameter);
     if (null !== $type) {
         $param->setType($type);
     }
     self::setOptionalParameter($param, $reflectionParameter);
     $param->setPassedByReference($reflectionParameter->isPassedByReference());
     return $param;
 }
Example #12
0
 public static function make($source = null, $type = null, $media = null)
 {
     $tag = new static();
     if ($source) {
         $tag->setSource($source);
     }
     if ($type) {
         $tag->setType($type);
     }
     if ($media) {
         $tag->setMedia($source);
     }
     return $tag;
 }
Example #13
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 #14
0
 public static function create($type, $scope, $message, $scopeId = null, $link = null)
 {
     $rtn = new static();
     $rtn->setType($type);
     $rtn->setScope($scope);
     if (!empty($scopeId)) {
         $rtn->setScopeId($scopeId);
     }
     $rtn->setMessage($message);
     if (!empty($link)) {
         $rtn->setLink($link);
     }
     $rtn->setLogDate(new \DateTime());
     $rtn->setUser($_SESSION['user']);
     $rtn = Store::get('Log')->save($rtn);
     return $rtn;
 }
 /**
  * Create a security scheme from an array
  *
  * @param string $key
  * @param array $data
  * [
  *  description: ?string
  *  type:        ?string
  *  describedBy: ?string[]
  *  settings:    ?object[]
  * ]
  * @param ApiDefinition $apiDefinition
  *
  * @return SecurityScheme
  */
 public static function createFromArray($key, array $data = [], ApiDefinition $apiDefinition = null)
 {
     $securityScheme = new static($key);
     if (isset($data['description'])) {
         $securityScheme->setDescription($data['description']);
     }
     if (isset($data['type'])) {
         $securityScheme->setType($data['type']);
     }
     if (isset($data['describedBy'])) {
         $securityScheme->setDescribedBy(SecuritySchemeDescribedBy::createFromArray('describedBy', $data['describedBy']));
     }
     if (isset($data['settings'])) {
         $securityScheme->setSettings($data['settings']);
     }
     return $securityScheme;
 }
 /**
  * Creates a new PHP property from reflection
  * 
  * @param \ReflectionProperty $ref
  * @return static
  */
 public static function fromReflection(\ReflectionProperty $ref)
 {
     $property = new static($ref->name);
     $property->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE));
     $docblock = new Docblock($ref);
     $property->setDocblock($docblock);
     $property->setDescription($docblock->getShortDescription());
     $property->setLongDescription($docblock->getLongDescription());
     $vars = $docblock->getTags('var');
     if ($vars->size() > 0) {
         $var = $vars->get(0);
         $property->setType($var->getType(), $var->getDescription());
     }
     $defaultProperties = $ref->getDeclaringClass()->getDefaultProperties();
     if (isset($defaultProperties[$ref->name])) {
         $property->setDefaultValue($defaultProperties[$ref->name]);
     }
     return $property;
 }
Example #17
0
 /**
  * Creates a PHP method from reflection
  * 
  * @param \ReflectionMethod $ref
  * @return PhpMethod
  */
 public static function fromReflection(\ReflectionMethod $ref)
 {
     $method = new static($ref->name);
     $method->setFinal($ref->isFinal())->setAbstract($ref->isAbstract())->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE))->setReferenceReturned($ref->returnsReference())->setBody(ReflectionUtils::getFunctionBody($ref));
     $docblock = new Docblock($ref);
     $method->setDocblock($docblock);
     $method->setDescription($docblock->getShortDescription());
     $method->setLongDescription($docblock->getLongDescription());
     // return type and description
     $returns = $method->getDocblock()->getTags('return');
     if ($returns->size() > 0) {
         $return = $returns->get(0);
         $method->setType($return->getType(), $return->getDescription());
     }
     // params
     foreach ($ref->getParameters() as $param) {
         $method->addParameter(static::createParameter($param));
     }
     return $method;
 }
Example #18
0
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     $value = HeaderWrap::mimeDecodeValue($value);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'content-type') {
         throw new Exception\InvalidArgumentException('Invalid header line for Content-Type string');
     }
     $value = str_replace(Headers::FOLDING, ' ', $value);
     $values = preg_split('#\\s*;\\s*#', $value);
     $type = array_shift($values);
     $header = new static();
     $header->setType($type);
     // Remove empty values
     $values = array_filter($values);
     foreach ($values as $keyValuePair) {
         $parts = explode('=', $keyValuePair, 2);
         $key = $parts[0];
         $value = count($parts) > 1 ? $parts[1] : "";
         $value = trim($value, "'\" \t\n\r\v");
         $header->addParameter($key, $value);
     }
     return $header;
 }
Example #19
0
 /**
  * Return new instance with needed OtpAlgorithm type
  *
  * @param string $type Type of OtpAlgorithm (see getAvailableTypes).
  * @throws \Bitrix\Main\ArgumentOutOfRangeException
  * @return static New instance
  */
 public static function getByType($type)
 {
     if (!in_array($type, static::$availableTypes)) {
         throw new ArgumentOutOfRangeException('type', static::$availableTypes);
     }
     $algo = static::$typeMap[$type];
     $instance = new static($algo);
     $instance->setType($type);
     return $instance;
 }
 /**
  * Generate from array
  *
  * @configkey name              string                                          [required] Class Name
  * @configkey type              string
  * @configkey defaultvalue      null|bool|string|int|float|array|ValueGenerator
  * @configkey passedbyreference bool
  * @configkey position          int
  * @configkey sourcedirty       bool
  * @configkey indentation       string
  * @configkey sourcecontent     string
  *
  * @throws Exception\InvalidArgumentException
  * @param  array $array
  * @return ParameterGenerator
  */
 public static function fromArray(array $array)
 {
     if (!isset($array['name'])) {
         throw new Exception\InvalidArgumentException('Paramerer generator requires that a name is provided for this object');
     }
     $param = new static($array['name']);
     foreach ($array as $name => $value) {
         // normalize key
         switch (strtolower(str_replace(['.', '-', '_'], '', $name))) {
             case 'type':
                 $param->setType($value);
                 break;
             case 'defaultvalue':
                 $param->setDefaultValue($value);
                 break;
             case 'passedbyreference':
                 $param->setPassedByReference($value);
                 break;
             case 'position':
                 $param->setPosition($value);
                 break;
             case 'sourcedirty':
                 $param->setSourceDirty($value);
                 break;
             case 'indentation':
                 $param->setIndentation($value);
                 break;
             case 'sourcecontent':
                 $param->setSourceContent($value);
                 break;
         }
     }
     return $param;
 }
Example #21
0
 public static function createNew($params)
 {
     $star = new static($params);
     $star->setType();
     if ($star->isValid()) {
         DB::transaction(function () use($star) {
             // So the strings can be used with interpolation
             // instead of concatenation or sprintf.
             $cost = (string) static::COST;
             $increment = (string) $star->voteIncrement();
             return $star->user->update(['osu_featurevotes' => DB::raw("osu_featurevotes - ({$cost})")]) && $star->topic->update(['osu_starpriority' => DB::raw("osu_starpriority + ({$increment})")]) && $star->saveOrFail();
         });
     }
     return $star;
 }
Example #22
0
 /**
  * Decompiles an array into an ApiProblem object.
  *
  * @param array $parsed
  *   An array parsed from JSON or XML to turn into an ApiProblem object.
  * @return \Crell\ApiProblem\ApiProblem
  *   A new ApiProblem object.
  */
 protected static function decompile(array $parsed)
 {
     $problem = new static();
     if (!empty($parsed['title'])) {
         $problem->setTitle($parsed['title']);
     }
     if (!empty($parsed['type'])) {
         $problem->setType($parsed['type']);
     }
     if (!empty($parsed['status'])) {
         $problem->setStatus($parsed['status']);
     }
     if (!empty($parsed['detail'])) {
         $problem->setDetail($parsed['detail']);
     }
     if (!empty($parsed['instance'])) {
         $problem->setInstance($parsed['instance']);
     }
     // Remove the defined keys. That means whatever is left must be a custom
     // extension property.
     unset($parsed['title'], $parsed['type'], $parsed['status'], $parsed['detail'], $parsed['instance']);
     foreach ($parsed as $key => $value) {
         $problem[$key] = $value;
     }
     return $problem;
 }
Example #23
0
 /**
  * Creates decorator
  *
  * @param object $oComponent
  * @param bool   $bHookEnable
  *
  * @return Decorator
  */
 static function Create($oComponent, $bHookEnable = true)
 {
     $sClassName = get_class($oComponent);
     if (!$bHookEnable || $sClassName == 'ModulePlugin' || $sClassName == 'ModuleHook') {
         return $oComponent;
     }
     if (DEBUG) {
         $sDecoratorClassName = 'Decorator' . $sClassName;
         $sDecoratorClassCode = 'class ' . $sDecoratorClassName . ' extends Decorator { }';
         eval($sDecoratorClassCode);
         $oComponentDecorator = new $sDecoratorClassName($oComponent);
     } else {
         $oComponentDecorator = new static($oComponent);
     }
     $aClassInfo = E::GetClassInfo($oComponent, Engine::CI_ACTION | Engine::CI_MODULE);
     if ($aClassInfo[Engine::CI_ACTION]) {
         $oComponentDecorator->setType('action');
         $oComponentDecorator->setName($aClassInfo[Engine::CI_ACTION]);
         $oComponentDecorator->setHookEnable(true);
     } elseif ($aClassInfo[Engine::CI_MODULE]) {
         $oComponentDecorator->setType('module');
         $oComponentDecorator->setName($aClassInfo[Engine::CI_MODULE]);
         $oComponentDecorator->setHookEnable(true);
     }
     return $oComponentDecorator;
 }
Example #24
0
 /**
  * @param string $type
  *
  * @return static
  */
 public static function make($type = self::TYPE_TEXT)
 {
     $tag = new static();
     $tag->setType($type);
     return $tag;
 }
Example #25
0
 /**
  * Rule factory
  *
  * @param int $type Type
  * @param mixed $value Value
  * @return RuleInterface A new rule
  */
 public function make($type, $value = null)
 {
     $product = new static();
     $product->setType($type)->setValue($value);
     return $product;
 }
Example #26
0
 /**
  * @param Event $event
  * @param User $speaker
  * @param TalkType $type
  * @param string $title
  * @param string $shortDescription
  * @param string $longDescription
  * @param string $complexity
  * @param array $tags
  * @param float $cost
  * @return Talk
  */
 public static function create(Event $event, User $speaker, TalkType $type, $title, $shortDescription, $longDescription, $complexity, array $tags, $cost = null)
 {
     $talk = new static();
     $talk->setEvent($event);
     $talk->setType($type);
     $talk->setTitle($title);
     $talk->setComplexity($complexity);
     $talk->setCost($cost);
     $talk->setTags($tags);
     $talk->setShortDescription($shortDescription);
     $talk->setLongDescription($longDescription);
     $talk->setCreationTime(new DateTime());
     $talk->getSpeakers()->add($speaker);
     return $talk;
 }
Example #27
0
 public static function create($locale, $type = 'page-content', $revision = 'default', $slug = NULL)
 {
     $cs = new static($locale, $slug, $revision);
     $cs->setType($type ?: 'page-content');
     return $cs;
 }
Example #28
0
 /**
  * Inline tag constructor
  *
  * @param string $name
  * @return static
  */
 public static function inline($name)
 {
     $tag = new static($name);
     $tag->setType(static::TYPE_INLINE);
     return $tag;
 }
Example #29
0
 /**
  * Creates decorator
  *
  * @param object $oComponent
  * @param bool   $bHookEnable
  *
  * @return object
  */
 static function Create($oComponent, $bHookEnable = true)
 {
     $sClassName = get_class($oComponent);
     if (!$bHookEnable || $sClassName == 'ModulePlugin' || $sClassName == 'ModuleHook') {
         return $oComponent;
     }
     $oComponentDecorator = new static($oComponent);
     $aClassInfo = E::GetClassInfo($oComponent, Engine::CI_ACTION | Engine::CI_MODULE);
     if ($aClassInfo[Engine::CI_ACTION]) {
         $oComponentDecorator->setType('action');
         $oComponentDecorator->setName($aClassInfo[Engine::CI_ACTION]);
         $oComponentDecorator->setHookEnable(true);
     } elseif ($aClassInfo[Engine::CI_MODULE]) {
         $oComponentDecorator->setType('module');
         $oComponentDecorator->setName($aClassInfo[Engine::CI_MODULE]);
         $oComponentDecorator->setHookEnable(true);
     }
     return $oComponentDecorator;
 }
Example #30
0
 /**
  * Create a Query Parameter from an Array
  *
  * @param $key
  * @param $data
  * [
  *  displayName:        ?string
  *  description:        ?string
  *  type:               ?["string","number","integer","date","boolean","file"]
  *  enum:               ?array
  *  pattern:            ?string
  *  validationPattern:  ?string
  *  minLength:          ?integer
  *  maxLength:          ?integer
  *  minimum:            ?integer
  *  maximum:            ?integer
  *  example:            ?string
  *  examples:           ?array
  *  repeat:             ?boolean
  *  required:           ?boolean
  *  default:            ?string
  * ]
  *
  * @throws \Exception
  *
  * @return NamedParameter
  */
 public static function createFromArray($key, array $data = [])
 {
     $namedParameter = new static($key);
     if (isset($data['displayName'])) {
         $namedParameter->setDisplayName($data['displayName']);
     }
     if (isset($data['description'])) {
         $namedParameter->setDescription($data['description']);
     }
     if (isset($data['type'])) {
         $namedParameter->setType($data['type']);
     }
     if (isset($data['enum'])) {
         $namedParameter->setEnum($data['enum']);
     }
     if (isset($data['pattern'])) {
         $namedParameter->setValidationPattern($data['pattern']);
     }
     // RAML 1.0
     if (isset($data['validationPattern'])) {
         $namedParameter->setValidationPattern($data['validationPattern']);
     }
     if (isset($data['minLength'])) {
         $namedParameter->setMinLength($data['minLength']);
     }
     if (isset($data['maxLength'])) {
         $namedParameter->setMaxLength($data['maxLength']);
     }
     if (isset($data['minimum'])) {
         $namedParameter->setMinimum($data['minimum']);
     }
     if (isset($data['maximum'])) {
         $namedParameter->setMaximum($data['maximum']);
     }
     if (isset($data['example'])) {
         $namedParameter->addExample($data['example']);
     }
     if (isset($data['examples'])) {
         foreach ($data['examples'] as $example) {
             $namedParameter->addExample($example);
         }
     }
     if (isset($data['repeat'])) {
         $namedParameter->setRepeat($data['repeat']);
     }
     if (isset($data['required'])) {
         $namedParameter->setRequired($data['required']);
     }
     if (isset($data['default'])) {
         if ($namedParameter->getType() === self::TYPE_DATE) {
             $namedParameter->setDefault(\DateTime::createFromFormat('D, d M Y H:i:s T', $data['default']));
         } else {
             $namedParameter->setDefault($data['default']);
         }
     }
     return $namedParameter;
 }