注册内容解析器

@param  array    $mediaTypes
@param  callable $parser
12671
protected function registerMediaTypeParser(array $mediaTypes, callable $parser)
    {
        if ($parser instanceof \Closure) {
            $parser = $parser->bindTo($this);
        }

        foreach ($mediaTypes as $mediaType) {
            $this->bodyParsers[$mediaType] = $parser;
        }
    }
410684
public void setParser(RtfParser parser) {
		if(this.rtfParser != null && this.rtfParser.equals(parser)) return;
		this.rtfParser = parser;
	}
1077319
public static function parse(Parser $parser, TokensList $list, array $options = [])
    {
        $ret = new self();

        /**
         * Last parsed column.
         *
         * @var array
         */
        $lastColumn = [];

        /**
         * The state of the parser.
         *
         * Below are the states of the parser.
         *
         *      0 ----------------------[ type ]-----------------------> 1
         *
         *      1 ----------------------[ name ]-----------------------> 1
         *      1 ---------------------[ columns ]---------------------> 2
         *
         *      2 ---------------------[ options ]---------------------> 3
         *
         * @var int
         */
        $state = 0;

        for (; $list->idx < $list->count; ++$list->idx) {
            /**
             * Token parsed at this moment.
             *
             * @var Token
             */
            $token = $list->tokens[$list->idx];

            // End of statement.
            if ($token->type === Token::TYPE_DELIMITER) {
                break;
            }

            // Skipping whitespaces and comments.
            if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) {
                continue;
            }

            if ($state === 0) {
                $ret->type = $token->value;
                $state = 1;
            } elseif ($state === 1) {
                if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) {
                    $state = 2;
                } else {
                    $ret->name = $token->value;
                }
            } elseif ($state === 2) {
                if ($token->type === Token::TYPE_OPERATOR) {
                    if ($token->value === '(') {
                        $state = 3;
                    } elseif (($token->value === ',') || ($token->value === ')')) {
                        $state = ($token->value === ',') ? 2 : 4;
                        if (! empty($lastColumn)) {
                            $ret->columns[] = $lastColumn;
                            $lastColumn = [];
                        }
                    }
                } else {
                    $lastColumn['name'] = $token->value;
                }
            } elseif ($state === 3) {
                if (($token->type === Token::TYPE_OPERATOR) && ($token->value === ')')) {
                    $state = 2;
                } else {
                    $lastColumn['length'] = $token->value;
                }
            } elseif ($state === 4) {
                $ret->options = OptionsArray::parse($parser, $list, static::$KEY_OPTIONS);
                ++$list->idx;
                break;
            }
        }

        --$list->idx;

        return $ret;
    }
266467
public static void get(HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) {
        addResource(Methods.GET, HandlerUtil.BASE_PATH, endpoint, mediaTypes);
    }
1264927
protected function setRecordViewButtons(\AbstractMetaDataParser $parser, $type, array $buttons)
    {
        foreach ($parser->_viewdefs['buttons'] as $key => $buttonsType) {
            if ($buttonsType['type'] === $type) {
                $keyDp = $key;
                break;
            }
        }

        $parser->_viewdefs['buttons'][$keyDp]['buttons'] = $buttons;
        $parser->handleSave(false);
    }
264559
private function setClientMediaType($clientMediaType)
    {
        $this->clientMediaType = (empty($clientMediaType) ? null : (string) $clientMediaType);

        return $this;
    }
279020
public function setDefaultMediaType($defaultMediaType)
    {
        if (!\in_array($defaultMediaType, $this->defaultMediaTypes, true)) {
            return;
        }
        $this->defaultMediaTypes[] = $defaultMediaType;
    }
965201
public function parse(Parser $parser)
    {
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->first = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_AS);
        $parser->match(Lexer::T_IDENTIFIER);
        $this->second = $parser->getLexer()->token['value'];
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }
862355
public static function create($url, string $mediaType = self::TYPE_IMAGE): self
    {
        return new self($url, $mediaType);
    }
1206799
public function setSupportedMediaTypes(array $mediaTypes)
    {
        foreach ($mediaTypes as $mediaType => $converterClass) {
            if (!is_string($mediaType)) {
                throw new Exception('Media type must be a string.');
            }

            if (!is_string($converterClass)) {
                throw new Exception('Converter class name must be a string.');
            }
        }

        $this->supportedMediaTypes = $mediaTypes;
    }
713550
private function createTypeFormView(MediaManager $mediaManager, $type)
    {
        $handler = $mediaManager->getHandlerForType($type);
        $media = new Media();
        $helper = $handler->getFormHelper($media);

        return $this->createForm($handler->getFormType(), $helper)->createView();
    }
716049
public function removeParser($parser)
    {
        if ($parser instanceof ValueParserInterface) {
            $parser = $parser->getName();
        }

        if (is_string($parser) && $this->hasParser($parser)) {
            unset($this->parsers[$parser]);
        }

        return $this;
    }
480774
public function getDocJSON(Parser $parser) {
    $doc = parent::getDocJSON($parser);

    $rClass = new \ReflectionClass(get_called_class());

    foreach($doc['methods'] as $k => $methodDoc) {
      if($methodDoc['InternalMethodName'] == 'get') {
        $doc['methods'][$k]['MethodName'] = 'Get Full Collection';
      }
      elseif($methodDoc['InternalMethodName'] == 'post') {
        $doc['methods'][$k]['MethodName'] = 'Add to Collection';
      }
      elseif($methodDoc['InternalMethodName'] == 'put') {
        $doc['methods'][$k]['MethodName'] = 'Replace Full Collection';
      }
      elseif($methodDoc['InternalMethodName'] == 'delete') {
        $doc['methods'][$k]['MethodName'] = 'Delete Full Collection';
      }
    }

    $methodDoc = $this->getRestMethodDocJSON($parser, 'Get Resource',
      'GET', "/{$this->base}/:id", $rClass, '_restGetResource');
    if (!empty($methodDoc)) {
      $doc['methods'][] = $methodDoc;
    }
    $methodDoc = $this->getRestMethodDocJSON($parser, 'Update Resource',
      'PUT', "/{$this->base}/:id", $rClass, '_restPutResource');
    if (!empty($methodDoc)) {
      $doc['methods'][] = $methodDoc;
    }
    $methodDoc = $this->getRestMethodDocJSON($parser, 'Delete Resource',
      'DELETE', "/{$this->base}/:id", $rClass, '_restDeleteResource');
    if (!empty($methodDoc)) {
      $doc['methods'][] = $methodDoc;
    }

    // Add documentation for custom rest actions
    $rMethods = $rClass->getMethods(\ReflectionMethod::IS_PUBLIC);
    foreach ($rMethods as $rMethod) {
      $docComment = $rMethod->getDocComment();
      // If there is a '@endpoint ignore' property, the function is not served as an endpoint
      if (in_array('ignore', ReflectionHelper::getDocDirective($docComment, 'endpoint'))) {
        continue;
      }

      $methodDoc = array();

      $methodDoc['InternalMethodName'] = $rMethod->name;
      if (strpos($rMethod->name, 'restGet', 0) === 0) {
        $methodDoc['MethodName'] = substr($rMethod->name, 7);
        $methodDoc['HTTPMethod'] = 'GET';
      }
      elseif (strpos($rMethod->name, 'restPut', 0) === 0) {
        $methodDoc['MethodName'] = substr($rMethod->name, 7);
        $methodDoc['HTTPMethod'] = 'PUT';
      }
      elseif (strpos($rMethod->name, 'restPost', 0) === 0) {
        $methodDoc['MethodName'] = substr($rMethod->name, 8);
        $methodDoc['HTTPMethod'] = 'POST';
      }
      elseif (strpos($rMethod->name, 'restDelete', 0) === 0) {
        $methodDoc['MethodName'] = substr($rMethod->name, 10);
        $methodDoc['HTTPMethod'] = 'DELETE';
      }
      else {
        continue;
      }
      $action = strtolower($methodDoc['MethodName']);
      $methodDoc['URI'] = "/{$this->base}/:id/{$action}";
      $methodDoc['Synopsis'] = $parser->parse(ReflectionHelper::getDocText($docComment));
      $methodDoc['parameters'][] = array(
        'Name' => 'id',
        'Required' => 'Y',
        'Type' => 'string',
        'Location' => 'url',
        'Description' => 'The id of the resource'
      );
      $methodDoc['parameters'] = array_merge($methodDoc['parameters'], $this->getDocParameters($rMethod));

      // Allow controller middlewares to modify the documentation for this method
      if (!empty($this->middlewares)) {
        $middleware = reset($this->middlewares);
        $middleware->documentMethod($rClass, $rMethod, $methodDoc);
      }

      if (!empty($methodDoc)) {
        $doc['methods'][] = $methodDoc;
      }
    }

    return $doc;
  }
967049
public function setParser($parser) {
        switch ($parser) {
            case self::PARSER_XML:
            case self::PARSER_XMLDTD:
            case self::PARSER_HTML:
            case self::PARSER_HTML5:
            case self::PARSER_HTML4:
            case self::PARSER_HTML4TR:
                $this->parser = $parser;
                return $this;
            default:
                throw new UnknownParserException('Unknown parser "' . $parser . '"');
        }
    }
191582
public static void post(String url, HttpConsumer<HttpExchange> endpoint, MediaTypes... mediaTypes) {
        addResource(Methods.POST, url, endpoint, mediaTypes);
    }
792412
private function getMimeTypeForParser($parser) {
        switch ($parser) {
            case self::PARSER_XML:
                return 'application/xml';
            case self::PARSER_XMLDTD:
                return 'application/xml-dtd';
            case self::PARSER_HTML:
            case self::PARSER_HTML5:
            case self::PARSER_HTML4:
            case self::PARSER_HTML4TR:
                return 'text/html';
        }
    }
1327396
public ApiListingBuilder consumes(Set<String> mediaTypes) {
    if (mediaTypes != null) {
      this.consumes = new HashSet<>(mediaTypes);
    }
    return this;
  }