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


PHP ReflectionMethod类代码示例

本文整理汇总了PHP中ReflectionMethod的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod类的具体用法?PHP ReflectionMethod怎么用?PHP ReflectionMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: validate

 /**
  * {@inheritdoc}
  */
 public function validate($object, Constraint $constraint)
 {
     if (null === $object) {
         return;
     }
     if (null !== $constraint->callback && null !== $constraint->methods) {
         throw new ConstraintDefinitionException('The Callback constraint supports either the option "callback" ' . 'or "methods", but not both at the same time.');
     }
     // has to be an array so that we can differentiate between callables
     // and method names
     if (null !== $constraint->methods && !is_array($constraint->methods)) {
         throw new UnexpectedTypeException($constraint->methods, 'array');
     }
     $methods = $constraint->methods ?: array($constraint->callback);
     foreach ($methods as $method) {
         if (is_array($method) || $method instanceof \Closure) {
             if (!is_callable($method)) {
                 throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1]));
             }
             call_user_func($method, $object, $this->context);
         } else {
             if (!method_exists($object, $method)) {
                 throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist', $method));
             }
             $reflMethod = new \ReflectionMethod($object, $method);
             if ($reflMethod->isStatic()) {
                 $reflMethod->invoke(null, $object, $this->context);
             } else {
                 $reflMethod->invoke($object, $this->context);
             }
         }
     }
 }
开发者ID:JoseGMaestre,项目名称:Cupon_check,代码行数:36,代码来源:CallbackValidator.php

示例2: testGetPageFactory

 public function testGetPageFactory()
 {
     $element = $this->createElement();
     $method = new \ReflectionMethod(get_class($element), 'getPageFactory');
     $method->setAccessible(true);
     $this->assertSame($this->pageFactory, $method->invoke($element));
 }
开发者ID:qa-tools,项目名称:qa-tools,代码行数:7,代码来源:AbstractElementContainerTest.php

示例3: handleRaw

 /**
  * @internal
  *
  * @param Oxygen_Http_Request     $request
  * @param Oxygen_Util_RequestData $requestData
  * @param string                  $className
  * @param string                  $method
  * @param array                   $actionParameters
  *
  * @return Oxygen_Http_Response
  * @throws Oxygen_Exception
  */
 public function handleRaw($request, $requestData, $className, $method, array $actionParameters)
 {
     $reflectionMethod = new ReflectionMethod($className, $method);
     $parameters = $reflectionMethod->getParameters();
     $arguments = array();
     foreach ($parameters as $parameter) {
         if (isset($actionParameters[$parameter->getName()])) {
             $arguments[] = $actionParameters[$parameter->getName()];
         } else {
             if (!$parameter->isOptional()) {
                 throw new Oxygen_Exception(Oxygen_Exception::ACTION_ARGUMENT_NOT_PROVIDED);
             }
             $arguments[] = $parameter->getDefaultValue();
         }
     }
     if (is_subclass_of($className, 'Oxygen_Container_ServiceLocatorAware')) {
         $instance = call_user_func(array($className, 'createFromContainer'), $this->container);
     } else {
         $instance = new $className();
     }
     $result = call_user_func_array(array($instance, $method), $arguments);
     if (is_array($result)) {
         $result = $this->convertResultToResponse($request, $requestData, $result);
     } elseif (!$result instanceof Oxygen_Http_Response) {
         throw new LogicException(sprintf('An action should return array or an instance of Oxygen_Http_Response; %s gotten.', gettype($result)));
     }
     return $result;
 }
开发者ID:Briareos,项目名称:Oxygen,代码行数:40,代码来源:ActionKernel.php

示例4: testPreNormalize

 /**
  * @dataProvider getPreNormalizationTests
  */
 public function testPreNormalize($denormalized, $normalized)
 {
     $node = new ArrayNode('foo');
     $r = new \ReflectionMethod($node, 'preNormalize');
     $r->setAccessible(true);
     $this->assertSame($normalized, $r->invoke($node, $denormalized));
 }
开发者ID:acappel01,项目名称:opencall,代码行数:10,代码来源:ArrayNodeTest.php

示例5: execute

 /**
  * Execute requested action
  */
 public function execute()
 {
     $method = $_SERVER['REQUEST_METHOD'];
     $verbs = $this->verbs();
     if (isset($verbs[$this->requestMethod])) {
         $action = 'action' . ucfirst(mb_strtolower($verbs[$method]));
         $reflectionMethod = new \ReflectionMethod($this, $action);
         $parsePath = array_slice($this->path, count($this->route));
         $args = [];
         $errors = [];
         if ($params = $reflectionMethod->getParameters()) {
             foreach ($params as $key => $param) {
                 if (isset($parsePath[$key])) {
                     $args[$param->name] = $parsePath[$key];
                 } else {
                     $errors[] = ['code' => 'required', 'message' => ucfirst(mb_strtolower(explode('_', $param->name)[0])) . ' cannot be blank.', 'name' => $param->name];
                 }
             }
             if ($errors) {
                 throw new \phantomd\ShopCart\modules\base\HttpException(400, 'Invalid data parameters', 0, null, $errors);
             }
         }
         if (count($parsePath) === count($params)) {
             return call_user_func_array([$this, $action], $args);
         }
     }
     throw new HttpException(404, 'Unable to resolve the request "' . $this->requestPath . '".', 0, null, $errors);
 }
开发者ID:phantom-d,项目名称:shop-cart,代码行数:31,代码来源:BaseController.php

示例6: getHtmlData

 public function getHtmlData()
 {
     $htmlDataString = "";
     foreach (get_class_methods(get_called_class()) as $method) {
         if (substr($method, 0, 3) == "get" && $method != "getHtmlData" && $method != "getPK") {
             $ref = new ReflectionMethod($this, $method);
             if (sizeOf($ref->getParameters()) == 0) {
                 $field = strtolower(substr($method, 3));
                 $value = $this->{$method}();
                 if (is_object($value)) {
                     if (get_class($value) != "Doctrine\\ORM\\PersistentCollection") {
                         $field = "id{$field}";
                         $pkGetter = "get" . $field;
                         $value = $value->{$pkGetter}();
                         $data = "data-{$field}=\"" . $value . "\" ";
                         $htmlDataString .= $data;
                     }
                 } else {
                     $data = "data-{$field}=\"" . $value . "\" ";
                     $htmlDataString .= $data;
                 }
             }
         }
     }
     return $htmlDataString . " data-crud=" . get_called_class() . " data-string=" . $this;
 }
开发者ID:phcs93,项目名称:proline,代码行数:26,代码来源:Model.php

示例7: connect

 /**
  * Actual routing + sanitizing data
  *
  * @param       $class
  * @param array $params
  */
 public static function connect($namespace, $class, $params = array())
 {
     $defaults = array('indexPage' => 'index', 'loginPage' => false, 'loginRedirect' => false);
     static::$class = strtolower($class);
     $class = $namespace . '\\' . $class;
     $params += $defaults;
     extract($params);
     // Authenticated controllers
     if ($loginPage) {
         Auth::checkLogin($loginRedirect, $loginPage);
     }
     $method = $indexPage;
     $parameters = array();
     if (isset($_SERVER[URI_INFO])) {
         $url = explode('/', substr($_SERVER[URI_INFO], 1));
         array_shift($url);
         if ($url) {
             foreach ($url as $key => $element) {
                 if (!$key && !is_numeric($element)) {
                     $method = $element;
                 } else {
                     $parameters[] = $element;
                 }
             }
         }
     }
     // Check availability
     try {
         $methodInfo = new \ReflectionMethod($class, $method);
         // Methods that start with _ are not accesible from browser
         $name = $methodInfo->getName();
         if ($name[0] == '_') {
             $method = $indexPage;
         }
         $methodParams = $methodInfo->getParameters();
         // Force cast parameters by arguments default value
         if ($methodParams) {
             foreach ($methodParams as $parameterKey => $parameterValue) {
                 try {
                     $defaultValue = $parameterValue->getDefaultValue();
                     $type = gettype($defaultValue);
                     if ($defaultValue) {
                         unset($methodParams[$parameterKey]);
                     }
                     //							settype($parameters[$parameterKey], $type);
                 } catch (\Exception $e) {
                     continue;
                 }
             }
         }
         //				if(count($methodParams) != count($parameters)) {
         //					$parameters = array();
         //				}
     } catch (\Exception $e) {
         $method = $indexPage;
     }
     static::$method = $method;
     call_user_func_array($class . '::' . $method, $parameters);
     return;
 }
开发者ID:unDemian,项目名称:gcdc-migrate,代码行数:66,代码来源:Router.php

示例8: __get

 /**
  * Magic function to read a data value
  *
  * @param $name string Name of the property to be returned
  * @throws Exception
  * @return mixed
  */
 public function __get($name)
 {
     if (isset($this->_valueMap[$name])) {
         $key = $this->_valueMap[$name];
     } else {
         $key = $name;
     }
     if (!is_array($this->_primaryKey) && $key == $this->_primaryKey) {
         return $this->getId();
     }
     if (!array_key_exists($key, $this->_data)) {
         // Is there a public getter function for this value?
         $functionName = $this->composeGetterName($key);
         if (method_exists($this, $functionName)) {
             $reflection = new \ReflectionMethod($this, $functionName);
             if ($reflection->isPublic()) {
                 return $this->{$functionName}();
             }
         }
         throw new Exception('Column not found in data: ' . $name);
     }
     $result = $this->_data[$key];
     if (isset($this->_formatMap[$key])) {
         $result = Format::fromSql($this->_formatMap[$key], $result);
     }
     return $result;
 }
开发者ID:lastzero,项目名称:sympathy,代码行数:34,代码来源:Entity.php

示例9: test_set_template

 /**
  * @covers System::set_template
  */
 public function test_set_template()
 {
     $method = new ReflectionMethod(System::class, 'set_template');
     $method->setAccessible(true);
     $method->invoke($this->system_obj);
     self::assertTrue($this->system_obj->template instanceof \common\interfaces\Template);
 }
开发者ID:one-more,项目名称:peach_framework,代码行数:10,代码来源:SystemTest.php

示例10: __construct

 public function __construct(\ReflectionMethod $method)
 {
     $this->_method = $method;
     $comment = $method->getDocComment();
     $comment = new DocBloc($comment);
     $this->_annotations = $comment->getAnnotations();
 }
开发者ID:richardjohn,项目名称:FlowProject,代码行数:7,代码来源:AnnotatedMethod.php

示例11: __construct

 public function __construct($callable, array $annotations = array())
 {
     if (is_array($callable)) {
         list($this->class, $method) = $callable;
         $reflMethod = new \ReflectionMethod($this->class, $method);
         if (!$reflMethod->isPublic()) {
             throw new \InvalidArgumentException('Class method must be public');
         } elseif ($reflMethod->isStatic()) {
             $this->staticMethod = $method;
         } else {
             $this->method = $method;
             $class = $this->class;
             $this->instance = new $class();
         }
     } elseif ($callable instanceof \Closure) {
         $this->closure = $callable;
     } elseif (is_string($callable)) {
         if (!function_exists($callable)) {
             throw new \InvalidArgumentException('Function does not exist');
         }
         $this->function = $callable;
     } else {
         throw new \InvalidArgumentException('Invalid callable type');
     }
     $this->annotations = $annotations;
 }
开发者ID:anlutro,项目名称:phpbench,代码行数:26,代码来源:Callback.php

示例12: testopen_archive

 /**
  * @covers gzip_file::open_archive
  * @todo   Implement testopen_archive().
  */
 public function testopen_archive()
 {
     $methods = get_class_methods($this->object);
     $this->assertTrue(in_array('open_archive', $methods), 'exists method open_archive');
     $r = new ReflectionMethod('gzip_file', 'open_archive');
     $params = $r->getParameters();
 }
开发者ID:emildev35,项目名称:processmaker,代码行数:11,代码来源:classgzip_fileTest.php

示例13: __call

 /**
  * Creates alias to all native methods of the resource.
  *
  * @param   string  $method  method name
  * @param   mixed   $args    arguments
  * @return  mixed
  */
 public function __call($method, $args)
 {
     $class = get_called_class();
     $obj = $class::instance();
     $method = new ReflectionMethod($obj, $method);
     return $method->invokeArgs($obj, $args);
 }
开发者ID:madeinnordeste,项目名称:kohana-aws,代码行数:14,代码来源:Core.php

示例14: testGetUrl

 public function testGetUrl()
 {
     $this->router->expects($this->once())->method('generate')->with($this->equalTo('sonata_cache_opcode'), $this->equalTo(array('token' => 'token')))->will($this->returnValue('/sonata/cache/opcode/token'));
     $method = new \ReflectionMethod($this->cache, 'getUrl');
     $method->setAccessible(true);
     $this->assertEquals('/sonata/cache/opcode/token', $method->invoke($this->cache));
 }
开发者ID:amine2z,项目名称:SonataCacheBundle,代码行数:7,代码来源:OpCodeCacheTest.php

示例15: moduleHasMethod

 /**
  * Check to see if said module has method and is publically callable
  * @param {string} $module The raw module name
  * @param {string} $method The method name
  */
 public function moduleHasMethod($module, $method)
 {
     $this->getActiveModules();
     $module = ucfirst(strtolower($module));
     if (!empty($this->moduleMethods[$module]) && in_array($method, $this->moduleMethods[$module])) {
         return true;
     }
     $amods = array();
     foreach (array_keys($this->active_modules) as $mod) {
         $amods[] = $this->cleanModuleName($mod);
     }
     if (in_array($module, $amods)) {
         try {
             $rc = new \ReflectionClass($this->FreePBX->{$module});
             if ($rc->hasMethod($method)) {
                 $reflection = new \ReflectionMethod($this->FreePBX->{$module}, $method);
                 if ($reflection->isPublic()) {
                     $this->moduleMethods[$module][] = $method;
                     return true;
                 }
             }
         } catch (\Exception $e) {
         }
     }
     return false;
 }
开发者ID:umjinsun12,项目名称:dngshin,代码行数:31,代码来源:Modules.class.php


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