本文整理汇总了PHP中ReflectionObject类的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject类的具体用法?PHP ReflectionObject怎么用?PHP ReflectionObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReflectionObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setForm
public function setForm(Form &$form, array $request)
{
$errors = array();
$form->befor_set();
$reflex = new ReflectionObject($form);
$propts = $reflex->getParentClass()->getProperties();
foreach ($propts as $propt) {
$name = $propt->getName();
$exis = method_exists($form, self::VALIDATE . $name);
$value = isset($request[$name]) ? $request[$name] : null;
$valid = self::VALIDATE . $name;
$setvl = self::SET_METHOD . ucfirst($name);
$respn = $exis ? $form->{$valid}($value) : true;
if ($respn === true) {
if (method_exists($form, $setvl)) {
if ($value != null) {
$form->{$setvl}($value);
}
} else {
if ($value != null) {
$propt->setAccessible(true);
$propt->setValue($form, $value);
$propt->setAccessible(false);
}
}
} else {
$errors[$name] = $respn;
}
}
$form->after_set();
return count($errors) > 0 ? $errors : true;
}
示例2: getPropertyValue
protected function getPropertyValue($object, $property)
{
$refl = new \ReflectionObject($object);
$repoProp = $refl->getProperty($property);
$repoProp->setAccessible(true);
return $repoProp->getValue($object);
}
示例3: invokeMethod
public function invokeMethod($object, $methodName, array $args = array())
{
$refObject = new \ReflectionObject($object);
$method = $refObject->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $args);
}
示例4: setProtectedProperty
/**
* @param object $object
* @param string $propertyName
* @param mixed $propertyValue
*/
public function setProtectedProperty($object, $propertyName, $propertyValue)
{
$class = new \ReflectionObject($object);
$property = $class->getProperty($propertyName);
$property->setAccessible(true);
$property->setValue($object, $propertyValue);
}
示例5: onKernelController
/**
* Guesses the template name to render and its variables and adds them to
* the request object.
*
* @param FilterControllerEvent $event A FilterControllerEvent instance
*/
public function onKernelController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
}
$request = $event->getRequest();
if (!($configuration = $request->attributes->get('_template'))) {
return;
}
if (!$configuration->getTemplate()) {
$guesser = $this->container->get('sensio_framework_extra.view.guesser');
$configuration->setTemplate($guesser->guessTemplateName($controller, $request, $configuration->getEngine()));
}
$request->attributes->set('_template', $configuration->getTemplate());
$request->attributes->set('_template_vars', $configuration->getVars());
$request->attributes->set('_template_streamable', $configuration->isStreamable());
// all controller method arguments
if (!$configuration->getVars()) {
$r = new \ReflectionObject($controller[0]);
$vars = array();
foreach ($r->getMethod($controller[1])->getParameters() as $param) {
$vars[] = $param->getName();
}
$request->attributes->set('_template_default_vars', $vars);
}
}
示例6: run
/**
* Runs the test case.
* @return void
*/
public function run($method = NULL)
{
$r = new \ReflectionObject($this);
$methods = array_values(preg_grep(self::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm) {
return $rm->getName();
}, $r->getMethods())));
if (substr($method, 0, 2) === '--') {
// back compatibility
$method = NULL;
}
if ($method === NULL && isset($_SERVER['argv']) && ($tmp = preg_filter('#(--method=)?([\\w-]+)$#Ai', '$2', $_SERVER['argv']))) {
$method = reset($tmp);
if ($method === self::LIST_METHODS) {
Environment::$checkAssertions = FALSE;
header('Content-Type: text/plain');
echo '[' . implode(',', $methods) . ']';
return;
}
}
if ($method === NULL) {
foreach ($methods as $method) {
$this->runMethod($method);
}
} elseif (in_array($method, $methods, TRUE)) {
$this->runMethod($method);
} else {
throw new TestCaseException("Method '{$method}' does not exist or it is not a testing method.");
}
}
示例7: isValid
/**
* {@inheritdoc}
*/
public function isValid(ProxyInterface $proxy) : bool
{
$asserted = true;
$reflectionObject = new \ReflectionObject($proxy);
//Browse properties assertion
foreach ($this->propertiesAssertions as $property => $exceptedValue) {
if (null !== $exceptedValue && \property_exists($proxy, $property)) {
//If the property exists, get it's value via the Reflection api (properties are often not accessible for public)
$reflectionProperty = $reflectionObject->getProperty($property);
$reflectionProperty->setAccessible(true);
$propertyValue = $reflectionProperty->getValue($proxy);
if (!\is_callable($exceptedValue)) {
//Not a callable, perform a equal test
$asserted &= $exceptedValue == $propertyValue;
} else {
$asserted &= $exceptedValue($propertyValue);
}
} else {
//If the property does not existn the assertion fail
$asserted = false;
}
if (!$asserted) {
//Stop at first fail
break;
}
}
return $asserted;
}
示例8: execute
public static function execute($commande, $params)
{
session_start();
$endpoint=new static();
$commande = "API_".$commande;
$endpointReflx = new ReflectionObject($endpoint);
$methodReflx = $endpointReflx->getMethod($commande);
try{
$result =$methodReflx->invokeArgs($endpoint, $params);
$result = [
'status'=>'success',
'value'=>$result
];
}
catch(ErrorException $ex)
{
$result = [
'status'=>'error',
'value'=>$ex->getMessage()
];
}
session_commit();
return $result;
}
示例9: setProtectedValue
/**
* @param $object
* @param $propertyName
* @param $value
*/
protected function setProtectedValue(&$object, $propertyName, $value)
{
$reflectionObject = new \ReflectionObject($object);
$property = $reflectionObject->getProperty($propertyName);
$property->setAccessible(true);
$property->setValue($object, $value);
}
示例10: testFilterResponseConvertsCookies
public function testFilterResponseConvertsCookies()
{
$client = new Client(new TestHttpKernel());
$r = new \ReflectionObject($client);
$m = $r->getMethod('filterResponse');
$m->setAccessible(true);
$expected = array(
'foo=bar; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly',
'foo1=bar1; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly'
);
$response = new Response();
$response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$domResponse = $m->invoke($client, $response);
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
$response = new Response();
$response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$response->headers->setCookie(new Cookie('foo1', 'bar1', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$domResponse = $m->invoke($client, $response);
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
$this->assertEquals($expected, $domResponse->getHeader('Set-Cookie', false));
}
示例11: testCommitNeedNotification
public function testCommitNeedNotification()
{
$notifier = $this->getMock('Sismo\\Contrib\\CrossFingerNotifier');
$r = new \ReflectionObject($notifier);
$m = $r->getMethod('commitNeedNotification');
$m->setAccessible(true);
$project = new Project('Twig');
$commit = new Commit($project, '123456');
$commit->setAuthor('Fabien');
$commit->setMessage('Foo');
$commit2 = new Commit($project, '123455');
$commit2->setAuthor('Fabien');
$commit2->setMessage('Bar');
$commit2->setStatusCode('success');
$commit3 = clone $commit2;
//a failed commit should be notified
$this->assertTrue($m->invoke($notifier, $commit));
//a successful commit without predecessor should be notified
$this->assertTrue($m->invoke($notifier, $commit2));
$project->setCommits(array($commit3));
//a successful commit with a successful predecessor should NOT be notified
$this->assertFalse($m->invoke($notifier, $commit2));
$project->setCommits(array($commit2, $commit3));
//a failed commit with a successful predecessor should be notified
$this->assertTrue($m->invoke($notifier, $commit));
}
示例12: testProtectedMethods
/**
* Test Clone
*/
public function testProtectedMethods()
{
$result = ConcreteSingleton::getInstance();
$reflection = new \ReflectionObject($result);
$this->assertTrue($reflection->getMethod('__construct')->isProtected());
$this->assertTrue($reflection->getMethod('__clone')->isProtected());
}
示例13: reflect
public function reflect($object)
{
$reflection = new \ReflectionObject($object);
$properties = $reflection->getProperties();
$fields = [];
foreach ($properties as $property) {
$name = $property->getName();
if ($name == 'bot_name') {
continue;
}
if (!$property->isPrivate()) {
if (is_object($object->{$name})) {
$fields[$name] = $this->reflect($object->{$name});
} else {
$property->setAccessible(true);
$value = $property->getValue($object);
if (is_null($value)) {
continue;
}
$fields[$name] = $value;
}
}
}
return $fields;
}
示例14: readRoutes
private function readRoutes($object)
{
$reflObj = new \ReflectionObject($object);
$reflProp = $reflObj->getProperty('routes');
$reflProp->setAccessible(true);
return $reflProp->getValue($object);
}
示例15: testBuildPath
/**
* Test build path.
*/
public function testBuildPath()
{
$reflection_object = new \ReflectionObject($this->client);
$reflection_method = $reflection_object->getMethod('buildPath');
$reflection_method->setAccessible(TRUE);
$this->assertEquals($reflection_method->invoke($this->client), 'HNK2IC/F_jM8Zls30dL/guid/-/2849493');
}