當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ParamConverter::setClass方法代碼示例

本文整理匯總了PHP中Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter::setClass方法的典型用法代碼示例。如果您正苦於以下問題:PHP ParamConverter::setClass方法的具體用法?PHP ParamConverter::setClass怎麽用?PHP ParamConverter::setClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter的用法示例。


在下文中一共展示了ParamConverter::setClass方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onKernelController

 /**
  * Modifies the ParamConverterManager instance.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $configurations = array();
     if ($configuration = $request->attributes->get('_converters')) {
         foreach (is_array($configuration) ? $configuration : array($configuration) as $configuration) {
             $configurations[$configuration->getName()] = $configuration;
         }
     }
     if (is_array($controller)) {
         $r = new \ReflectionMethod($controller[0], $controller[1]);
     } else {
         $r = new \ReflectionFunction($controller);
     }
     // automatically apply conversion for non-configured objects
     foreach ($r->getParameters() as $param) {
         if (!$param->getClass() || $param->getClass()->isInstance($request)) {
             continue;
         }
         $name = $param->getName();
         if (!isset($configurations[$name])) {
             $configuration = new ParamConverter(array());
             $configuration->setName($name);
             $configuration->setClass($param->getClass()->getName());
             $configurations[$name] = $configuration;
         } elseif (null === $configurations[$name]->getClass()) {
             $configurations[$name]->setClass($param->getClass()->getName());
         }
         $configurations[$name]->setIsOptional($param->isOptional());
     }
     $this->manager->apply($request, $configurations);
 }
開發者ID:joan16v,項目名稱:symfony2_test,代碼行數:38,代碼來源:ParamConverterListener.php

示例2: onCoreController

 /**
  * Modifies the ParamConverterManager instance.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  */
 public function onCoreController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $configurations = array();
     if ($configuration = $request->attributes->get('_converters')) {
         $configurations = is_array($configuration) ? $configuration : array($configuration);
     }
     if (is_array($controller)) {
         $r = new \ReflectionMethod($controller[0], $controller[1]);
     } else {
         $r = new \ReflectionFunction($controller);
     }
     // automatically apply conversion for non-configured objects
     foreach ($r->getParameters() as $param) {
         if ($param->getClass() && !$request->attributes->get($param->getName())) {
             $configuration = new ParamConverter(array());
             $configuration->setName($param->getName());
             $configuration->setClass($param->getClass()->getName());
             $configuration->setIsOptional($param->isOptional());
             $configurations[] = $configuration;
         }
     }
     $this->manager->apply($request, $configurations);
 }
開發者ID:rfc1483,項目名稱:symfony,代碼行數:30,代碼來源:ParamConverterListener.php

示例3: testMissingParameters

 public function testMissingParameters()
 {
     $config = new ParamConverter(['name' => 'credentials']);
     $config->setClass(AuthDTO::class);
     $request = Request::create('/', 'POST', ['username' => 'Ma27']);
     $converter = new DataTransferObjectParamConverter();
     $converter->apply($request, $config);
     /** @var AuthDTO $instance */
     $instance = $request->attributes->get('credentials');
     $this->assertEmpty($instance->getPassword());
 }
開發者ID:thesoftwarefactoryuk,項目名稱:SenNetwork,代碼行數:11,代碼來源:DataTransferObjectParamConverterTest.php

示例4: supports

 /**
  * {@inheritdoc}
  */
 public function supports(ParamConverter $configuration)
 {
     $original_class = $configuration->getClass();
     // Replace the class with our resolved class
     $configuration->setClass($this->resolveClass($original_class));
     if (parent::supports($configuration)) {
         return true;
     } else {
         // Reset our changes
         $configuration->setClass($original_class);
         return false;
     }
 }
開發者ID:vivait,項目名稱:resolve-entity-bundle,代碼行數:16,代碼來源:ResolveParamConverter.php

示例5: autoConfigure

 private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, $configurations)
 {
     foreach ($r->getParameters() as $param) {
         if (!$param->getClass() || $param->getClass()->isInstance($request)) {
             continue;
         }
         $name = $param->getName();
         if (!isset($configurations[$name])) {
             $configuration = new ParamConverter(array());
             $configuration->setName($name);
             $configuration->setClass($param->getClass()->getName());
             $configurations[$name] = $configuration;
         } elseif (null === $configurations[$name]->getClass()) {
             $configurations[$name]->setClass($param->getClass()->getName());
         }
         $configurations[$name]->setIsOptional($param->isOptional());
     }
     return $configurations;
 }
開發者ID:BusinessCookies,項目名稱:CoffeeMachineProject,代碼行數:19,代碼來源:ParamConverterListener.php

示例6: onCoreController

 /**
  * Modifies the ParamConverterManager instance.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  */
 public function onCoreController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $configurations = array();
     if ($configuration = $request->attributes->get('_converters')) {
         foreach (is_array($configuration) ? $configuration : array($configuration) as $configuration) {
             $configurations[$configuration->getName()] = $configuration;
         }
     }
     if (is_array($controller)) {
         $r = new \ReflectionMethod($controller[0], $controller[1]);
     } else {
         $r = new \ReflectionFunction($controller);
     }
     // automatically apply conversion for non-configured objects
     foreach ($r->getParameters() as $param) {
         if (!$param->getClass()) {
             continue;
         }
         $name = $param->getName();
         // the parameter is already set, so disable the conversion
         if ($request->attributes->has($name)) {
             unset($configurations[$name]);
         } else {
             if (isset($configurations[$name])) {
                 $configuration = $configurations[$name];
             } else {
                 $configuration = new ParamConverter(array());
                 $configuration->setName($name);
                 $configuration->setClass($param->getClass()->getName());
             }
             $configuration->setIsOptional($param->isOptional());
             $configurations[$name] = $configuration;
         }
     }
     $this->manager->apply($request, array_values($configurations));
 }
開發者ID:rfc1483,項目名稱:doctrine,代碼行數:43,代碼來源:ParamConverterListener.php


注:本文中的Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter::setClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。