本文整理汇总了PHP中ReflectionObject::getProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject::getProperty方法的具体用法?PHP ReflectionObject::getProperty怎么用?PHP ReflectionObject::getProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionObject
的用法示例。
在下文中一共展示了ReflectionObject::getProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start
public function start($keyName, $lifetime = null)
{
static $reflector;
if (!$this->_backend->getFrontend() instanceof Output) {
return null;
}
if (!$reflector) {
$reflector = new \ReflectionObject($this->_backend);
}
$existingCache = $this->get($keyName, $lifetime);
if ($existingCache === null) {
$fresh = true;
$this->_backend->getFrontend()->start();
} else {
$fresh = false;
}
$_fresh = $reflector->getProperty('_fresh');
$_fresh->setAccessible(true);
$_fresh->setValue($this->_backend, $fresh);
$_started = $reflector->getProperty('_started');
$_started->setAccessible(true);
$_started->setValue($this->_backend, true);
/**
* Update the last lifetime to be used in save()
*/
if ($lifetime !== null) {
$_lastLifetime = $reflector->getProperty('_lastLifetime');
$_lastLifetime->setAccessible(true);
$_lastLifetime->setValue($this->_backend, $lifetime);
}
return $existingCache;
}
示例2: testObjectPropertiesGet
public function testObjectPropertiesGet()
{
$id = 1;
$title = "title";
$password = "test";
$userlimit = 12;
$queueid = 1;
$room = new Room();
$refRoom = new \ReflectionObject($room);
$idProp = $refRoom->getProperty('_id');
$idProp->setAccessible(true);
$idProp->setValue($room, $id);
$titleProp = $refRoom->getProperty('_title');
$titleProp->setAccessible(true);
$titleProp->setValue($room, $title);
$passwordProp = $refRoom->getProperty('_password');
$passwordProp->setAccessible(true);
$passwordProp->setValue($room, $password);
$userlimitProp = $refRoom->getProperty('_userlimit');
$userlimitProp->setAccessible(true);
$userlimitProp->setValue($room, $userlimit);
$queueIdProp = $refRoom->getProperty('_queueid');
$queueIdProp->setAccessible(true);
$queueIdProp->setValue($room, $queueid);
$this->assertEquals($id, $room->getId(), "ID not properly returned by Room getter method.");
$this->assertEquals($title, $room->getTitle(), "Title not properly returned by Room getter method.");
$this->assertEquals($password, $room->getPassword(), "Password not properly returned by Room getter method.");
$this->assertEquals($userlimit, $room->getUserLimit(), "Thumbsup not properly returned by Room getter method.");
$this->assertEquals($queueid, $room->getQueueId(), "Queue ID not properly returned by Room getter method.");
}
示例3: map
/**
* Map data to Video object and return it.
*
* @param array $data
*
* @throws \Exception
*
* @return Video
*/
public function map(array $data)
{
$video = new Video();
$reflection = new \ReflectionObject($video);
$mappers = array_keys($this->mappers);
foreach ($data as $key => $value) {
try {
$prop = $reflection->getProperty($this->snakeToCamel($key));
$prop->setAccessible(true);
} catch (\ReflectionException $e) {
continue;
}
if (in_array($key, $mappers)) {
$mapper = __NAMESPACE__ . '\\' . $this->mappers[$key];
if (!in_array(__NAMESPACE__ . '\\MapperInterface', class_implements($mapper))) {
throw new \Exception($mapper . ' must implement mapper interface.');
}
/**
* @var MapperInterface $mapperObj
*/
$mapperObj = new $mapper();
$prop->setValue($video, $mapperObj->map($value));
} else {
$prop->setValue($video, $value);
}
}
$file = $reflection->getProperty('file');
$file->setAccessible(true);
$file->setValue($video, new \SplFileInfo(rtrim($this->downloadPath, '/') . '/' . $video->getFilename()));
return $video;
}
示例4: testCustomHandler
public function testCustomHandler()
{
$handler = \Jenner\Crontab\Logger\MissionLoggerFactory::getHandler("custom://CustomHandler?param_1=param_1¶m_2=param_2");
$this->assertInstanceOf("Monolog\\Handler\\HandlerInterface", $handler);
$reflect = new ReflectionObject($handler);
$this->assertEquals($reflect->getProperty("param_1")->getValue($handler), "param_1");
$this->assertEquals($reflect->getProperty("param_2")->getValue($handler), "param_2");
}
示例5: setMyPropertie
public function setMyPropertie($object = null)
{
if (null === $this->_meta_self_reflection) {
$this->_meta_self_reflection = new \ReflectionObject($this);
}
$this->freeze = false;
if (is_array($object) || is_object($object)) {
// $access = \\Symfony\Component\PropertyAccess\PropertyAccess::getPropertyAccessor() ;
foreach ($object as $property => $value) {
if (null === $value) {
continue;
}
$set = 'set_' . $property;
try {
if (method_exists($this, $set)) {
if ($this->{$set}($value)) {
$this->throwError("%s already seted", $property);
}
} else {
if (!$this->_meta_self_reflection->hasProperty($property)) {
$this->throwError("%s not exists", $property);
}
$_set = 'set' . $this->camelize($property);
if (method_exists($this, $_set)) {
throw new \Exception(sprintf("%s->%s method %s should change to %s", $this->getMeteTypeName(), $property, $_set, $set));
}
if (0 === strpos($property, '_')) {
$this->throwError("%s is private property", $property);
}
$_property = $this->_meta_self_reflection->getProperty($property);
if ($_property->isStatic()) {
$this->throwError("%s is static property", $property);
}
if ($_property->isPrivate()) {
$this->throwError("%s is private property", $property);
}
/*
$_property->setAccessible( true ) ;
$_property->setValue( $this, $value ) ;
*/
$this->{$property} = $value;
}
$this->_annot_properties[$property] = true;
} catch (\Symforce\AdminBundle\Compiler\MetaType\Exception $e) {
if ($this instanceof \Symforce\AdminBundle\Compiler\MetaType\DoctrineType || $this instanceof \Symforce\AdminBundle\Compiler\MetaType\DoctrineProperty) {
$this->throwPropertyError($property, $e->getMessage());
} else {
throw $e;
}
}
}
} else {
if (!empty($object)) {
throw new \Exception(sprintf("%s can not setValue(%s)", $this->getClassName(), $value));
}
}
$this->freeze = true;
}
示例6: hydrate
/**
* @param array $data
*
* @return RepresentsEntity
*/
public function hydrate(array $data)
{
$entity = clone $this->prototypeEntity;
foreach ($data as $propertyName => $propertyValue) {
$property = $this->reflectionObject->getProperty($propertyName);
$property->setAccessible(true);
$property->setValue($entity, $this->castingBehavior->castValue($property, $propertyValue));
}
return $entity;
}
示例7: testObjectPropertiesGet
public function testObjectPropertiesGet()
{
$id = 1;
$title = "title";
$link = "test";
$thumbsup = 12;
$thumbsdown = 4;
$channelid = "ueoueoueohtn13";
$channeltitle = "channes tieont";
$thumbnail = "ueaunehtoaunht";
$description = "euohtnsuhetaoutnehnoaueohtauhtneoaunhteoanht\r\n\t\tueouhtenoauhteoa\r\n\t\tueaohueoa\r\n\t\theuaoueoaueohtnauhtneoau\r\n\t\teoauhteoauhtneonhtaunehto\r\n\t\tauhteaouehtnoauneoahtnueona\r\n\t\tuehtaouhteoahuneohauhneoahtn";
$duration = 123213;
$video = new MediaItem();
$refMediaItem = new \ReflectionObject($video);
$idProp = $refMediaItem->getProperty('_id');
$idProp->setAccessible(true);
$idProp->setValue($video, $id);
$titleProp = $refMediaItem->getProperty('_title');
$titleProp->setAccessible(true);
$titleProp->setValue($video, $title);
$linkProp = $refMediaItem->getProperty('_link');
$linkProp->setAccessible(true);
$linkProp->setValue($video, $link);
$thumbsupProp = $refMediaItem->getProperty('_thumbsup');
$thumbsupProp->setAccessible(true);
$thumbsupProp->setValue($video, $thumbsup);
$thumbsdownProp = $refMediaItem->getProperty('_thumbsdown');
$thumbsdownProp->setAccessible(true);
$thumbsdownProp->setValue($video, $thumbsdown);
$channelidProp = $refMediaItem->getProperty('_channelid');
$channelidProp->setAccessible(true);
$channelidProp->setValue($video, $channelid);
$channeltitleProp = $refMediaItem->getProperty('_channeltitle');
$channeltitleProp->setAccessible(true);
$channeltitleProp->setValue($video, $channeltitle);
$thumbnailProp = $refMediaItem->getProperty('_thumbnail');
$thumbnailProp->setAccessible(true);
$thumbnailProp->setValue($video, $thumbnail);
$descriptionProp = $refMediaItem->getProperty('_description');
$descriptionProp->setAccessible(true);
$descriptionProp->setValue($video, $description);
$durationProp = $refMediaItem->getProperty('_duration');
$durationProp->setAccessible(true);
$durationProp->setValue($video, $duration);
$this->assertEquals($id, $video->getId(), "ID not properly returned by MediaItem getter method.");
$this->assertEquals($title, $video->getTitle(), "Title not properly returned by MediaItem getter method.");
$this->assertEquals($link, $video->getLink(), "Link not properly returned by MediaItem getter method.");
$this->assertEquals($thumbsup, $video->getThumbsUp(), "Thumbsup not properly returned by MediaItem getter method.");
$this->assertEquals($thumbsdown, $video->getThumbsDown(), "Thumbsdown not properly returned by MediaItem getter method.");
$this->assertEquals($channelid, $video->getChannelId(), "Channel ID not properly returned by MediaItem getter method.");
$this->assertEquals($channeltitle, $video->getChannelTitle(), "Channel title not properly returned by MediaItem getter method.");
$this->assertEquals($thumbnail, $video->getThumbnail(), "Thumbnail not properly returned by MediaItem getter method.");
$this->assertEquals($description, $video->getDescription(), "Description not properly returned by MediaItem getter method.");
$this->assertEquals($duration, $video->getDuration(), "Duration not properly returned by MediaItem getter method.");
}
示例8: findProperty
/**
* @param \ReflectionObject $reflectionObject
* @param string $key
* @return null|\ReflectionProperty
*/
private static function findProperty(\ReflectionObject $reflectionObject, $key)
{
if ($reflectionObject->hasProperty($key)) {
return $reflectionObject->getProperty($key);
}
$camelized = lcfirst(join(array_map('ucfirst', explode('_', $key))));
if ($reflectionObject->hasProperty($camelized)) {
return $reflectionObject->getProperty($camelized);
}
return null;
}
示例9: setConfig
/**
* Test minifier import configuration methods.
*
* @test
*/
public function setConfig()
{
$this->minifier->setMaxImportSize(10);
$this->minifier->setImportExtensions(array('gif' => 'data:image/gif'));
$object = new ReflectionObject($this->minifier);
$property = $object->getProperty('maxImportSize');
$property->setAccessible(true);
$this->assertEquals($property->getValue($this->minifier), 10);
$property = $object->getProperty('importExtensions');
$property->setAccessible(true);
$this->assertEquals($property->getValue($this->minifier), array('gif' => 'data:image/gif'));
}
示例10: testConstructAndOptions
public function testConstructAndOptions()
{
$fakeOptions = ['scriptRootPath' => 'fake/root', 'fileExtension' => 'fake.php'];
$tmpObject = new View($fakeOptions);
$rObject = new \ReflectionObject($tmpObject);
$prop = $rObject->getProperty('scriptRootPath');
$prop->setAccessible(true);
$this->assertEquals($fakeOptions['scriptRootPath'], $prop->getValue($tmpObject));
$prop = $rObject->getProperty('fileExtension');
$prop->setAccessible(true);
$this->assertEquals($fakeOptions['fileExtension'], $prop->getValue($tmpObject));
}
示例11: testGetRedisObject
/**
* @see \Endeveit\Cache\Drivers\Redis::getRedisObject()
*/
public function testGetRedisObject()
{
$method = self::$driverReflection->getMethod('getRedisObject');
$method->setAccessible(true);
$property = self::$driverReflection->getProperty('connectionsOptions');
$property->setAccessible(true);
$options = $property->getValue(self::$driver);
$this->assertCount(2, $options);
foreach (array_keys($options) as $key) {
$this->assertInstanceOf('Redis', $method->invoke(self::$driver, $key));
}
}
示例12: testShouldReturnTheSameTimeDifference
public function testShouldReturnTheSameTimeDifference()
{
$benchmark = new Benchmark();
$reflectObject = new \ReflectionObject($benchmark);
$benchmark->start();
$startedAtProperty = $reflectObject->getProperty('startedAt');
$startedAtProperty->setAccessible(true);
$this->assertInternalType('float', $startedAtProperty->getValue($benchmark));
$benchmark->finish();
$finishedAtProperty = $reflectObject->getProperty('finishedAt');
$finishedAtProperty->setAccessible(true);
$this->assertInternalType('float', $finishedAtProperty->getValue($benchmark));
$this->assertSame($finishedAtProperty->getValue($benchmark) - $startedAtProperty->getValue($benchmark), $benchmark->getGenerationTime());
}
示例13: testCreateBinary
public function testCreateBinary()
{
$condition = new Condition('12 < 13');
$reflector = new \ReflectionObject($condition);
$x = $reflector->getProperty('x');
$x->setAccessible(true);
$this->assertEquals('12', $x->getValue($condition));
$operator = $reflector->getProperty('operator');
$operator->setAccessible(true);
$this->assertEquals('<', $operator->getValue($condition));
$y = $reflector->getProperty('y');
$y->setAccessible(true);
$this->assertEquals('13', $y->getValue($condition));
}
示例14: testConstruct
/**
* @covers \Moaction\Jsonrpc\Common\Error::__construct
* @dataProvider providerTestConstruct
*/
public function testConstruct($errorCode, $errorMessage, $errorData, $expectedCode)
{
$error = new Error($errorCode, $errorMessage, $errorData);
$object = new \ReflectionObject($error);
$code = $object->getProperty('code');
$code->setAccessible(true);
$this->assertEquals($expectedCode, $code->getValue($error));
$message = $object->getProperty('message');
$message->setAccessible(true);
$this->assertEquals($errorMessage, $message->getValue($error));
$data = $object->getProperty('data');
$data->setAccessible(true);
$this->assertEquals($errorData, $data->getValue($error));
}
示例15: getErrorExceptionMock
/**
* Get a modified ErrorException object that is mocked with the required properties.
*
* @param string $message
* @param string $file
* @param integer $line
* @param array $trace
*
* @return \ErrorException
*/
private function getErrorExceptionMock($message, $file, $line, array $trace = array())
{
$exception = new \ErrorException($message);
$reflection = new \ReflectionObject($exception);
$fileProperty = $reflection->getProperty('file');
$fileProperty->setAccessible(true);
$fileProperty->setValue($exception, $file);
$lineProperty = $reflection->getProperty('line');
$lineProperty->setAccessible(true);
$lineProperty->setValue($exception, $line);
$traceProperty = $reflection->getParentClass()->getProperty('trace');
$traceProperty->setAccessible(true);
$traceProperty->setValue($exception, $trace);
return $exception;
}