当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionMethod::invoke方法代码示例

本文整理汇总了PHP中ReflectionMethod::invoke方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::invoke方法的具体用法?PHP ReflectionMethod::invoke怎么用?PHP ReflectionMethod::invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionMethod的用法示例。


在下文中一共展示了ReflectionMethod::invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testOptionMethods

 public function testOptionMethods()
 {
     $item = new Item();
     $rmSetProduct = new \ReflectionMethod($item, 'setProduct');
     $rmSetProduct->setAccessible(true);
     $this->assertNull($item->getOption('noOption'));
     $rmSetOptions = new \ReflectionMethod($item, 'setOptions');
     $rmSetOptions->setAccessible(true);
     $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate()));
     $rmSetOptions->invoke($item, array('option2' => 2, 'option3' => 3));
     $options = $item->getOptions();
     $this->assertCount(2, $options);
     $this->assertArrayHasKey('option2', $options);
     $this->assertArrayHasKey('option3', $options);
     $rmClearOptions = new \ReflectionMethod($item, 'clearOptions');
     $rmClearOptions->setAccessible(true);
     $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate(false)));
     $this->setExpectedException('Vespolina\\Exception\\InvalidOptionsException');
     $rmClearOptions->invoke($item);
     $this->assertSame($options, $item->getOptions(), 'nothing should have been removed if the validation fails');
     $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate()));
     $rmClearOptions->invoke($item);
     $this->assertEmpty($item->getOptions());
     $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate(false)));
     $this->setExpectedException('Vespolina\\Exception\\InvalidOptionsException');
     $rmSetOptions->invokeArgs($item, array('failure' => 0));
     $this->assertEmpty($item->getOptions(), 'nothing should be added if the validation fails');
 }
开发者ID:vespolina,项目名称:core,代码行数:28,代码来源:ItemTest.php

示例2: testTrackPageView

    public function testTrackPageView()
    {
        $viewer = CMTest_TH::createUser();
        $environment = new CM_Frontend_Environment(CM_Site_Abstract::factory(), $viewer);
        $client = new CMService_AdWords_Client();
        $pushConversion = new ReflectionMethod($client, '_pushConversion');
        $pushConversion->setAccessible(true);
        $pushConversion->invoke($client, $viewer, CMService_AdWords_Conversion::fromJson('{"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}}'));
        $pushConversion->invoke($client, $viewer, CMService_AdWords_Conversion::fromJson('{"google_conversion_id":789}'));
        $this->assertSame('', $client->getJs());
        $this->assertSame(<<<EOD
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script>
EOD
, $client->getHtml($environment));
        $client->trackPageView($environment, '/');
        $this->assertSame(<<<EOD
window.google_trackConversion({"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}});window.google_trackConversion({"google_conversion_id":789});
EOD
, $client->getJs());
        $this->assertSame(<<<EOD
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script><script type="text/javascript">
/* <![CDATA[ */
window.google_trackConversion({"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}});window.google_trackConversion({"google_conversion_id":789});
//]]>
</script>
EOD
, $client->getHtml($environment));
    }
开发者ID:cargomedia,项目名称:cm,代码行数:28,代码来源:ClientTest.php

示例3: 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

示例4: _invoke

 private function _invoke($clz = '', $act = '', $param, $namespace = 'Home\\Controller\\')
 {
     $clz = ucwords($clz);
     $clz_name = $namespace . $clz . 'Controller';
     try {
         $ref_clz = new \ReflectionClass($clz_name);
         if ($ref_clz->hasMethod($act)) {
             $ref_fun = new \ReflectionMethod($clz_name, $act);
             if ($ref_fun->isPrivate() || $ref_fun->isProtected()) {
                 $ref_fun->setAccessible(true);
             }
             if ($ref_fun->isStatic()) {
                 $ref_fun->invoke(null);
             } else {
                 $ref_fun_par = $ref_fun->getParameters();
                 if (!empty($param) && is_array($param)) {
                     if (is_array($ref_fun_par) && count($ref_fun_par) == count($param)) {
                         $ref_fun->invokeArgs(new $clz_name(), $param);
                     } else {
                         $ref_fun->invoke(new $clz_name());
                     }
                 } else {
                     $ref_fun->invoke(new $clz_name());
                 }
             }
         }
     } catch (\LogicException $le) {
         $this->ajaxReturn(array('status' => '500', 'info' => '服务器内部发生严重错误'));
     } catch (\ReflectionException $re) {
         $this->ajaxReturn(array('status' => '404', 'info' => '访问' . $clz . '控制器下的非法操作', 'data' => array('code' => $re->getCode())));
     }
 }
开发者ID:AInotamm,项目名称:Welcome2015,代码行数:32,代码来源:ApiController.class.php

示例5: testRetrievesAndCachesTargetData

 public function testRetrievesAndCachesTargetData()
 {
     $ctime = strtotime('January 1, 2013');
     $a = $this->getMockBuilder('SplFileinfo')->setMethods(array('getSize', 'getMTime', '__toString'))->disableOriginalConstructor()->getMock();
     $a->expects($this->any())->method('getSize')->will($this->returnValue(10));
     $a->expects($this->any())->method('getMTime')->will($this->returnValue($ctime));
     $a->expects($this->any())->method('__toString')->will($this->returnValue(''));
     $b = $this->getMockBuilder('SplFileinfo')->setMethods(array('getSize', 'getMTime', '__toString'))->disableOriginalConstructor()->getMock();
     $b->expects($this->any())->method('getSize')->will($this->returnValue(11));
     $b->expects($this->any())->method('getMTime')->will($this->returnValue($ctime));
     $a->expects($this->any())->method('__toString')->will($this->returnValue(''));
     $c = 0;
     $converter = $this->getMockBuilder('Aws\\S3\\Sync\\KeyConverter')->setMethods(array('convert'))->getMock();
     $converter->expects($this->any())->method('convert')->will($this->returnCallback(function () use(&$c) {
         if (++$c == 1) {
             return 'foo';
         } else {
             return 'bar';
         }
     }));
     $targetIterator = new \ArrayIterator(array($b, $a));
     $targetIterator->rewind();
     $changed = new ChangedFilesIterator($targetIterator, $targetIterator, $converter, $converter);
     $ref = new \ReflectionMethod($changed, 'getTargetData');
     $ref->setAccessible(true);
     $this->assertEquals(array(10, $ctime), $ref->invoke($changed, 'bar'));
     $this->assertEquals(array(11, $ctime), $ref->invoke($changed, 'foo'));
     $this->assertFalse($ref->invoke($changed, 'baz'));
 }
开发者ID:im286er,项目名称:ent,代码行数:29,代码来源:ChangedFilesIteratorTest.php

示例6: 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

示例7: testExtractParams

 /**
  * Test extractParams().
  */
 public function testExtractParams()
 {
     $method = new \ReflectionMethod('Social\\Connection', 'extractParams');
     $method->setAccessible(true);
     $this->assertEquals(array(), $method->invoke(null, 'http://www.example.com'));
     $this->assertEquals(array('foo' => 'bar', 'fox' => 'dog'), $method->invoke(null, 'http://www.example.com?foo=bar&fox=dog'));
 }
开发者ID:jasny,项目名称:social,代码行数:10,代码来源:ConnectionTest.php

示例8: testRelativeURLs

 public function testRelativeURLs()
 {
     $hrefIsRelativeMethod = new ReflectionMethod('NavigationScraperService', 'hrefIsRelative');
     $hrefIsRelativeMethod->setAccessible(true);
     $service = new NavigationScraperService();
     $this->assertTrue($hrefIsRelativeMethod->invoke($service, '/blah'));
     $this->assertTrue($hrefIsRelativeMethod->invoke($service, 'blah/something'));
 }
开发者ID:helpfulrobot,项目名称:deptinternalaffairsnz-silverstripe-navigation-scraper,代码行数:8,代码来源:HrefIsRelativeTest.php

示例9: call

 /**
  * Call a class reference method with set parameters.
  * @param $classInstance instantiated class name
  */
 public function call($classInstance)
 {
     if (isset($this->parameters)) {
         $this->method->invokeArgs($classInstance, $this->parameters);
     } else {
         $this->method->invoke($classInstance);
     }
 }
开发者ID:radekstepan,项目名称:Clubhouse,代码行数:12,代码来源:ApplicationReflection.php

示例10: testEscape

 public function testEscape()
 {
     $method = new ReflectionMethod($this->feed, 'escape');
     $method->setAccessible(true);
     $this->assertEquals('&amp;', $method->invoke($this->feed, '&'));
     $this->assertEquals('&quot;', $method->invoke($this->feed, '"'));
     $this->assertEquals('&lt;br&gt;', $method->invoke($this->feed, '<br>'));
 }
开发者ID:a11enwong,项目名称:pochika,代码行数:8,代码来源:FeedTest.php

示例11: testParseOptions

 /**
  * @dataProvider dpParseOptions
  */
 public function testParseOptions(array $arguments, array $expected)
 {
     /** @var \Delusion\Suggestible $input */
     $input = new ArgvInput();
     Configurator::setCustomBehavior($input, 'getOption', $arguments);
     $this->method->invoke(self::$launcher, $input);
     $this->assertSame($expected, $this->params->all());
 }
开发者ID:komex,项目名称:unteist,代码行数:11,代码来源:LauncherOverwriteParamsTest.php

示例12: testGetUniversalDomainName

 public function testGetUniversalDomainName()
 {
     $reflector = new ReflectionMethod('\\T4\\Http\\Helpers', 'getUniversalDomainName');
     $reflector->setAccessible(true);
     $this->assertEquals('', $reflector->invoke(null, 'localhost'));
     $this->assertEquals('.mail.ru', $reflector->invoke(null, 'www.mail.ru'));
     $this->assertEquals('.mail.ru', $reflector->invoke(null, 'mail.ru'));
 }
开发者ID:pr-of-it,项目名称:t4,代码行数:8,代码来源:HttpHelpersTest.php

示例13: testGetTimestampReturnsConsistentTimestamp

 /**
  * @covers Aws\Common\Signature\AbstractSignature::getTimestamp
  */
 public function testGetTimestampReturnsConsistentTimestamp()
 {
     $signature = $this->getMockBuilder('Aws\\Common\\Signature\\AbstractSignature')->getMockForAbstractClass();
     $method = new \ReflectionMethod('Aws\\Common\\Signature\\AbstractSignature', 'getTimestamp');
     $method->setAccessible(true);
     // Ensure that the timestamp is the same when cached
     $t = $method->invoke($signature);
     $this->assertEquals($t, $method->invoke($signature));
 }
开发者ID:njbhatt18,项目名称:Amazon_API,代码行数:12,代码来源:AbstractSignatureTest.php

示例14: test_create_speaker_return_speaker

 public function test_create_speaker_return_speaker()
 {
     $method = new ReflectionMethod(get_class($this->speaker_seeker), 'create_speaker');
     $method->setAccessible(true);
     $speaker_mock = $method->invoke($this->speaker_seeker, 'Speaker_Mock');
     $this->assertTrue($speaker_mock instanceof Speaker_Mock);
     $speaker_mock = $method->invoke($this->speaker_seeker, 'Dummy_Speaker_Mock');
     $this->assertNull($speaker_mock);
 }
开发者ID:torounit,项目名称:hello-kushimoto,代码行数:9,代码来源:test-hello-kushimoto-speaker-seeker.php

示例15: test_parse_color_pairs

 /**
  * Test the private color parsing function. Combined colors.
  *
  * @depends test_class_defined
  */
 public function test_parse_color_pairs()
 {
     $m = new \ReflectionMethod("ansi", "parse_color");
     $m->setAccessible(true);
     $this->assertEquals(0x700, $m->invoke("ansi", "black_in_white"));
     $this->assertEquals(0x1710, $m->invoke("ansi", "Black_in_White"));
     $this->assertEquals(0x417, $m->invoke("ansi", "White_on_blue"));
     $this->assertEquals(0x117, $m->invoke("ansi", "White_on_red"));
 }
开发者ID:twoixter,项目名称:ansicolors,代码行数:14,代码来源:AnsiTest.php


注:本文中的ReflectionMethod::invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。