本文整理汇总了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();
}
}
示例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);
}
}
示例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}();
}
示例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);
}
}
}
}
示例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);
}
示例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;
}
示例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');
}
}
示例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}");
}
}
示例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));
}
}
示例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);
}
}
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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));
}
}