/**
  * @return \Twig_Function|\Twig_SimpleFunction
  */
 public function getNativeInstance()
 {
     if (Inspect::useClass('\\Twig_Function')->isAbstract()) {
         return new \Twig_SimpleFunction($this->name, $this->callable, $this->options->toArray());
     }
     return new \Twig_Function($this->name, $this->callable, $this->options->toArray());
 }
 /**
  * @param string $data
  */
 public function unserialize($data)
 {
     $properties = (array) Serializer::create(Serializer::TYPE_IGBINARY)->unserialize($data);
     foreach ($properties as $name => $value) {
         Inspect::this($this)->getProperty($name)->setValue($this, $value);
     }
 }
 /**
  * @param mixed $style
  */
 public function __construct($style)
 {
     $this->style = $style;
     $this->input = $style->getInput();
     $this->output = $style->getOutput();
     $this->inspect = Inspect::thisInstance($style);
 }
 /**
  * @param string $method
  * @param string $class
  *
  * @return bool|\Closure
  */
 private static function isValidMethod($method, $class)
 {
     $inspect = Inspect::thisClass($class);
     if ($inspect->hasMethod($method) && $inspect->getMethod($method)->visibilityPublic()) {
         return true;
     }
     return function () use($method, $class) {
         Context::get()->getOutput()->writeln(sprintf('[WARNING] Request task "%s::%s" could not be found.', $class, $method));
     };
 }
 public function testSetAndGetAndClearFilters()
 {
     $callable = function () {
         return 'test-callable';
     };
     $extension = new TwigExtension();
     $extension->addFilter('test', $callable);
     if (Inspect::useClass('\\Twig_Filter')->isAbstract()) {
         $this->assertInstanceOf('\\Twig_SimpleFilter', $extension->getFilters()[0]);
     } else {
         $this->assertInstanceOf('\\Twig_Filter', $extension->getFilters()[0]);
     }
     $extension->clearFilters();
     $this->assertCount(0, $extension->getFilters());
 }
 public function testLongWordsBlockWrapping()
 {
     $word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
     $wordLength = strlen($word);
     $style = $this->getStyle();
     $inspect = Inspect::this($style);
     $property = $inspect->getProperty('lineLengthMax');
     $maxLineLength = $property->value($style) - 3;
     $this->command->setCode(function (InputInterface $input, OutputInterface $output) use($word) {
         $sfStyle = new StyleWithForcedLineLength($input, $output);
         $sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
     });
     $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
     $expectedCount = (int) ceil($wordLength / $maxLineLength) + (int) ($wordLength > $maxLineLength - 5);
     $this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § '));
 }
 public function testInitializeMethods()
 {
     $className = 'SR\\Doctrine\\ORM\\Mapping\\Tests\\Fixture\\IdEntity';
     $instance = new $className(false);
     $this->assertNull($instance->getAString());
     $this->assertNull($instance->getAnInt());
     $this->assertNull($instance->getAnArray());
     $instance->__construct(true);
     $this->assertNotNull($instance->getAString());
     $this->assertSame('aString', $instance->getAString());
     $this->assertNotNull($instance->getAnInt());
     $this->assertNotNull($instance->getAnArray());
     $aStringProperty = Inspect::thisInstance($instance)->matchOneProperty('aString', 'nameUnQualified');
     $aStringProperty->setValue($instance, 'aStringValueSetViaReflection');
     $instance->__construct();
     $this->assertSame('aStringValueSetViaReflection', $instance->getAString());
 }
 /**
  * @param Entity $compareTo
  *
  * @return bool
  */
 public final function isEqualTo(Entity $compareTo)
 {
     $propertiesSelfNorm = [];
     $propertiesCompNorm = [];
     $propertiesSelf = Inspect::thisInstance($this)->properties();
     $propertiesComp = Inspect::thisInstance($compareTo)->properties();
     $visitor = function (array $properties, array &$normalized, $bind) {
         foreach ($properties as $property) {
             $normalized[$property->name()] = $property->value($bind);
         }
     };
     $visitor($propertiesSelf, $propertiesSelfNorm, $this);
     $visitor($propertiesComp, $propertiesCompNorm, $compareTo);
     ksort($propertiesSelfNorm);
     ksort($propertiesCompNorm);
     return $propertiesSelfNorm === $propertiesCompNorm;
 }
 /**
  * @return \SR\Reflection\Inspector\ConstantInspector[]
  */
 private function getLogLevelConstants()
 {
     return Inspect::useInstance($this)->constants();
 }
 /**
  * @param string      $search
  * @param null|Entity $entity
  *
  * @return null|PropertyIntrospection
  */
 protected final function findProperty($search, Entity $entity = null)
 {
     $_ = function (PropertyIntrospection $p, $index) use($search) {
         return $p->nameUnQualified() === $search;
     };
     return Inspect::thisInstance($entity ?: $this)->filterOneProperty($_, null);
 }
 public function testBindTo()
 {
     $object = FixtureClassOne::class;
     $method = Inspect::useClass($object, $fixture = new FixtureClassOne());
     $result = $method->visitConstants(function (ConstantInspector $const) use($object) {
         return $this->protectedOne0($const->value()) . '---' . $const->name();
     });
     $this->assertGreaterThan(3, $result);
     foreach ($result as $r) {
         $this->assertNotFalse(strpos($r, 'propProtectedOne0') !== false);
         $this->assertNotFalse(strpos($r, 'ONE_') !== false || strpos($r, 'NULL_') !== false);
     }
 }
Example #12
0
 /**
  * Validate the requested object instance or class name exists.
  *
  * @param string|object $object The object instance or class name
  * @param bool          $static Whether this is a static call or not
  *
  * @internal
  *
  * @throws BadFunctionCallException
  *
  * @return string|object
  */
 private static function validateClass($object, $static)
 {
     try {
         $class = Inspect::using($object)->nameQualified();
     } catch (\Exception $e) {
         throw BadFunctionCallException::create()->setMessage('Could not validate call class (got "%s" with message "%s").', var_export($object, true), $e->getMessage());
     }
     return $static ? $class : $object;
 }
 public function testFindPropertySet()
 {
     $class = 'SR\\Doctrine\\ORM\\Mapping\\Tests\\Fixture\\EntityA';
     $instance = new $class();
     $findPropertySetMethod = Inspect::thisInstance($instance)->getMethod('findPropertySet');
     $properties = $findPropertySetMethod->invoke($instance, '{^property}', true);
     $this->assertCount(3, $properties);
 }
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject $entity
  * @param string                                   $initializeMethod
  */
 private function initializerCall(\PHPUnit_Framework_MockObject_MockObject $entity, $initializeMethod)
 {
     $inspector = Inspect::thisInstance($entity);
     try {
         $method = $inspector->getMethod($initializeMethod);
     } catch (InvalidArgumentException $e) {
         $initializeMethod = $initializeMethod;
         $method = $inspector->getMethod($initializeMethod);
     }
     $method->invoke($entity);
 }
 /**
  * The attendants are designated their "type" using the class names of the respective object. Although
  * fully-qualified names can be (and are) used, this implementation does take the assuption that the
  * base names of the implementations does not overlap.
  *
  * @param bool $qualified
  *
  * @return string
  */
 public function getType($qualified = false)
 {
     return Inspect::useInstance($this)->name($qualified);
 }
 /**
  * @param bool        $qualified
  * @param null|object $instance
  *
  * @return string
  */
 public final function getParentName($qualified = false, $instance = null)
 {
     return Inspect::this(get_parent_class($instance))->name($qualified);
 }