当前位置: 首页>>代码示例>>PHP>>正文


PHP Route::setMethods方法代码示例

本文整理汇总了PHP中Symfony\Component\Routing\Route::setMethods方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::setMethods方法的具体用法?PHP Route::setMethods怎么用?PHP Route::setMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Routing\Route的用法示例。


在下文中一共展示了Route::setMethods方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processOutbound

 /**
  * {@inheritdoc}
  */
 public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     if ($route_name === '<current>') {
         if ($current_route = $this->routeMatch->getRouteObject()) {
             $requirements = $current_route->getRequirements();
             // Setting _method and _schema is deprecated since 2.7. Using
             // setMethods() and setSchemes() are now the recommended ways.
             unset($requirements['_method']);
             unset($requirements['_schema']);
             $route->setRequirements($requirements);
             $route->setPath($current_route->getPath());
             $route->setSchemes($current_route->getSchemes());
             $route->setMethods($current_route->getMethods());
             $route->setOptions($current_route->getOptions());
             $route->setDefaults($current_route->getDefaults());
             $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
             if ($bubbleable_metadata) {
                 $bubbleable_metadata->addCacheContexts(['route']);
             }
         } else {
             // If we have no current route match available, point to the frontpage.
             $route->setPath('/');
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:RouteProcessorCurrent.php

示例2: load

 /**
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  *
  * @param mixed $resource
  * @param null  $type
  *
  * @return RouteCollection
  */
 public function load($resource, $type = null) : RouteCollection
 {
     $resource = (string) $resource;
     if (in_array($resource, $this->descriptions)) {
         throw new \RuntimeException("Resource '{$resource}' was already loaded");
     }
     $description = $this->repository->get($resource);
     $routes = new RouteCollection();
     $router = $description->getExtension('router') ?: 'swagger.controller';
     $routerController = $description->getExtension('router-controller');
     foreach ($description->getPaths() as $pathItem) {
         $relativePath = ltrim($pathItem->getPath(), '/');
         $resourceName = strpos($relativePath, '/') ? substr($relativePath, 0, strpos($relativePath, '/')) : $relativePath;
         $routerController = $pathItem->getExtension('router-controller') ?: $routerController;
         foreach ($pathItem->getOperations() as $operation) {
             $controllerKey = $this->resolveControllerKey($operation, $resourceName, $router, $routerController);
             $defaults = ['_controller' => $controllerKey, RequestMeta::ATTRIBUTE_URI => $resource, RequestMeta::ATTRIBUTE_PATH => $pathItem->getPath()];
             $route = new Route($pathItem->getPath(), $defaults, $this->resolveRequirements($operation));
             $route->setMethods($operation->getMethod());
             $routes->add($this->createRouteId($resource, $pathItem->getPath(), $controllerKey), $route);
         }
     }
     $this->descriptions[] = $resource;
     return $routes;
 }
开发者ID:kleijnweb,项目名称:swagger-bundle,代码行数:33,代码来源:OpenApiRouteLoader.php

示例3: processMethod

 /**
  * @param Method $method
  * @param string $endpoint
  *
  * @return RpcApiDoc
  */
 protected function processMethod(Method $method, $endpoint)
 {
     /** @var string[] $views */
     $views = $method->getContext();
     if ($method->includeDefaultContext()) {
         $views[] = 'Default';
     }
     $views[] = 'default';
     $request = new Request($method, [], new ParameterBag(['_controller' => $method->getController()]));
     /** @var array $controller */
     $controller = $this->resolver->getController($request);
     $refl = new \ReflectionMethod($controller[0], $controller[1]);
     /** @var RpcApiDoc $methodDoc */
     $methodDoc = $this->reader->getMethodAnnotation($refl, RpcApiDoc::class);
     if (null === $methodDoc) {
         $methodDoc = new RpcApiDoc(['resource' => $endpoint]);
     }
     $methodDoc = clone $methodDoc;
     $methodDoc->setEndpoint($endpoint);
     $methodDoc->setRpcMethod($method);
     if (null === $methodDoc->getSection()) {
         $methodDoc->setSection($endpoint);
     }
     foreach ($views as $view) {
         $methodDoc->addView($view);
     }
     $route = new Route($endpoint);
     $route->setMethods([$endpoint]);
     $route->setDefault('_controller', get_class($controller[0]) . '::' . $controller[1]);
     $methodDoc->setRoute($route);
     return $methodDoc;
 }
开发者ID:bankiru,项目名称:rpc-server-bundle,代码行数:38,代码来源:AbstractRpcMethodProvider.php

示例4: format

 /**
  * Given an array of RAML\Resources, this function will add each Resource
  * into the Symfony Route Collection, and set the corresponding method.
  *
  * @param BasicRoute[Resource] $resources
  *  Associative array where the key is the method and full path, and the value contains
  *  the path, method type (GET/POST etc.) and then the Raml\Method object
  *
  * @return array
  */
 public function format(array $resources)
 {
     // Loop over the Resources
     foreach ($resources as $path => $resource) {
         // This is the path from the RAML, with or without a /.
         $path = $resource->getUri() . ($this->addTrailingSlash ? '/' : '');
         // This is the baseUri + path, the complete URL.
         $url = $resource->getBaseUrl() . $path;
         // Now remove the host away, so we have the FULL path to the resource.
         // baseUri may also contain path that has been omitted for brevity in the
         // RAML creation.
         $host = parse_url($url, PHP_URL_HOST);
         $fullPath = substr($url, strpos($url, $host) + strlen($host));
         // Now build our Route class.
         $route = new Route($fullPath);
         $route->setMethods($resource->getMethod()->getType());
         $route->setSchemes($resource->getProtocols());
         // Loop over each of the URI Parameters searching for validation patterns
         // or default values for parameters.
         foreach ($resource->getUriParameters() as $name => $param) {
             $route->setRequirement($name, $param->getValidationPattern());
             if ($default = $param->getDefault()) {
                 $route->setDefault($name, $default);
             }
         }
         $this->routes->add($resource->getType() . ' ' . $path, $route);
     }
     return $resources;
 }
开发者ID:TheKnarf,项目名称:php-raml-parser,代码行数:39,代码来源:SymfonyRouteFormatter.php

示例5: it_adds_input_for_dynamic_form_type

 /** @test */
 public function it_adds_input_for_dynamic_form_type()
 {
     $apiDoc = new ApiDoc([]);
     $generateApiDocAnnotation = new GenerateApiDoc([]);
     $route = new Route('/posts', ['_entity' => Post::class, '_roles' => ['ROLE_ADMIN']]);
     $route->setMethods(['POST']);
     $method = $this->getMockBuilder(\ReflectionMethod::class)->disableOriginalConstructor()->getMock();
     $handler = new GenerateApiDocHandler($this->manager, $this->em, $this->router, $this->client->getContainer());
     $handler->handle($apiDoc, [$generateApiDocAnnotation], $route, $method);
     $this->assertCount(5, $apiDoc->getParameters());
     $this->assertEquals(Post::class, $apiDoc->getOutput());
 }
开发者ID:bitecodes,项目名称:rest-api-generator-bundle,代码行数:13,代码来源:GenerateApiDocHandlerTest.php

示例6: load

 /**
  * @param string $resource
  * @param null   $type
  *
  * @return RouteCollection
  */
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add the "siab" loader twice');
     }
     $routes = new RouteCollection();
     $path = $this->container->getParameter('symfonian_id.admin.home.route_path');
     $defaults = array('_controller' => $this->container->getParameter('symfonian_id.admin.home.controller'));
     $route = new Route($path, $defaults, array(), array('expose' => true));
     $route->setMethods('GET');
     $routes->add('home', $route);
     $this->loaded = true;
     return $routes;
 }
开发者ID:deryfebriantara,项目名称:AdminBundle,代码行数:20,代码来源:HomeRouteLoader.php

示例7: generateRouteCollection

 private function generateRouteCollection(ParameterBag $routes) : RouteCollection
 {
     $routeCollection = new RouteCollection();
     foreach ($routes as $key => $route) {
         $pattern = explode('::', $route->route, 2);
         $sfRoute = new Route(isset($pattern[1]) ? $pattern[1] : $pattern[0]);
         if (isset($route->require)) {
             $sfRoute->setRequirements((array) $route->require);
         }
         if (isset($pattern[1])) {
             $sfRoute->setMethods(strtoupper($pattern[0]));
         }
         $routeCollection->add($key, $sfRoute);
     }
     return $routeCollection;
 }
开发者ID:ndufreche,项目名称:tiimber,代码行数:16,代码来源:RouteResolverTrait.php

示例8: load

 /** {@inheritdoc} */
 public function load($resource, $type = null)
 {
     if ($this->loaded) {
         throw new \LogicException('Endpoint loader is already loaded');
     }
     $collection = new RouteCollection();
     foreach ($this->endpoints as $name => $endpoint) {
         // prepare a new route
         $path = $endpoint['path'];
         $defaults = $endpoint['defaults'];
         $route = new Route($path, $defaults);
         $route->setMethods('POST');
         $collection->add($name, $route);
     }
     $this->loaded = true;
     return $collection;
 }
开发者ID:bankiru,项目名称:rpc-server-bundle,代码行数:18,代码来源:EndpointRouteLoader.php

示例9: GetRouteCollection

 /**
  * Extract route collection from config/routes.yml
  * 
  * @return \Symfony\Component\Routing\RouteCollection
  */
 public static function GetRouteCollection()
 {
     // create Symfony routing route collection
     $collection = new RouteCollection();
     $routearray = new RouteArray();
     $value = $routearray->getAll();
     // fill collection
     foreach ($value as $name => $rte) {
         $rp = new RouteParser($rte, $name);
         if ($rp->parse()) {
             $defaults = $rp->getArrayParams();
             $route = new Route($rp->getPattern(), $defaults);
             $route->setMethods($rp->getMethods());
             $collection->add($name, $route);
         }
     }
     return $collection;
 }
开发者ID:kletellier,项目名称:mvc,代码行数:23,代码来源:RouteProvider.php

示例10: configureRoute

 /**
  * Configures the _controller default parameter and eventually the HTTP method
  * requirement of a given Route instance.
  *
  * @param Route             $route  A route instance
  * @param \ReflectionClass  $class  A ReflectionClass instance
  * @param \ReflectionMethod $method A ReflectionClass method
  * @param mixed             $annot  The annotation class instance
  *
  * @throws \LogicException When the service option is specified on a method
  */
 protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
 {
     // controller
     $classAnnot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass);
     if ($classAnnot instanceof FrameworkExtraBundleRoute && ($service = $classAnnot->getService())) {
         $route->setDefault('_controller', $service . ':' . $method->getName());
     } else {
         $route->setDefault('_controller', $class->getName() . '::' . $method->getName());
     }
     // requirements (@Method)
     foreach ($this->reader->getMethodAnnotations($method) as $configuration) {
         if ($configuration instanceof Method) {
             $route->setMethods(implode('|', $configuration->getMethods()));
         } elseif ($configuration instanceof FrameworkExtraBundleRoute && $configuration->getService()) {
             throw new \LogicException('The service option can only be specified at class level.');
         }
     }
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:29,代码来源:AnnotatedRouteControllerLoader.php

示例11: format

 /**
  * Given an array of RAML\Resources, this function will add each Resource
  * into the Symfony Route Collection, and set the corresponding method.
  *
  * @param BasicRoute[] $resources
  *  Associative array where the key is the method and full path, and the value contains
  *  the path, method type (GET/POST etc.) and then the Raml\Method object
  *
  * @return array
  */
 public function format(array $resources)
 {
     foreach ($resources as $path => $resource) {
         // This is the path from the RAML, with or without a /.
         $path = $resource->getUri() . ($this->addTrailingSlash ? '/' : '');
         // This is the baseUri + path, the complete URL.
         $url = $resource->getBaseUrl() . $path;
         // Now remove the host away, so we have the FULL path to the resource.
         // baseUri may also contain path that has been omitted for brevity in the
         // RAML creation.
         $host = parse_url($url, PHP_URL_HOST);
         $fullPath = substr($url, strpos($url, $host) + strlen($host));
         // Now build our Route class.
         $route = new Route($fullPath);
         $route->setMethods($resource->getMethod()->getType());
         $route->setSchemes($resource->getProtocols());
         $this->routes->add($resource->getType() . ' ' . $path, $route);
     }
     return $resources;
 }
开发者ID:eerootsus,项目名称:php-raml-parser,代码行数:30,代码来源:SymfonyRouteFormatter.php

示例12: load

 public function load($resource, $type = null)
 {
     $collection = new RouteCollection();
     $resource = str_replace('\\', '/', $resource);
     $this->yaml = Yaml::parse(file_get_contents($this->getGeneratorFilePath($resource)));
     $namespace = $this->getNamespaceFromResource($resource);
     $bundle_name = $this->getBundleNameFromResource($resource);
     foreach ($this->actions as $controller => $datas) {
         $action = 'index';
         $loweredNamespace = str_replace(array('/', '\\'), '_', $namespace);
         if ($controller_folder = $this->getControllerFolder($resource)) {
             $route_name = $loweredNamespace . '_' . $bundle_name . '_' . $controller_folder . '_' . $controller;
         } else {
             $route_name = $loweredNamespace . '_' . $bundle_name . '_' . $controller;
         }
         if (in_array($controller, array('edit', 'update', 'object', 'show')) && null !== ($pk_requirement = $this->getFromYaml('params.pk_requirement', null))) {
             $datas['requirements'] = array_merge($datas['requirements'], array('pk' => $pk_requirement));
         }
         if (isset($datas['controller'])) {
             $action = $controller;
             $controller = $datas['controller'];
         }
         $controllerName = $resource . ucfirst($controller) . 'Controller.php';
         if (!is_file($controllerName)) {
             // TODO: what does it mean if controller is not a file??
             continue;
         }
         if ($controller_folder) {
             $datas['defaults']['_controller'] = $namespace . '\\' . $bundle_name . '\\Controller\\' . $controller_folder . '\\' . ucfirst($controller) . 'Controller::' . $action . 'Action';
         } else {
             $datas['defaults']['_controller'] = $loweredNamespace . $bundle_name . ':' . ucfirst($controller) . ':' . $action;
         }
         $route = new Route($datas['path'], $datas['defaults'], $datas['requirements']);
         $route->setMethods($datas['methods']);
         $route_name = ltrim($route_name, '_');
         // fix routes in AppBundle without vendor
         $collection->add($route_name, $route);
         $collection->addResource(new FileResource($controllerName));
     }
     return $collection;
 }
开发者ID:hyperlator,项目名称:GeneratorBundle,代码行数:41,代码来源:RoutingLoader.php

示例13: dispatch

 public function dispatch()
 {
     // @todo - create the RouteCollection
     // @todo - run the matcher against this and get a route back
     $this->router = $this->serviceManager->get('MicroRouter');
     $routeCollection = new RouteCollection();
     foreach ($this->routes as $routeKey => $r) {
         $route = new Route($r['uri']);
         $route->setMethods($r['method']);
         $routeCollection->add($routeKey, $route);
         // @todo - dont md5() this.
     }
     $request = $this->getRequest();
     $requestContext = $this->getServiceManager()->get('RouterRequestContext');
     $requestContext->fromRequest($request);
     $matcher = new UrlMatcher($routeCollection, $requestContext);
     // @todo - try catch this
     $routeAttributes = $matcher->match($request->getPathInfo());
     $matchedRouteKey = $routeAttributes['_route'];
     $this->routes[$matchedRouteKey]['callback']($this->getServiceManager());
     // @todo - handle when the callback returns a Response object and send that to the client.
     return $this;
 }
开发者ID:dragoonis,项目名称:framework,代码行数:23,代码来源:MicroApp.php

示例14: createRoute

 private function createRoute($path, array $globals, array $options = [])
 {
     foreach ($globals as $k => $v) {
         if (is_array($v) && isset($options[$k])) {
             $options[$k] = array_merge($v, $options[$k]);
         } else {
             $options[$k] = isset($options[$k]) ? $options[$k] : $v;
         }
     }
     $route = new Route($path);
     if (isset($options['host'])) {
         $route->setHost($options['host']);
     }
     if (isset($options['defaults'])) {
         $route->setDefaults($options['defaults']);
     }
     if (isset($options['requirements'])) {
         $route->setRequirements($options['requirements']);
     }
     if (isset($options['methods'])) {
         $route->setMethods($options['methods']);
     }
     return $route;
 }
开发者ID:EXSyst,项目名称:ApiBundle,代码行数:24,代码来源:ApiClassLoaderTest.php

示例15: load

 /**
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  *
  * @param mixed $resource
  * @param null  $type
  *
  * @return RouteCollection
  */
 public function load($resource, $type = null)
 {
     $resource = (string) $resource;
     if (in_array($resource, $this->loadedSpecs)) {
         throw new \RuntimeException("Resource '{$resource}' was already loaded");
     }
     $document = $this->documentRepository->get($resource);
     $routes = new RouteCollection();
     foreach ($document->getPathDefinitions() as $path => $methods) {
         $relativePath = ltrim($path, '/');
         $resourceName = strpos($relativePath, '/') ? substr($relativePath, 0, strpos($relativePath, '/')) : $relativePath;
         foreach ($methods as $methodName => $operationSpec) {
             $operationName = isset($operationSpec['operationId']) ? $operationSpec['operationId'] : $methodName;
             $defaults = ['_controller' => "swagger.controller.{$resourceName}:{$operationName}", '_definition' => $resource];
             $requirements = [];
             $route = new Route($path, $defaults, $requirements);
             $route->setMethods($methodName);
             $routeName = "swagger.{$this->createRouteIdFromPath($path)}.{$operationName}";
             $routes->add($routeName, $route);
         }
     }
     $this->loadedSpecs[] = $resource;
     return $routes;
 }
开发者ID:krizon,项目名称:swagger-bundle,代码行数:32,代码来源:SwaggerRouteLoader.php


注:本文中的Symfony\Component\Routing\Route::setMethods方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。