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; }
/** * 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; }
/** * Create a new WebFormObject from an array * * @param string $key The valid media type to use as the key * @param array $data The array of data to create \NamedParameter objects from * * @return \Raml\WebFormBody */ public static function createFromArray($key, array $data = []) { $webFormBody = new static($key); if ($data['formParameters']) { foreach ($data['formParameters'] as $namedParam => $namedParamData) { $webFormBody->addParameter(NamedParameter::createFromArray($namedParam, $namedParamData)); } } return $webFormBody; }
/** * @param $definition * @return static */ public static function createFromApiJsonDocs($definition) { if (arr::get('group', $definition) == 'deprecated') { return null; } $operation = new static(); $operation->version = arr::get('group', $definition) == 'streams' ? 'stream' : arr::get('api_version', $definition, '1'); $operation->httpMethod = arr::get('http_method', $definition); $operation->summary = arr::get('desc', $definition); $operation->notes = arr::get('param_notes', $definition); $operation->parsePath(arr::get('path', $definition)); foreach (arr::get('params', $definition, array()) as $param => $desc) { // Always false due to complex rules on meetup's side (one of x is required) $operation->addParameter(str_replace('*', '', $param), 'query', false, $desc); } foreach (arr::get('orders', $definition, array()) as $param => $desc) { $operation->addParameter($param, 'query', false, $desc); } $operation->addStandardParameters(arr::get('http_method', $definition)); $operation->name = OperationNameConverter::parseOperationName($operation); return $operation; }
public static function fromReflection(\ReflectionMethod $ref) { $method = new static(); $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())->setName($ref->name); if ($docComment = $ref->getDocComment()) { $method->setDocblock(ReflectionUtils::getUnindentedDocComment($docComment)); } foreach ($ref->getParameters() as $param) { $method->addParameter(static::createParameter($param)); } // FIXME: Extract body? return $method; }
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()); foreach ($ref->getParameters() as $param) { $method->addParameter(static::createParameter($param)); } return $method; }
public static function fromReflection(\ReflectionFunction $ref) { $function = new static(); if (false === ($pos = strrpos($ref->name, '\\'))) { $function->setName(substr($ref->name, $pos + 1)); $function->setNamespace(substr($ref->name, $pos)); } else { $function->setName($ref->name); } $function->referenceReturned = $ref->returnsReference(); $function->docblock = ReflectionUtils::getUnindentedDocComment($ref->getDocComment()); foreach ($ref->getParameters() as $refParam) { assert($refParam instanceof \ReflectionParameter); $param = PhpParameter::fromReflection($refParam); $function->addParameter($param); } return $function; }
public static function fromString($headerLine) { list($name, $value) = GenericHeader::splitHeaderLine($headerLine); $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header disposition for this factory if (strtolower($name) !== 'content-disposition') { throw new InvalidArgumentException('Invalid header line for Content-Disposition string'); } $value = str_replace(Headers::FOLDING, ' ', $value); $values = preg_split('#\\s*;\\s*#', $value); $disposition = array_shift($values); $header = new static(); $header->setDisposition($disposition); // Remove empty values $values = array_filter($values); foreach ($values as $keyValuePair) { list($key, $value) = explode('=', $keyValuePair, 2); $value = trim($value, "'\" \t\n\r\v"); $header->addParameter($key, $value); } return $header; }
/** * * * @param ReflectionMethod $reflection * @return Method */ public static function fromReflection(ReflectionMethod $reflection) { // gestion du type // $type = implode('|', $reflection->getDocBlockTypeStrings()); // // construction $method = new static($reflection->getName(), [], $reflection->getBodyCode()); // docblock $docblock = new \phpDocumentor\Reflection\DocBlock($reflection->getDocComment()); $method->setSummary($docblock->getShortDescription()); $method->setDescription($docblock->getLongDescription()); // gestion des modifiers $reflection->isPrivate() ? $method->enablePrivate() : $method->disablePrivate(); $reflection->isProtected() ? $method->enableProtected() : $method->disabledProtected(); $reflection->isPublic() ? $method->enablePublic() : $method->disablePublic(); $reflection->isStatic() ? $method->enableStatic() : $method->disableStatic(); $reflection->isFinal() ? $method->enableFinal() : $method->disableFinal(); foreach ($reflection->getParameters() as $parameter) { $method->addParameter(Parameter::fromReflection($parameter)); } return $method; }