本文整理汇总了PHP中ReflectionObject类的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject类的具体用法?PHP ReflectionObject怎么用?PHP ReflectionObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReflectionObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:exildev,项目名称:corvus,代码行数:32,代码来源:View.php
示例2: getPropertyValue
protected function getPropertyValue($object, $property)
{
$refl = new \ReflectionObject($object);
$repoProp = $refl->getProperty($property);
$repoProp->setAccessible(true);
return $repoProp->getValue($object);
}
开发者ID:xpressengine,项目名称:xpressengine,代码行数:7,代码来源:AdvisorCollectionTest.php
示例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);
}
开发者ID:zhangxiaoliu,项目名称:PHPPdf,代码行数:7,代码来源:TestCase.php
示例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);
}
开发者ID:tankist,项目名称:codeception-profiler,代码行数:12,代码来源:Unit.php
示例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);
}
}
开发者ID:Dren-x,项目名称:mobit,代码行数:32,代码来源:TemplateListener.php
示例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.");
}
}
开发者ID:jave007,项目名称:test,代码行数:33,代码来源:TestCase.php
示例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;
}
开发者ID:TeknooSoftware,项目名称:states-life-cycle,代码行数:31,代码来源:Assertion.php
示例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;
}
开发者ID:RomLAURENT,项目名称:Jar2Fer,代码行数:29,代码来源:api.php
示例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);
}
开发者ID:pmill,项目名称:doctrine-array-hydrator,代码行数:12,代码来源:TestCase.php
示例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));
}
开发者ID:usefulthink,项目名称:symfony,代码行数:25,代码来源:ClientTest.php
示例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));
}
开发者ID:hyperlator,项目名称:Sismo,代码行数:26,代码来源:CrossFingerNotifierTest.php
示例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());
}
开发者ID:dezvell,项目名称:mm.local,代码行数:10,代码来源:SingletonTest.php
示例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;
}
开发者ID:KelvinVenancio,项目名称:php-telegram-bot,代码行数:25,代码来源:Entity.php
示例14: readRoutes
private function readRoutes($object)
{
$reflObj = new \ReflectionObject($object);
$reflProp = $reflObj->getProperty('routes');
$reflProp->setAccessible(true);
return $reflProp->getValue($object);
}
开发者ID:yannisrichard,项目名称:uframework,代码行数:7,代码来源:AppTest.php
示例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');
}
开发者ID:robcolburn,项目名称:mpx-php,代码行数:10,代码来源:FeedMediaClientTest.php
示例16: checkAPI
/**
* Defines all required functions and constants
*
* @see _define()
* @return void
*/
public function checkAPI()
{
// The constants are defined.
$this->_define('T_NAMESPACE');
$this->_define('T_NS_SEPARATOR');
$this->_define('E_USER_DEPRECATED', E_USER_WARNING);
/*
* Every static public method with an @implement annotation defines
* a function.
*/
$reflectionObject = new ReflectionObject($this);
$methods = $reflectionObject->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
// The method comment is parsed for the @implement annotation
$isAnnotated = preg_match('/\\s*\\*\\s*@implement\\s+(\\S+)/', $method->getDocComment(), $matches);
if (!$isAnnotated) {
continue;
}
$function = $matches[1];
// A function might already exist.
if (function_exists($function)) {
continue;
}
// The parameters are build.
$parametersArray = array();
for ($i = 0; $i < $method->getNumberOfParameters(); $i++) {
$parametersArray[] = '$parameter' . $i;
}
$parameters = implode(', ', $parametersArray);
// The function is defined.
$apiClass = get_class($this);
$definition = "function {$function}({$parameters})\n {\n \$parameters = func_get_args();\n return call_user_func_array(\n array('{$apiClass}', '{$method->getName()}'),\n \$parameters\n );\n }\n ";
eval($definition);
}
}
开发者ID:xxdf,项目名称:showtimes,代码行数:41,代码来源:OldPHPAPI.php
示例17: testNoConstructor
public function testNoConstructor()
{
$obj = Singleton::getInstance();
$refl = new \ReflectionObject($obj);
$meth = $refl->getMethod('__construct');
$this->assertTrue($meth->isPrivate());
}
开发者ID:xtrasmal,项目名称:DesignPatternsPHP,代码行数:7,代码来源:SingletonTest.php
示例18: getRepoProperty
protected function getRepoProperty($container)
{
$refl = new \ReflectionObject($container);
$repoProp = $refl->getProperty('items');
$repoProp->setAccessible(true);
return $repoProp->getValue($container);
}
开发者ID:qkrcjfgus33,项目名称:xpressengine,代码行数:7,代码来源:ContainerTest.php
示例19: get_eids
static function get_eids($search_term, $prop_id, $type_id, $search_compare_op = 0)
{
$prop_name = Property::static_get_table_name($prop_id);
$vptepte_class_name = "view_" . $prop_name . "_to_e_p_to_e";
// include_once (dirname(__FILE__) .'/../PropertyTypeEntity/'.$vptepte_class_name.'.php');
$theclass = new $vptepte_class_name();
$reflObject = new ReflectionObject($theclass);
$reflMethod = $reflObject->getMethod("get_eids");
$reflParameters = $reflMethod->getParameters();
$args = array();
foreach ($reflParameters as $param) {
//$paramName = $param->getName();
//$args[$param->getPosition()] = $paramName;
$args[$param->getPosition()] = func_get_arg($param->getPosition());
//this way view_int_prop... will be passed the fourth argument.
//Note: assumes get_eids signature matches order between here and the vptepte's
}
$eids = array();
if (!$type_id) {
$type_hash = MixedQueries::get_type_list();
foreach ($type_hash as $_type_id => $type_name) {
//$eids = array_merge($eids, $theclass->get_eids($search_term, $prop_id, $_type_id));
$args[2] = $_type_id;
$eids = array_merge($eids, $reflMethod->invokeArgs($theclass, $args));
}
} else {
//$eids = $theclass->get_eids($search_term, $prop_id, $type_id);
$eids = $reflMethod->invokeArgs($theclass, $args);
}
return $eids;
}
开发者ID:awgtek,项目名称:myedb,代码行数:31,代码来源:MixedQueries.php
示例20: load
/**
* @param AdminInterface $admin
*
* @return mixed
* @throws \RuntimeException
*/
public function load(AdminInterface $admin)
{
$filename = $this->cacheFolder . '/route_' . md5($admin->getCode());
$cache = new ConfigCache($filename, $this->debug);
if (!$cache->isFresh()) {
$resources = array();
$routes = array();
$reflection = new \ReflectionObject($admin);
$resources[] = new FileResource($reflection->getFileName());
if (!$admin->getRoutes()) {
throw new \RuntimeException('Invalid data type, Admin::getRoutes must return a RouteCollection');
}
foreach ($admin->getRoutes()->getElements() as $code => $route) {
$routes[$code] = $route->getDefault('_sonata_name');
}
if (!is_array($admin->getExtensions())) {
throw new \RuntimeException('extensions must be an array');
}
foreach ($admin->getExtensions() as $extension) {
$reflection = new \ReflectionObject($extension);
$resources[] = new FileResource($reflection->getFileName());
}
$cache->write(serialize($routes), $resources);
}
return unserialize(file_get_contents($filename));
}
开发者ID:kwuerl,项目名称:SonataAdminBundle,代码行数:32,代码来源:RoutesCache.php
注:本文中的ReflectionObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论