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


PHP ReflectionProperty类代码示例

本文整理汇总了PHP中ReflectionProperty的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionProperty类的具体用法?PHP ReflectionProperty怎么用?PHP ReflectionProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $request = $event->getRequest();
     $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, 'format' => $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     try {
         $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     } catch (\Exception $e) {
         $this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
         $wrapper = $e;
         while ($prev = $wrapper->getPrevious()) {
             if ($exception === ($wrapper = $prev)) {
                 throw $e;
             }
         }
         $prev = new \ReflectionProperty('Exception', 'previous');
         $prev->setAccessible(true);
         $prev->setValue($wrapper, $exception);
         throw $e;
     }
     $event->setResponse($response);
 }
开发者ID:ccq18,项目名称:EduSoho,代码行数:25,代码来源:ExceptionListener.php

示例2: testValue

 /**
  * Test factory method
  */
 public function testValue()
 {
     $typecast = TypeCast::value('abc123');
     $refl = new \ReflectionProperty('Jasny\\TypeCast', 'value');
     $refl->setAccessible(true);
     $this->assertSame('abc123', $refl->getValue($typecast));
 }
开发者ID:jasny,项目名称:typecast,代码行数:10,代码来源:TypeCastTest.php

示例3: __call

 public function __call($name, $args)
 {
     $class = get_class($this);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class}' method without name.");
     }
     if (preg_match('#^on[A-Z]#', $name)) {
         $rp = new ReflectionProperty($class, $name);
         if ($rp->isPublic() && !$rp->isStatic()) {
             $list = $this->{$name};
             if (is_array($list) || $list instanceof Traversable) {
                 foreach ($list as $handler) {
                     if (is_object($handler)) {
                         call_user_func_array(array($handler, '__invoke'), $args);
                     } else {
                         call_user_func_array($handler, $args);
                     }
                 }
             }
             return NULL;
         }
     }
     if ($cb = self::extensionMethod("{$class}::{$name}")) {
         array_unshift($args, $this);
         return call_user_func_array($cb, $args);
     }
     throw new MemberAccessException("Call to undefined method {$class}::{$name}().");
 }
开发者ID:radimklaska,项目名称:Drupal.cz,代码行数:28,代码来源:texy.compact.5.php

示例4: _setConnectionOnInstaller

 /**
  * Force connection setter injection on setup model using reflection
  * 
  * @param $setup
  * @param $connection
  */
 protected function _setConnectionOnInstaller($setup, $connection)
 {
     $prop = new ReflectionProperty($setup, '_conn');
     $prop->setAccessible(true);
     $prop->setValue($setup, $connection);
     $prop->setAccessible(false);
 }
开发者ID:gewaechshaus,项目名称:groupscatalog2,代码行数:13,代码来源:SetupTest.php

示例5: testSetProperties

 /**
  * Test for ExportCodegen::setProperties
  *
  * @return void
  */
 public function testSetProperties()
 {
     $method = new ReflectionMethod('ExportCodegen', 'setProperties');
     $method->setAccessible(true);
     $method->invoke($this->object, null);
     $attrProperties = new ReflectionProperty('ExportCodegen', 'properties');
     $attrProperties->setAccessible(true);
     $properties = $attrProperties->getValue($this->object);
     $this->assertInstanceOf('ExportPluginProperties', $properties);
     $this->assertEquals('CodeGen', $properties->getText());
     $this->assertEquals('cs', $properties->getExtension());
     $this->assertEquals('text/cs', $properties->getMimeType());
     $this->assertEquals('Options', $properties->getOptionsText());
     $options = $properties->getOptions();
     $this->assertInstanceOf('OptionsPropertyRootGroup', $options);
     $this->assertEquals('Format Specific Options', $options->getName());
     $generalOptionsArray = $options->getProperties();
     $generalOptions = $generalOptionsArray[0];
     $this->assertInstanceOf('OptionsPropertyMainGroup', $generalOptions);
     $this->assertEquals('general_opts', $generalOptions->getName());
     $generalProperties = $generalOptions->getProperties();
     $hidden = $generalProperties[0];
     $this->assertInstanceOf('HiddenPropertyItem', $hidden);
     $this->assertEquals('structure_or_data', $hidden->getName());
     $select = $generalProperties[1];
     $this->assertInstanceOf('SelectPropertyItem', $select);
     $this->assertEquals('format', $select->getName());
     $this->assertEquals('Format:', $select->getText());
     $this->assertEquals(array("NHibernate C# DO", "NHibernate XML"), $select->getValues());
 }
开发者ID:kfjihailong,项目名称:phpMyAdmin,代码行数:35,代码来源:PMA_ExportCodegen_test.php

示例6: initialize

 public function initialize($object)
 {
     $reflectionClass = new ReflectionClass($object);
     $reader = new Phake_Annotation_Reader($reflectionClass);
     if ($this->useDoctrineParser()) {
         $parser = new \Doctrine\Common\Annotations\PhpParser();
     }
     $properties = $reader->getPropertiesWithAnnotation('Mock');
     foreach ($properties as $property) {
         $annotations = $reader->getPropertyAnnotations($property);
         if ($annotations['Mock'] !== true) {
             $mockedClass = $annotations['Mock'];
         } else {
             $mockedClass = $annotations['var'];
         }
         if (isset($parser)) {
             // Ignore it if the class start with a backslash
             if (substr($mockedClass, 0, 1) !== '\\') {
                 $useStatements = $parser->parseClass($reflectionClass);
                 $key = strtolower($mockedClass);
                 if (array_key_exists($key, $useStatements)) {
                     $mockedClass = $useStatements[$key];
                 }
             }
         }
         $reflProp = new ReflectionProperty(get_class($object), $property);
         $reflProp->setAccessible(true);
         $reflProp->setValue($object, Phake::mock($mockedClass));
     }
 }
开发者ID:eric-seekas,项目名称:Phake,代码行数:30,代码来源:MockInitializer.php

示例7: __construct

 /**
  * Constructor.
  *
  * @param RepositoryInterface $repository PathRepository object
  */
 public function __construct(RepositoryInterface $repository)
 {
     $reflection = new \ReflectionProperty(get_class($repository), 'url');
     $reflection->setAccessible(true);
     $this->url = $reflection->getValue($repository);
     #$repository->url;
 }
开发者ID:holisticagency,项目名称:satis-file-manager,代码行数:12,代码来源:SatisPathRepository.php

示例8: testIndex

    public function testIndex()
    {
        $logger = $this->getMock('Psr\\Log\\LoggerInterface');
        $logger->expects($this->once())->method('info');
        $controller = new Controller($logger);
        $prop = new \ReflectionProperty(__NAMESPACE__ . '\\Controller', 'response');
        $prop->setAccessible(true);
        $prop->setValue($controller, new \SS_HTTPResponse());
        $req = new \SS_HTTPRequest('GET', '/');
        $req->setBody(<<<JSON
{
  "csp-report": {
    "document-uri": "http://example.com/signup.html",
    "referrer": "",
    "blocked-uri": "http://example.com/css/style.css",
    "violated-directive": "style-src cdn.example.com",
    "original-policy": "default-src 'none'; style-src cdn.example.com; report-uri /_/csp-reports"
  }
}
JSON
);
        $response = $controller->index($req);
        $this->assertEquals(204, $response->getStatusCode());
        $this->assertEquals('', $response->getBody());
    }
开发者ID:helpfulrobot,项目名称:camspiers-silverstripe-csp-logging,代码行数:25,代码来源:ControllerTest.php

示例9: _initScalarProperties

 /**
  * Initialize list of scalar properties by response
  *
  * @param \SimpleXMLElement $apiResponse
  * @param array $properties
  * @throws \Exception
  */
 protected function _initScalarProperties($apiResponse, array $properties)
 {
     foreach ($properties as $property) {
         if (is_array($property)) {
             $classPropertyName = current($property);
             $value = $apiResponse->{key($property)};
         } else {
             $classPropertyName = $this->_underToCamel(str_replace('-', '_', $property));
             $value = $apiResponse->{$property};
         }
         $reflectionProperty = new \ReflectionProperty($this, $classPropertyName);
         $docBlock = $reflectionProperty->getDocComment();
         $propertyType = preg_replace('/^.+ @var ([a-z]+) .+$/', '\\1', $docBlock);
         if ('string' == $propertyType) {
             $value = (string) $value;
         } else {
             if ('integer' == $propertyType) {
                 $value = (int) $value;
             } else {
                 if ('boolean' == $propertyType) {
                     $value = in_array((string) $value, ['true', 'on', 'enabled']);
                 } else {
                     throw new \Exception("Unknown property type '{$propertyType}'.");
                 }
             }
         }
         $this->{$classPropertyName} = $value;
     }
 }
开发者ID:plesk,项目名称:api-php-lib,代码行数:36,代码来源:Struct.php

示例10: actionBucketList

 protected function actionBucketList(WURFL_Utils_CLI_Argument $arg)
 {
     $wurfl_service = new ReflectionProperty('WURFL_WURFLManager', '_wurflService');
     $wurfl_service->setAccessible(true);
     $service = $wurfl_service->getValue($this->wurfl);
     $wurfl_ua_chain = new ReflectionProperty('WURFL_WURFLService', '_userAgentHandlerChain');
     $wurfl_ua_chain->setAccessible(true);
     $ua_chain = $wurfl_ua_chain->getValue($service);
     echo 'PHP API v' . WURFL_Constants::API_VERSION . ' for ' . $this->wurfl->getWURFLInfo()->version . PHP_EOL;
     echo "Bucket\tDeviceId\tNormalizedUserAgent\tOriginaUserAgent" . PHP_EOL;
     $ordered_buckets = [];
     foreach ($ua_chain->getHandlers() as $userAgentHandler) {
         $ordered_buckets[$this->formatBucketName($userAgentHandler->getName())] = $userAgentHandler;
     }
     ksort($ordered_buckets);
     foreach ($ordered_buckets as $bucket => $userAgentHandler) {
         /**
          * @see WURFL_Handlers_Handler::getUserAgentsWithDeviceId()
          */
         $current = $userAgentHandler->getUserAgentsWithDeviceId();
         if ($current) {
             $sorted = array_flip($current);
             ksort($sorted);
             foreach ($sorted as $device_id => $normalized_ua) {
                 $device = $this->wurfl->getDevice($device_id);
                 echo $bucket . "\t" . $device_id . "\t" . $normalized_ua . "\t" . $device->userAgent . PHP_EOL;
             }
         } else {
             echo $bucket . "\t" . 'EMPTY' . "\t" . 'EMPTY' . "\t" . 'EMPTY' . PHP_EOL;
         }
     }
 }
开发者ID:acasademont,项目名称:wurfl,代码行数:32,代码来源:CLI.php

示例11: __construct

 public function __construct(InputInterface $input, OutputInterface $output)
 {
     parent::__construct($input, $output);
     $ref = new \ReflectionProperty(get_parent_class($this), 'lineLength');
     $ref->setAccessible(true);
     $ref->setValue($this, 120);
 }
开发者ID:christengc,项目名称:wheel,代码行数:7,代码来源:SymfonyStyleTest.php

示例12: getPropertyLine

 /**
  * @param \ReflectionProperty $property
  * @return int
  */
 public static function getPropertyLine(\ReflectionProperty $property)
 {
     $class = $property->getDeclaringClass();
     $context = 'file';
     $contextBrackets = 0;
     foreach (token_get_all(file_get_contents($class->getFileName())) as $token) {
         if ($token === '{') {
             $contextBrackets += 1;
         } elseif ($token === '}') {
             $contextBrackets -= 1;
         }
         if (!is_array($token)) {
             continue;
         }
         if ($token[0] === T_CLASS) {
             $context = 'class';
             $contextBrackets = 0;
         } elseif ($context === 'class' && $contextBrackets === 1 && $token[0] === T_VARIABLE) {
             if ($token[1] === '$' . $property->getName()) {
                 return $token[2];
             }
         }
     }
     return NULL;
 }
开发者ID:kdyby,项目名称:doctrine,代码行数:29,代码来源:Helpers.php

示例13: testCanReturnItemsToStock

 /**
  * @param bool $canReturnToStock
  * @param bool $manageStock
  * @param bool $result
  * @dataProvider canReturnItemsToStockDataProvider
  */
 public function testCanReturnItemsToStock($canReturnToStock, $manageStock, $result)
 {
     $productId = 7;
     $property = new \ReflectionProperty($this->items, '_canReturnToStock');
     $property->setAccessible(true);
     $this->assertNull($property->getValue($this->items));
     $this->stockConfiguration->expects($this->once())->method('canSubtractQty')->will($this->returnValue($canReturnToStock));
     if ($canReturnToStock) {
         $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup', 'getStore'], [], '', false);
         $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false);
         $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue(10));
         $orderItem->expects($this->any())->method('getStore')->will($this->returnValue($store));
         $orderItem->expects($this->once())->method('getProductId')->will($this->returnValue($productId));
         $creditMemoItem = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', ['setCanReturnToStock', 'getOrderItem', '__wakeup'], [], '', false);
         $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false);
         $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue([$creditMemoItem]));
         $creditMemoItem->expects($this->any())->method('getOrderItem')->will($this->returnValue($orderItem));
         $this->stockItemMock->expects($this->once())->method('getManageStock')->will($this->returnValue($manageStock));
         $creditMemoItem->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf());
         $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCanReturnToStock', '__wakeup'], [], '', false);
         $order->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf());
         $creditMemo->expects($this->once())->method('getOrder')->will($this->returnValue($order));
         $this->registryMock->expects($this->any())->method('registry')->with('current_creditmemo')->will($this->returnValue($creditMemo));
     }
     $this->assertSame($result, $this->items->canReturnItemsToStock());
     $this->assertSame($result, $property->getValue($this->items));
     // lazy load test
     $this->assertSame($result, $this->items->canReturnItemsToStock());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:35,代码来源:ItemsTest.php

示例14: openPresenter

 protected function openPresenter($fqa)
 {
     /** @var IntegrationTestCase|PresenterRunner $this */
     $sl = $this->getContainer();
     //insert fake HTTP Request for Presenter - for presenter->link() etc.
     $params = $sl->getParameters();
     $this->fakeUrl = new Nette\Http\UrlScript(isset($params['console']['url']) ? $params['console']['url'] : 'localhost');
     $sl->removeService('httpRequest');
     $sl->addService('httpRequest', new HttpRequest($this->fakeUrl, NULL, [], [], [], [], PHP_SAPI, '127.0.0.1', '127.0.0.1'));
     /** @var Nette\Application\IPresenterFactory $presenterFactory */
     $presenterFactory = $sl->getByType('Nette\\Application\\IPresenterFactory');
     $name = substr($fqa, 0, $namePos = strrpos($fqa, ':'));
     $class = $presenterFactory->getPresenterClass($name);
     if (!class_exists($overriddenPresenter = 'DamejidloTests\\' . $class)) {
         $classPos = strrpos($class, '\\');
         eval('namespace DamejidloTests\\' . substr($class, 0, $classPos) . '; class ' . substr($class, $classPos + 1) . ' extends \\' . $class . ' { ' . 'protected function startup() { if ($this->getParameter("__terminate") == TRUE) { $this->terminate(); } parent::startup(); } ' . 'public static function getReflection() { return parent::getReflection()->getParentClass(); } ' . '}');
     }
     $this->presenter = $sl->createInstance($overriddenPresenter);
     $sl->callInjects($this->presenter);
     $app = $this->getService('Nette\\Application\\Application');
     $appRefl = new \ReflectionProperty($app, 'presenter');
     $appRefl->setAccessible(TRUE);
     $appRefl->setValue($app, $this->presenter);
     $this->presenter->autoCanonicalize = FALSE;
     $this->presenter->run(new Nette\Application\Request($name, 'GET', ['action' => substr($fqa, $namePos + 1) ?: 'default', '__terminate' => TRUE]));
 }
开发者ID:kdyby,项目名称:tester-extras,代码行数:26,代码来源:PresenterRunner.php

示例15: __construct

 /**
  * @param \ReflectionProperty $accessedProperty
  * @param string              $nameSuffix
  */
 public function __construct(\ReflectionProperty $accessedProperty, $nameSuffix)
 {
     $this->accessedProperty = $accessedProperty;
     $originalName = $accessedProperty->getName();
     $name = UniqueIdentifierGenerator::getIdentifier($originalName . $nameSuffix);
     parent::__construct(Class_::MODIFIER_PRIVATE, [new PropertyProperty($name)]);
 }
开发者ID:indigophp,项目名称:hydra,代码行数:11,代码来源:PropertyAccessor.php


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