本文整理汇总了PHP中ReflectionMethod类的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod类的具体用法?PHP ReflectionMethod怎么用?PHP ReflectionMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReflectionMethod类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: format_controller_methods
private function format_controller_methods($path, $file)
{
$this->load->helper("url");
$controller = array();
// only show php files
if (($extension = substr($file, strrpos($file, ".") + 1)) == "php") {
// include the class
include_once $path . "/" . $file;
$parts = explode(".", $file);
$class_lower = $parts["0"];
$class = ucfirst($class_lower);
// check if a class actually exists
if (class_exists($class) and get_parent_class($class) == "MY_Controller") {
// get a list of all methods
$controller["name"] = $class;
$controller["path"] = base_url() . $class_lower;
$controller["methods"] = array();
// get a list of all public methods
foreach (get_class_methods($class) as $method) {
$reflect = new ReflectionMethod($class, $method);
if ($reflect->isPublic()) {
// ignore some methods
$object = new $class();
if (!in_array($method, $object->internal_methods)) {
$method_array = array();
$method_array["name"] = $method;
$method_array["path"] = base_url() . $class_lower . "/" . $method;
$controller["methods"][] = $method_array;
}
}
}
}
}
return $controller;
}
开发者ID:MaizerGomes,项目名称:api,代码行数:35,代码来源:contents.php
示例17: validate
/**
* {@inheritdoc}
*/
public function validate($object, Constraint $constraint)
{
if (!$constraint instanceof Callback) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Callback');
}
$method = $constraint->callback;
if ($method instanceof \Closure) {
$method($object, $this->context, $constraint->payload);
} elseif (is_array($method)) {
if (!is_callable($method)) {
if (isset($method[0]) && is_object($method[0])) {
$method[0] = get_class($method[0]);
}
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
}
call_user_func($method, $object, $this->context, $constraint->payload);
} elseif (null !== $object) {
if (!method_exists($object, $method)) {
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
}
$reflMethod = new \ReflectionMethod($object, $method);
if ($reflMethod->isStatic()) {
$reflMethod->invoke(null, $object, $this->context, $constraint->payload);
} else {
$reflMethod->invoke($object, $this->context, $constraint->payload);
}
}
}
开发者ID:Ener-Getick,项目名称:symfony,代码行数:31,代码来源:CallbackValidator.php
示例18: testBuildSelector
/**
* @covers ::buildSelector
*/
public function testBuildSelector()
{
$this->stringTranslation->expects($this->any())->method('translate')->willReturnArgument(0);
$method = new \ReflectionMethod($this->sut, 'buildSelector');
$method->setAccessible(TRUE);
$plugin_id = $this->randomMachineName();
$plugin_label = $this->randomMachineName();
$plugin_definition = $this->getMock(PluginLabelDefinitionInterface::class);
$plugin_definition->expects($this->atLeastOnce())->method('getLabel')->willReturn($plugin_label);
$plugin = $this->getMock(PluginInspectionInterface::class);
$plugin->expects($this->atLeastOnce())->method('getPluginDefinition')->willReturn($plugin_definition);
$plugin->expects($this->atLeastOnce())->method('getPluginId')->willReturn($plugin_id);
$this->selectablePluginType->expects($this->atLeastOnce())->method('ensureTypedPluginDefinition')->willReturnArgument(0);
$this->sut->setSelectedPlugin($plugin);
$selector_title = $this->randomMachineName();
$this->sut->setLabel($selector_title);
$selector_description = $this->randomMachineName();
$this->sut->setDescription($selector_description);
$element = array('#parents' => array('foo', 'bar'), '#title' => $selector_title);
$form_state = $this->getMock(FormStateInterface::class);
$available_plugins = array($plugin);
$expected_build_plugin_id = array('#ajax' => array('callback' => array(Radios::class, 'ajaxRebuildForm'), 'effect' => 'fade', 'event' => 'change', 'progress' => 'none', 'trigger_as' => array('name' => 'foo[bar][select][container][change]')), '#attached' => ['library' => ['plugin/plugin_selector.plugin_radios']], '#default_value' => $plugin_id, '#empty_value' => 'select', '#options' => array($plugin_id => $plugin_label), '#required' => FALSE, '#title' => $selector_title, '#description' => $selector_description, '#type' => 'radios');
$expected_build_change = array('#ajax' => array('callback' => array(AdvancedPluginSelectorBase::class, 'ajaxRebuildForm')), '#attributes' => array('class' => array('js-hide')), '#limit_validation_errors' => array(array('foo', 'bar', 'select', 'plugin_id')), '#name' => 'foo[bar][select][container][change]', '#submit' => [[AdvancedPluginSelectorBase::class, 'rebuildForm']], '#type' => 'submit', '#value' => 'Choose');
$build = $method->invokeArgs($this->sut, array($element, $form_state, $available_plugins));
$this->assertEquals($expected_build_plugin_id, $build['container']['plugin_id']);
$this->assertEquals($expected_build_change, $build['container']['change']);
$this->assertSame('container', $build['container']['#type']);
}
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:31,代码来源:RadiosTest.php
示例19: bindActionParams
/**
* Binds the parameters to the action.
* This method is invoked by [[\yii\base\Action]] when it begins to run with the given parameters.
* This method will check the parameter names that the action requires and return
* the provided parameters according to the requirement. If there is any missing parameter,
* an exception will be thrown.
* @param \yii\base\Action $action the action to be bound with parameters
* @param array $params the parameters to be bound to the action
* @return array the valid parameters that the action can run with.
* @throws HttpException if there are missing or invalid parameters.
*/
public function bindActionParams($action, $params)
{
if ($action instanceof InlineAction) {
$method = new \ReflectionMethod($this, $action->actionMethod);
} else {
$method = new \ReflectionMethod($action, 'run');
}
$args = [];
$missing = [];
$actionParams = [];
foreach ($method->getParameters() as $param) {
$name = $param->getName();
if (array_key_exists($name, $params)) {
if ($param->isArray()) {
$args[] = $actionParams[$name] = is_array($params[$name]) ? $params[$name] : [$params[$name]];
} elseif (!is_array($params[$name])) {
$args[] = $actionParams[$name] = $params[$name];
} else {
throw new BadRequestHttpException(Yii::t('yii', 'Invalid data received for parameter "{param}".', ['param' => $name]));
}
unset($params[$name]);
} elseif ($param->isDefaultValueAvailable()) {
$args[] = $actionParams[$name] = $param->getDefaultValue();
} else {
$missing[] = $name;
}
}
if (!empty($missing)) {
throw new BadRequestHttpException(Yii::t('yii', 'Missing required parameters: {params}', ['params' => implode(', ', $missing)]));
}
$this->actionParams = $actionParams;
return $args;
}
开发者ID:sanggabee,项目名称:hellomedia-yii-basic,代码行数:44,代码来源:Controller.php
示例20: __construct
public function __construct($argv)
{
$this->verbose = $this->verbose == true ? true : false;
$argv[] = '-clean';
$argv[] = '';
$this->args = $argv;
// get the systems username and set the home dir.
$this->user = get_current_user();
$this->home = '/home/' . $this->user . '/';
foreach ($this->args as $location => $args) {
$chars = str_split($args);
if ($chars[0] === '-') {
$tmp = explode('-', $args);
$function = end($tmp);
unset($tmp);
// this does a check to make sure we can only
// run public functions via this constructor.
$check = new ReflectionMethod($this, $function);
if (!$check->isPublic()) {
continue;
}
$this->{$function}($argv[++$location]);
}
}
}
开发者ID:ErdMutter92,项目名称:linux-file-sweaper,代码行数:25,代码来源:main.php
注:本文中的ReflectionMethod类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论