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


PHP ReflectionClass::hasMethod方法代码示例

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


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

示例1: evaluateCallback

 /**
  * Evaluate the callback and create an object instance if required and possible.
  *
  * @param array|callable $callback The callback to invoke.
  *
  * @return array|callable
  */
 protected static function evaluateCallback($callback)
 {
     if (is_array($callback) && count($callback) == 2 && is_string($callback[0]) && is_string($callback[1])) {
         $class = new \ReflectionClass($callback[0]);
         // Ff the method is static, do not create an instance.
         if ($class->hasMethod($callback[1]) && $class->getMethod($callback[1])->isStatic()) {
             return $callback;
         }
         // Fetch singleton instance.
         if ($class->hasMethod('getInstance')) {
             $getInstanceMethod = $class->getMethod('getInstance');
             if ($getInstanceMethod->isStatic()) {
                 $callback[0] = $getInstanceMethod->invoke(null);
                 return $callback;
             }
         }
         // Create a new instance.
         $constructor = $class->getConstructor();
         if (!$constructor || $constructor->isPublic()) {
             $callback[0] = $class->newInstance();
         } else {
             $callback[0] = $class->newInstanceWithoutConstructor();
             $constructor->setAccessible(true);
             $constructor->invoke($callback[0]);
         }
     }
     return $callback;
 }
开发者ID:amenk,项目名称:dc-general,代码行数:35,代码来源:Callbacks.php

示例2: mapBy

 /**
  * Map collection by key. For objects, return the property, use
  * get method or is method, if avaliable.
  *
  * @param  array                     $input Array of arrays or objects.
  * @param  string                    $key   Key to map by.
  * @throws \InvalidArgumentException If array item is not an array or object.
  * @throws \LogicException           If array item could not be mapped by given key.
  * @return array                     Mapped array.
  */
 public function mapBy(array $input, $key)
 {
     return array_map(function ($item) use($key) {
         if (is_array($item)) {
             if (!array_key_exists($key, $item)) {
                 throw new \LogicException("Could not map item by key \"{$key}\". Array key does not exist.");
             }
             return $item[$key];
         }
         if (!is_object($item)) {
             throw new \InvalidArgumentException("Item must be an array or object.");
         }
         $ref = new \ReflectionClass($item);
         if ($ref->hasProperty($key) && $ref->getProperty($key)->isPublic()) {
             return $item->{$key};
         }
         if ($ref->hasMethod($key) && !$ref->getMethod($key)->isPrivate()) {
             return $item->{$key}();
         }
         $get = 'get' . ucfirst($key);
         if ($ref->hasMethod($get) && !$ref->getMethod($get)->isPrivate()) {
             return $item->{$get}();
         }
         $is = 'is' . ucfirst($key);
         if ($ref->hasMethod($is) && !$ref->getMethod($is)->isPrivate()) {
             return $item->{$is}();
         }
         throw new \LogicException("Could not map item by key \"{$key}\". Cannot access the property directly or through getter/is method.");
     }, $input);
 }
开发者ID:andriantodorov,项目名称:GeneratorBundle,代码行数:40,代码来源:ArrayExtension.php

示例3: callHooks

 /**
  * Call the initialization hooks.
  *
  * @param \Pimple $container The container that got initialized.
  *
  * @return void
  *
  * @throws \InvalidArgumentException When the hook method is invalid.
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function callHooks($container)
 {
     if (isset($GLOBALS['TL_HOOKS']['initializeDependencyContainer']) && is_array($GLOBALS['TL_HOOKS']['initializeDependencyContainer'])) {
         foreach ($GLOBALS['TL_HOOKS']['initializeDependencyContainer'] as $callback) {
             if (is_array($callback)) {
                 $class = new \ReflectionClass($callback[0]);
                 if (!$class->hasMethod($callback[1])) {
                     if ($class->hasMethod('__call')) {
                         $method = $class->getMethod('__call');
                         $args = array($callback[1], $container);
                     } else {
                         throw new \InvalidArgumentException(sprintf('No such Method %s::%s', $callback[0], $callback[1]));
                     }
                 } else {
                     $method = $class->getMethod($callback[1]);
                     $args = array($container);
                 }
                 $object = null;
                 if (!$method->isStatic()) {
                     $object = $this->getInstanceOf($callback[0]);
                 }
                 $method->invokeArgs($object, $args);
             } else {
                 call_user_func($callback, $container);
             }
         }
     }
 }
开发者ID:contao-community-alliance,项目名称:dependency-container,代码行数:40,代码来源:ContainerInitializer.php

示例4: testContracts

 public function testContracts()
 {
     $this->assertTrue($this->reflectedObject->isAbstract());
     $this->assertTrue($this->reflectedObject->hasMethod('cleanVar'));
     $this->assertTrue($this->reflectedObject->hasMethod('getVar'));
     $this->assertInstanceOf('\\Xoops\\Core\\Text\\Sanitizer', \PHPUnit_Framework_Assert::readAttribute($this->object, 'ts'));
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:7,代码来源:DtypeAbstractTest.php

示例5: testContracts

 public function testContracts()
 {
     $this->assertTrue($this->reflectedObject->isAbstract());
     $this->assertTrue($this->reflectedObject->hasMethod('getDhtmlEditorSupport'));
     $this->assertTrue($this->reflectedObject->hasMethod('registerExtensionProcessing'));
     $this->assertTrue($this->reflectedObject->hasMethod('getEditorButtonHtml'));
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:7,代码来源:ExtensionAbstractTest.php

示例6: testHasMethods

 public function testHasMethods()
 {
     $reflection = new \ReflectionClass('\\Cekurte\\Environment\\Resource\\ResourceInterface');
     $this->assertTrue($reflection->hasMethod('setResource'));
     $this->assertTrue($reflection->hasMethod('getResource'));
     $this->assertTrue($reflection->hasMethod('process'));
 }
开发者ID:eltonoliveira,项目名称:environment,代码行数:7,代码来源:ResourceInterfaceTest.php

示例7: load

 public function load(Application $application)
 {
     $in = $this->container->getParameter('seed.directory');
     //add seed:load and seed:unload commands
     $application->add($this->container->get('seed.load_seeds_command'));
     $application->add($this->container->get('seed.unload_seeds_command'));
     //Go through bundles and add *Seeds available in seed.directory
     foreach ($application->getKernel()->getBundles() as $bundle) {
         if (!is_dir($dir = sprintf('%s/%s', $bundle->getPath(), $in))) {
             continue;
         }
         $finder = new Finder();
         $finder->files()->name('*Seed.php')->in($dir);
         $prefix = $bundle->getNameSpace() . '\\' . strtr($in, '/', '\\');
         foreach ($finder as $file) {
             $ns = $prefix;
             if ($relativePath = $file->getRelativePath()) {
                 $ns .= '\\' . strtr($relativePath, '/', '\\');
             }
             $class = $ns . '\\' . $file->getBasename('.php');
             $alias = 'seed.command.' . strtolower(str_replace('\\', '_', $class));
             if ($this->container->has($alias)) {
                 continue;
             }
             $r = new \ReflectionClass($class);
             if ($r->isSubclassOf('Soyuka\\SeedBundle\\Command\\Seed') && !$r->isAbstract() && ($r->hasMethod('load') || $r->hasMethod('unload'))) {
                 $application->add($r->newInstanceArgs([$this->prefix, $this->separator]));
             }
         }
     }
 }
开发者ID:soyuka,项目名称:SeedBundle,代码行数:31,代码来源:Loader.php

示例8: initializeModels

 /**
  * Initializes the EventDispatcher-aware models.
  *
  * This methods has to accept unknown classes as it is triggered during
  * the boot and so will be called before running the propel:build command.
  */
 public function initializeModels()
 {
     foreach ($this->classes as $id => $class) {
         $baseClass = sprintf('%s\\om\\Base%s', substr($class, 0, strrpos($class, '\\')), substr($class, strrpos($class, '\\') + 1, strlen($class)));
         try {
             $ref = new \ReflectionClass($baseClass);
         } catch (\ReflectionException $e) {
             $this->log(sprintf('The class "%s" does not exist.', $baseClass));
             continue;
         }
         try {
             $ref = new \ReflectionClass($class);
         } catch (\ReflectionException $e) {
             $this->log(sprintf('The class "%s" does not exist. Either your model is not generated yet or you have an error in your listener configuration.', $class));
             continue;
         }
         $canSetEventDispatcher = false;
         if (strpos($class, 'Query') !== false && $ref->hasMethod('setEventDispatcher') && $ref->hasMethod('getEventDispatcher')) {
             $canSetEventDispatcher = true;
         } elseif (strpos($class, 'Query') !== false) {
             $this->log(sprintf('The class "%s" does not implement "%s" and "%s" methods.', $class, 'setEventDispatcher', 'getEventDispatcher'));
             continue;
         }
         if (!$canSetEventDispatcher && !$ref->implementsInterface(self::MODEL_INTERFACE)) {
             $this->log(sprintf('The class "%s" does not implement "%s". Either your model is outdated or you forgot to add the EventDispatcherBehavior.', $class, self::MODEL_INTERFACE));
             continue;
         }
         $class::setEventDispatcher(new LazyEventDispatcher($this->container, $id));
     }
 }
开发者ID:GoldenLine,项目名称:BazingaPropelEventDispatcherBundle,代码行数:36,代码来源:DispatcherInjector.php

示例9: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     foreach ($container->findTaggedServiceIds('mautic.model') as $id => $tags) {
         $definition = $container->findDefinition($id);
         $definition->addMethodCall('setEntityManager', [new Reference('doctrine.orm.entity_manager')]);
         $definition->addMethodCall('setSecurity', [new Reference('mautic.security')]);
         $definition->addMethodCall('setDispatcher', [new Reference('event_dispatcher')]);
         $definition->addMethodCall('setTranslator', [new Reference('translator')]);
         $definition->addMethodCall('setUserHelper', [new Reference('mautic.helper.user')]);
         $modelClass = $definition->getClass();
         $reflected = new \ReflectionClass($modelClass);
         if ($reflected->hasMethod('setRouter')) {
             $definition->addMethodCall('setRouter', [new Reference('router')]);
         }
         if ($reflected->hasMethod('setLogger')) {
             $definition->addMethodCall('setLogger', [new Reference('monolog.logger.mautic')]);
         }
         if ($reflected->hasMethod('setSession')) {
             $definition->addMethodCall('setSession', [new Reference('session')]);
         }
         // Temporary, for development purposes
         if ($reflected->hasProperty('factory')) {
             $definition->addMethodCall('setFactory', [new Reference('mautic.factory')]);
         }
     }
 }
开发者ID:dongilbert,项目名称:mautic,代码行数:29,代码来源:ModelPass.php

示例10: validateCallback

 /**
  * Validates a callback more strictly and with more detailed errors.
  *
  * @param string|object|array $class A class name, object, function name, or array containing class/object and method
  * @param null|string $method If first param is class or object, the method name
  * @param string $error Error key returned by reference
  * @param bool $forceMethod If true, if no method is provided, never treat the class as a function
  *
  * @return bool
  *
  * @throws InvalidArgumentException
  */
 public static function validateCallback($class, $method = null, &$error = null, $forceMethod = true)
 {
     if (is_array($class)) {
         if ($method) {
             throw new InvalidArgumentException('Method cannot be provided with class as array');
         }
         $method = $class[1];
         $class = $class[0];
     }
     if ($forceMethod) {
         $method = strval($method);
     } else {
         if (!$method) {
             if (is_object($class)) {
                 throw new InvalidArgumentException('Object given with no method');
             }
             if (!function_exists($class)) {
                 $error = 'invalid_function';
                 return false;
             } else {
                 return true;
             }
         }
     }
     if (!is_string($method)) {
         throw new InvalidArgumentException('Method to check is not a string');
     }
     if (!is_object($class)) {
         if (!$class || !class_exists($class)) {
             $error = 'invalid_class';
             return false;
         }
     }
     $reflectionClass = new ReflectionClass($class);
     $isObject = is_object($class);
     if ($isObject && $reflectionClass->hasMethod('__call') || !$isObject && $reflectionClass->hasMethod('__callStatic')) {
         // magic method will always be called if a method can't be
         return true;
     }
     if (!$method || !$reflectionClass->hasMethod($method)) {
         $error = 'invalid_method';
         return false;
     }
     $reflectionMethod = $reflectionClass->getMethod($method);
     if ($reflectionMethod->isAbstract() || !$reflectionMethod->isPublic()) {
         $error = 'invalid_method_configuration';
         return false;
     }
     $isStatic = $reflectionMethod->isStatic();
     if ($isStatic && $isObject) {
         $error = 'method_static';
         return false;
     } else {
         if (!$isStatic && !$isObject) {
             $error = 'method_not_static';
             return false;
         }
     }
     return true;
 }
开发者ID:darkearl,项目名称:projectT122015,代码行数:72,代码来源:Php.php

示例11: testAddMethod

 /**
  */
 public function testAddMethod()
 {
     $method = new ReflectionMethod('testMethod');
     $this->assertFalse($this->object->hasMethod('testMethod'));
     $this->object->addMethod($method);
     $this->assertTrue($this->object->hasMethod('testMethod'));
 }
开发者ID:neiluJ,项目名称:Documentor,代码行数:9,代码来源:ReflectionClassTest.php

示例12: invoke

 public function invoke(URLComponent $url)
 {
     $class_name = $url->getController();
     $method = $url->getAction();
     $class = $this->app . '\\action\\' . $class_name;
     //Response对象
     $response = Response::getInstance();
     //Request对象
     $request = Request::getInstance();
     #实例化控制器,使用反射
     $reflection = new \ReflectionClass($class);
     $instacne = $reflection->newInstance();
     //先执行初始化方法init
     if ($reflection->hasMethod('init')) {
         $init = $reflection->getMethod('init');
         $data = $init->invokeArgs($instacne, array($request, $response));
         if ($data) {
             //如果有返回数据则输出
             $response->setBody($data);
             $response->send();
             return true;
         }
     }
     if ($reflection->hasMethod($method)) {
         $method = $reflection->getMethod($method);
     } elseif ($reflection->hasMethod('getMiss')) {
         $method = $reflection->getMethod('getMiss');
     } else {
         throw new RouteException('Method does not exist.');
     }
     $data = $method->invokeArgs($instacne, array($request, $response));
     #输出
     $response->setBody($data);
     $response->send();
 }
开发者ID:qazzhoubin,项目名称:emptyphp,代码行数:35,代码来源:Route.php

示例13: make

 public static function make($name, $param = [])
 {
     $name = strtolower($name);
     if (isset(self::$wareHouse[$name . join(":", $param)])) {
         return self::$wareHouse[$name . join(":", $param)];
     }
     if (!($service = Dependency::getService($name))) {
         Log::Error("The service \"{$name}\" dose not exist!");
         throw new \Exception("The service \"{$name}\" dose not exist!", 1);
     }
     if (!class_exists($service)) {
         Log::Error("Class \" {$service}\" dose not exist!");
         throw new \Exception("Class \" {$service}\" dose not exist!", 1);
     }
     $reflectClass = new \ReflectionClass($service);
     if ($reflectClass->hasMethod("newInstance")) {
         if (empty($param)) {
             return self::$wareHouse[$name] = call_user_func([$service, "newInstance"]);
         } else {
             return self::$wareHouse[$name . join(":", $param)] = call_user_func_array([$service, "newInstance"], $param);
         }
     }
     if ($constructor = $reflectClass->hasMethod("__construct")) {
         if ($constructor->isPublic()) {
             return self::$wareHouse[$name . join(":", $param)] = $reflectClass->newInstanceArgs($param);
         }
     }
     throw new \Exception("Class \" {$service} \" has no public contructor ", 1);
 }
开发者ID:longmonhau,项目名称:Half-Life,代码行数:29,代码来源:Factory.php

示例14: testGetterAndSetter

 /**
  * @dataProvider getClass
  */
 public function testGetterAndSetter($class, $constructorParameterList)
 {
     $reflexionClass = new \ReflectionClass($class);
     if ($reflexionClass->getConstructor()) {
         $instance = $reflexionClass->newInstanceArgs($constructorParameterList);
     } else {
         $instance = $reflexionClass->newInstance();
     }
     $propertyList = $reflexionClass->getProperties();
     foreach ($propertyList as $property) {
         $name = ucfirst($property->getName());
         $property->setAccessible(true);
         $getter = 'get' . $name;
         $setter = 'set' . $name;
         if ($reflexionClass->hasMethod($setter)) {
             $type = $this->guessParamType($reflexionClass->getMethod($setter));
             if (isset($this->valueList[$type])) {
                 $value = $this->valueList[$type];
                 $instance->{$setter}($value[0]);
                 // test setter
                 $this->assertEquals($property->getValue($instance), $value[0]);
                 if ($reflexionClass->hasMethod($getter)) {
                     $property->setValue($instance, $value[1]);
                     // test getter
                     $this->assertEquals($instance->{$getter}(), $value[1]);
                 }
             }
         }
     }
 }
开发者ID:jfouca,项目名称:L10nBundle,代码行数:33,代码来源:GetterSetterTest.php

示例15: initialize

 /**
  * Initialize preferences
  *
  * @access	public
  * @param	array
  * @return	void
  */
 public function initialize(array $config = array(), $reset = TRUE)
 {
     $reflection = new ReflectionClass($this);
     if ($reset === TRUE) {
         $defaults = $reflection->getDefaultProperties();
         foreach (array_keys($defaults) as $key) {
             if ($key[0] === '_') {
                 continue;
             }
             if (isset($config[$key])) {
                 if ($reflection->hasMethod('set_' . $key)) {
                     $this->{'set_' . $key}($config[$key]);
                 } else {
                     $this->{$key} = $config[$key];
                 }
             } else {
                 $this->{$key} = $defaults[$key];
             }
         }
     } else {
         foreach ($config as $key => &$value) {
             if ($key[0] !== '_' && $reflection->hasProperty($key)) {
                 if ($reflection->hasMethod('set_' . $key)) {
                     $this->{'set_' . $key}($value);
                 } else {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     // if a file_name was provided in the config, use it instead of the user input
     // supplied file name for all uploads until initialized again
     $this->_file_name_override = $this->file_name;
     return $this;
 }
开发者ID:brandon-bailey,项目名称:osdms,代码行数:42,代码来源:MY_Upload.php


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