當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ReflectionObject類代碼示例

本文整理匯總了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;
 }
開發者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


注:本文中的ReflectionObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。