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; }
public function testObjectPropertiesGet() { $id = 1; $title = "title"; $password = "******"; $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."); }
/** * 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; }
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"); }
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; }
/** * @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; }
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."); }
/** * @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; }
/** * 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')); }
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)); }
/** * @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)); } }
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()); }
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)); }
/** * @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)); }
/** * 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; }
/** * Retrieves the base path from the CldrRepository's cldrBasePath attribute * @return string */ protected function retrieveCldrBasePath() { $reflectedCldrRepository = new \ReflectionObject($this->cldrRepository); $reflectedBasePathProperty = $reflectedCldrRepository->getProperty('cldrBasePath'); $reflectedBasePathProperty->setAccessible(true); return $reflectedBasePathProperty->getValue($this->cldrRepository); }
public function preFlush(PreFlushEventArgs $eventArgs) { $uow = $eventArgs->getEntityManager()->getUnitOfWork(); $insertions = $uow->getScheduledEntityInsertions(); $updates = $uow->getScheduledEntityUpdates(); $entities = array_merge($insertions, $updates); foreach ($entities as $entity) { $refl = new \ReflectionObject($entity); foreach ($refl->getProperties() as $prop) { /** @var TsVector $annot */ $annot = $this->reader->getPropertyAnnotation($prop, TsVector::class); if (is_null($annot)) { continue; } $fields = $annot->fields; $tsVectorVal = []; foreach ($fields as $field) { $field = $refl->getProperty($field); $field->setAccessible(true); $fieldValue = $field->getValue($entity); if (is_array($fieldValue)) { $fieldValue = implode(' ', $fieldValue); } $tsVectorVal[] = $fieldValue; } $prop->setAccessible(true); $value = ['data' => join(' ', $tsVectorVal), 'language' => $annot->language, 'weight' => $annot->weight]; $prop->setValue($entity, $value); } } }
/** * @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); }
/** * Getter for properties, regardless of the visibility * * @param string $propertyName the name of the property * @return mixed */ protected function getProperty($propertyName) { $reflectionObject = new \ReflectionObject($this->fixture); $reflectionProperty = $reflectionObject->getProperty($propertyName); $reflectionProperty->setAccessible(true); return $reflectionProperty->getValue($this->fixture); }
protected function getPropertyValue($object, $property) { $refl = new \ReflectionObject($object); $repoProp = $refl->getProperty($property); $repoProp->setAccessible(true); return $repoProp->getValue($object); }
/** * A utulity method ripped from the Monga\Query\Find tests for inspecting * the value of a Find object. * * @param string $property * @return mixed */ protected function getProperty($find, $property) { $reflection = new \ReflectionObject($find); $property = $reflection->getProperty($property); $property->setAccessible(true); return $property->getValue($find); }
/** * Serialize an event so that it can be stored in the database */ public function serialize() { $class = new \ReflectionObject($this); $params = $class->getConstructor()->getParameters(); $data = array(); // Iterate through all the parameters of the constructor foreach ($params as $param) { // Find the related class property $property = $class->getProperty($param->getName()); $property->setAccessible(true); $value = $property->getValue($this); // We just need to store IDs and types for models if ($value !== null && $this->isModel($param)) { if (!$param->getClass()->isAbstract()) { // The parameter is a non-abstract model, we can just // store its ID since the type will be known when // unserializing $value = $value->getId(); } else { // The parameter is an abstract model class, we need to // store the model's type as well $value = array('id' => $value->getId(), 'type' => get_class($value)); } } $data[$property->getName()] = $value; } return serialize($data); }
public function capture() { $shim = $this->getShim(); $event_manager = $shim->getApp(); if ($shim->isMage2()) { $shim->getObjectManager()->get('Magento\\Logger')->log('Work in ' . __FILE__); $shim->getObjectManager()->get('Magento\\Event\\Manager')->collectAllMage2(); return; } $r = new ReflectionObject($event_manager); $rp = $r->getProperty('_events'); if (method_exists($rp, 'setAccessible')) { $rp->setAccessible(true); $events = $rp->getValue($event_manager); } else { $events = $this->_phpFivePointTwoReflection($event_manager); } $collector = new Pzdgmailcom_Commercebug_Model_Collectorevents(); foreach ($events as $area => $event) { foreach ($event as $event_name => $configuration) { $o = new stdClass(); $o->area = $area; $o->event = $event_name; $o->data = array(); $collector->collectInformation($o); $collector->collectObservers($event_name, $configuration); } } }
protected function getRepoProperty($container) { $refl = new \ReflectionObject($container); $repoProp = $refl->getProperty('items'); $repoProp->setAccessible(true); return $repoProp->getValue($container); }
private function readRoutes($object) { $reflObj = new \ReflectionObject($object); $reflProp = $reflObj->getProperty('routes'); $reflProp->setAccessible(true); return $reflProp->getValue($object); }
private function expectCount($prop, $expected) { $ro = new \ReflectionObject($this->uow); $rp = $ro->getProperty($prop); $rp->setAccessible(true); $this->assertCount($expected, $rp->getValue($this->uow)); }
/** * {@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; }
/** * Retrieves a key from an Ably\Auth instance, which is * normally not accessible, via reflection. */ protected static function retrieveKeyFromAblyAuth($ablyAuth) { $authRefl = new ReflectionObject($ablyAuth); $optionsProperty = $authRefl->getProperty('defaultAuthOptions'); $optionsProperty->setAccessible(true); return $optionsProperty->getValue($ablyAuth)->key; }
/** * @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); }
/** * Ensures an authorization header is created correctly with an incorrectly-cased request method. */ public function testCaseInsensitiveRequestMethod() { $authId = 'efdde334-fe7b-11e4-a322-1697f925ec7b'; $authSecret = 'W5PeGMxSItNerkNFqQMfYiJvH14WzVJMy54CPoTAYoI='; $authKey = new Key($authId, $authSecret); $nonce = 'd1954337-5319-4821-8427-115542e08d10'; $headers = ['X-Authorization-Timestamp' => '1432075982', 'Content-Type' => 'application/json']; $request1 = new Request('GET', 'http://example.com', $headers); $builder1 = new AuthorizationHeaderBuilder($request1, $authKey); $builder1->setId($authId); $builder1->setNonce($nonce); $authHeader1 = $builder1->getAuthorizationHeader(); // Guzzle requests automatically normalize request methods on set, so // we need to manually set the property to an un-normalized method. $request2 = clone $request1; $refObject = new \ReflectionObject($request2); $refProperty = $refObject->getProperty('method'); $refProperty->setAccessible(true); $refProperty->setValue($request2, 'gEt'); $builder2 = new AuthorizationHeaderBuilder($request2, $authKey); $builder2->setId($authId); $builder2->setNonce($nonce); $authHeader2 = $builder2->getAuthorizationHeader(); $this->assertEquals((string) $authHeader1, (string) $authHeader2); }