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


PHP ReflectionObject::hasMethod方法代码示例

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


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

示例1: instanceMapFrom

 /**
  * @param FormField $formField
  * @param KForm     $form
  */
 public function instanceMapFrom(FormField $formField, KForm $form)
 {
     $attribute = $formField->getFieldName();
     $method = 'mappingFromFormField' . ucfirst($attribute);
     if ($this->instanceReflector->hasMethod($method)) {
         $methodReflector = $this->instanceReflector->getMethod($method);
         $parameters = array();
         foreach ($methodReflector->getParameters() as $paramReflector) {
             switch (true) {
                 case $paramReflector->getClass()->isSubclassOf(KForm::class):
                     $parameters[] = $form;
                     break;
                 case $paramReflector->getClass()->isSubclassOf(FormField::class):
                     $parameters[] = $formField;
                     break;
                 default:
                     $parameters[] = $formField;
                     break;
             }
         }
         call_user_func_array(array($this->instance, $method), $parameters);
     } else {
         $this->instance->{$attribute} = $formField->getValue();
     }
 }
开发者ID:xjtuwangke,项目名称:laravel-bundles,代码行数:29,代码来源:SingleEloquentInstance.php

示例2: runController

 public function runController($cName, $aName, $params)
 {
     $theController = new $cName();
     $reflection_object = new ReflectionObject($theController);
     if ($reflection_object->hasMethod('before_action')) {
         $reflection_object->getMethod('before_action')->invoke($theController);
     }
     call_user_func_array(array($theController, $aName), $params);
     if ($reflection_object->hasMethod('after_action')) {
         $reflection_object->getMethod('after_action')->invoke($theController);
     }
 }
开发者ID:reny-ahmad,项目名称:WayangCMS,代码行数:12,代码来源:WY_Bootstrap.php

示例3: _processObjectMethod

 /**
  * Checks to call the method.
  *
  * Throws exceptions if the method doesn't exist, is not public or if there are mandatory parameters.
  *
  * @param \ReflectionObject $reflector
  * @throws \BadMethodCallException
  */
 private static function _processObjectMethod(\ReflectionObject $reflector)
 {
     // check for method name
     if (!$reflector->hasMethod(self::$part)) {
         throw new \BadMethodCallException(sprintf('Method %s doesn\'t exist at path "%s"', self::$part, self::$actPath));
     }
     // check that method is public
     $methodReclector = $reflector->getMethod(self::$part);
     if (!$methodReclector->isPublic()) {
         throw new \BadMethodCallException(sprintf('Method %s is not public at path "%s"', self::$part, self::$actPath));
     }
     // check that method has no mandatory parameters
     $parameters = $methodReclector->getParameters();
     if (!empty($parameters)) {
         foreach ($parameters as $parameter) {
             // If has no default value, throw exception, can't call the method without parameters
             try {
                 $parameter->getDefaultValue();
             } catch (\ReflectionException $e) {
                 throw new \BadMethodCallException(sprintf('Method %s has mandatory parameter at path "%s", can\'t call it', self::$part, self::$actPath));
             }
         }
     }
     $method = self::$part;
     self::$reference = self::$reference->{$method}();
 }
开发者ID:holloway87,项目名称:hw-basics-bundle,代码行数:34,代码来源:VarAtPath.php

示例4: wrapClosures

 /**
  * Recursively traverses and wraps all Closure objects within the value.
  *
  * NOTE: THIS MAY NOT WORK IN ALL USE CASES, SO USE AT YOUR OWN RISK.
  *
  * @param mixed $data Any variable that contains closures.
  * @param SerializerInterface $serializer The serializer to use.
  */
 public static function wrapClosures(&$data, SerializerInterface $serializer)
 {
     if ($data instanceof \Closure) {
         // Handle and wrap closure objects.
         $reflection = new \ReflectionFunction($data);
         if ($binding = $reflection->getClosureThis()) {
             self::wrapClosures($binding, $serializer);
             $scope = $reflection->getClosureScopeClass();
             $scope = $scope ? $scope->getName() : 'static';
             $data = $data->bindTo($binding, $scope);
         }
         $data = new SerializableClosure($data, $serializer);
     } elseif (is_array($data) || $data instanceof \stdClass || $data instanceof \Traversable) {
         // Handle members of traversable values.
         foreach ($data as &$value) {
             self::wrapClosures($value, $serializer);
         }
     } elseif (is_object($data) && !$data instanceof \Serializable) {
         // Handle objects that are not already explicitly serializable.
         $reflection = new \ReflectionObject($data);
         if (!$reflection->hasMethod('__sleep')) {
             foreach ($reflection->getProperties() as $property) {
                 if ($property->isPrivate() || $property->isProtected()) {
                     $property->setAccessible(true);
                 }
                 $value = $property->getValue($data);
                 self::wrapClosures($value, $serializer);
                 $property->setValue($data, $value);
             }
         }
     }
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:40,代码来源:Serializer.php

示例5: __call

 /**
  * Provides functionality for getters and setters of the customer
  * @see Varien_Object::__call()
  */
 public function __call($method, $args)
 {
     if ($this->_customer instanceof Mage_Customer_Model_Customer) {
         $key = $this->_underscore(substr($method, 3));
         switch (substr($method, 0, 3)) {
             case 'get':
                 return $this->_customer->getData($key, isset($args[0]) ? $args[0] : null);
             case 'set':
                 return $this->_customer->setData($key, isset($args[0]) ? $args[0] : null);
             case 'uns':
                 return $this->_customer->unsetData($key);
             case 'has':
                 $data = $this->_customer->getData();
                 return isset($data[$key]);
         }
         try {
             $_reflectionObject = new ReflectionObject($this->_customer);
             if ($_reflectionObject->hasMethod($method)) {
                 $_reflectionMethod = new ReflectionMethod(get_class($this->_customer), $method);
                 return $_reflectionMethod->invokeArgs($this->_customer, $args);
             }
         } catch (Exception $e) {
             return parent::__call($method, $args);
         }
     }
     return parent::__call($method, $args);
 }
开发者ID:rajarshc,项目名称:Rooja,代码行数:31,代码来源:Wrapper.php

示例6: callRPCMethod

 public function callRPCMethod()
 {
     $sRawMethod = $this->oRequest->method;
     @(list($sNameSpace, $sMethod) = explode('.', $sRawMethod));
     if (is_null($sMethod)) {
         $sMethod = $sNameSpace;
         $sNameSpace = 'wp';
     }
     $oInterface = $this->getRPCInterface($sNameSpace);
     if (!$this->hasRPCMethod($oInterface, $sMethod)) {
         $this->oResponse->error = 'Invalid RPC request: method [' . var_export($sMethod, true) . '] does not exist';
     } else {
         if (is_null($this->oRequest->params) || !is_array($this->oRequest->params)) {
             throw new ExceptionResponseError('Invalid RPC request: missing parameters');
         }
         $oReflectedInterface = new \ReflectionObject($oInterface);
         if ($oReflectedInterface->hasMethod($sMethod)) {
             /* @var $oReflectedMethod \ReflectionMethod */
             $oReflectedMethod = $oReflectedInterface->getMethod($sMethod);
             if ($oReflectedMethod->isPublic()) {
                 return $oReflectedMethod->invokeArgs($oInterface, $this->oRequest->params);
             }
         }
     }
     return null;
 }
开发者ID:bogdananton,项目名称:vsc,代码行数:26,代码来源:RPCProcessorA.php

示例7: inflater

 public static function inflater(array $objects, $invokeName, $invokeArgs = null)
 {
     if (!is_array($objects) || count($objects) == 0) {
         return null;
     }
     $ref = new \ReflectionObject($objects[0]);
     $mode = $ref->hasMethod($invokeName) ? self::MODE_METHOD : self::MODE_PROPERTY;
     if ($mode == self::MODE_METHOD) {
         $values = array();
         $methodRef = $ref->getMethod($invokeName);
         $argsCount = count($methodRef->getParameters());
         unset($methodRef);
         if ($argsCount > 0) {
             foreach ($objects as $object) {
                 array_push($values, call_user_func_array(array($object, $invokeName), $invokeArgs));
             }
         } else {
             foreach ($objects as $object) {
                 array_push($values, $object->{$invokeName}());
             }
         }
         return $values;
     } elseif ($mode == self::MODE_PROPERTY) {
         $values = array();
         foreach ($objects as $object) {
             $value = $object->{$invokeName};
             array_push($values, $value);
         }
         return $values;
     } else {
         throw new \InvalidArgumentException('not found invoker');
     }
 }
开发者ID:laiello,项目名称:perminator,代码行数:33,代码来源:ObjectValueInflater.php

示例8: __call

 public function __call($method, $args)
 {
     $ro = new \ReflectionObject($this->runtimeCollection);
     if ($ro->hasMethod($method)) {
         call_user_func_array([$this->runtimeCollection, $method], $args);
     } else {
         throw new \RuntimeException("Attempted to call a non-existent proxy method on runtime collection: {$method}");
     }
 }
开发者ID:jimbojsb,项目名称:simple-asset,代码行数:9,代码来源:Manager.php

示例9: ReflectionObject

 function __call($method, $args)
 {
     $this_reflection = new ReflectionObject($this);
     if (in_array($method, $this->resource_methods) && $this_reflection->hasMethod("resource_{$method}")) {
         return call_user_func_array(array($this, "resource_{$method}"), $args);
     } else {
         throw new ShopifyResourceException("Method {$method} is unsupported for " . get_class($this));
     }
 }
开发者ID:rajtrivedi2001,项目名称:shopify-php,代码行数:9,代码来源:shopify_resource.php

示例10: hydrate

 /**
  * @param array $data
  * @param $object
  */
 public function hydrate(array $data, $object)
 {
     $reflection = new \ReflectionObject($object);
     foreach ($data as $name => $value) {
         $methodName = $this->getMethodName($name, self::METHOD_SETTER);
         if ($reflection->hasMethod($methodName)) {
             $reflection->getMethod($methodName)->invoke($object, $value);
         }
     }
 }
开发者ID:archdevil666pl,项目名称:common,代码行数:14,代码来源:Method.php

示例11: createObject

 protected function createObject(\FS\Components\Factory\ConfigurationInterface $configuration, $class)
 {
     $reflected = new \ReflectionObject($configuration);
     $targets = explode('\\', $class);
     $configurationMethod = 'get' . end($targets);
     if ($reflected->hasMethod($configurationMethod)) {
         return $configuration->{$configurationMethod}();
     }
     return new $class();
 }
开发者ID:flagshipcompany,项目名称:flagship-for-woocommerce,代码行数:10,代码来源:ComponentFactory.php

示例12: propose

 /**
  * Loads definitions and translations from provided context.
  *
  * @param ContextInterface $context
  * @param StepNode         $step
  *
  * @return DefinitionSnippet
  */
 public function propose(ContextInterface $context, StepNode $step)
 {
     $contextRefl = new \ReflectionObject($context);
     $contextClass = $contextRefl->getName();
     $replacePatterns = array("/(?<= |^)\\\\'(?:((?!\\').)*)\\\\'(?= |\$)/", '/(?<= |^)\\"(?:[^\\"]*)\\"(?= |$)/', '/(\\d+)/');
     $text = $step->getText();
     $text = preg_replace('/([\\/\\[\\]\\(\\)\\\\^\\$\\.\\|\\?\\*\\+\'])/', '\\\\$1', $text);
     $regex = preg_replace($replacePatterns, array("\\'([^\\']*)\\'", "\"([^\"]*)\"", "(\\d+)"), $text);
     preg_match('/' . $regex . '/', $step->getText(), $matches);
     $count = count($matches) - 1;
     $methodName = preg_replace($replacePatterns, '', $text);
     $methodName = Transliterator::transliterate($methodName, ' ');
     $methodName = preg_replace('/[^a-zA-Z\\_\\ ]/', '', $methodName);
     $methodName = str_replace(' ', '', ucwords($methodName));
     if (0 !== strlen($methodName)) {
         $methodName[0] = strtolower($methodName[0]);
     } else {
         $methodName = 'stepDefinition1';
     }
     // get method number from method name
     $methodNumber = 2;
     if (preg_match('/(\\d+)$/', $methodName, $matches)) {
         $methodNumber = intval($matches[1]);
     }
     // check that proposed method name isn't arelady defined in context
     while ($contextRefl->hasMethod($methodName)) {
         $methodName = preg_replace('/\\d+$/', '', $methodName);
         $methodName .= $methodNumber++;
     }
     // check that proposed method name haven't been proposed earlier
     if (isset(self::$proposedMethods[$contextClass])) {
         foreach (self::$proposedMethods[$contextClass] as $proposedRegex => $proposedMethod) {
             if ($proposedRegex !== $regex) {
                 while ($proposedMethod === $methodName) {
                     $methodName = preg_replace('/\\d+$/', '', $methodName);
                     $methodName .= $methodNumber++;
                 }
             }
         }
     }
     self::$proposedMethods[$contextClass][$regex] = $methodName;
     $args = array();
     for ($i = 0; $i < $count; $i++) {
         $args[] = "\$arg" . ($i + 1);
     }
     foreach ($step->getArguments() as $argument) {
         if ($argument instanceof PyStringNode) {
             $args[] = "PyStringNode \$string";
         } elseif ($argument instanceof TableNode) {
             $args[] = "TableNode \$table";
         }
     }
     $description = $this->generateSnippet($regex, $methodName, $args);
     return new DefinitionSnippet($step, $description);
 }
开发者ID:unkerror,项目名称:Budabot,代码行数:63,代码来源:AnnotatedDefinitionProposal.php

示例13: create

 /**
  * @param object $object
  * @param string $methodName
  *
  * @return \Donquixote\CallbackReflection\Callback\CallbackReflection_ObjectMethod
  */
 static function create($object, $methodName)
 {
     if (!is_object($object)) {
         throw new \InvalidArgumentException("First parameter must be an object.");
     }
     $reflObject = new \ReflectionObject($object);
     if (!$reflObject->hasMethod($methodName)) {
         throw new \InvalidArgumentException("Object has no such method.");
     }
     $reflMethod = $reflObject->getMethod($methodName);
     return new self($object, $reflMethod);
 }
开发者ID:donquixote,项目名称:callback-reflection,代码行数:18,代码来源:CallbackReflection_ObjectMethod.php

示例14: getChildController

 /**
  * Get the child controller object.
  *
  * Gets the new child controller object from the child controller class
  * method. If the method does not exist, or the returned value is not a
  * controller object, a \RuntimeException is thrown.
  *
  * @throws \RuntimeException
  * @param $controllerName
  * @return Controller
  */
 public function getChildController($controllerName)
 {
     $methodName = $this->parseControllerName($controllerName);
     if (!$this->reflection->hasMethod($methodName)) {
         throw new \RuntimeException("{$this->reflection->getName()}::{$methodName} does not exist");
     }
     $controller = $this->reflection->getMethod($methodName)->invokeArgs($this->controller, []);
     if (!is_object($controller) || !$controller instanceof Controller) {
         throw new \RuntimeException("{$this->reflection->getName()}::{$methodName} did not return a Controller");
     }
     return $controller;
 }
开发者ID:AyeAyeApi,项目名称:Api,代码行数:23,代码来源:ReflectionController.php

示例15: inject

 /**
  * Injects $dependency into property $name of $target
  *
  * This is a convenience method for setting a protected or private property in
  * a test subject for the purpose of injecting a dependency.
  *
  * @param object $target The instance which needs the dependency
  * @param string $name Name of the property to be injected
  * @param mixed $dependency The dependency to inject – usually an object but can also be any other type
  * @return void
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  */
 protected function inject($target, $name, $dependency)
 {
     if (!is_object($target)) {
         throw new \InvalidArgumentException('Wrong type for argument $target, must be object.');
     }
     $objectReflection = new \ReflectionObject($target);
     $methodNamePart = strtoupper($name[0]) . substr($name, 1);
     if ($objectReflection->hasMethod('set' . $methodNamePart)) {
         $methodName = 'set' . $methodNamePart;
         $target->{$methodName}($dependency);
     } elseif ($objectReflection->hasMethod('inject' . $methodNamePart)) {
         $methodName = 'inject' . $methodNamePart;
         $target->{$methodName}($dependency);
     } elseif ($objectReflection->hasProperty($name)) {
         $property = $objectReflection->getProperty($name);
         $property->setAccessible(true);
         $property->setValue($target, $dependency);
     } else {
         throw new \RuntimeException('Could not inject ' . $name . ' into object of type ' . get_class($target));
     }
 }
开发者ID:neos,项目名称:flow-development-collection,代码行数:34,代码来源:BaseTestCase.php


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