本文整理汇总了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);
}
}
}
}
示例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));
}
示例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;
}
示例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));
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例10: __construct
public function __construct(\ReflectionMethod $method)
{
$this->_method = $method;
$comment = $method->getDocComment();
$comment = new DocBloc($comment);
$this->_annotations = $comment->getAnnotations();
}
示例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;
}
示例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();
}
示例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);
}
示例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));
}
示例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;
}