addProperty() public method

Adds (defines) a specific property and its type.
public addProperty ( string $name, string $type, boolean $lazy = false, boolean $transient = false ) : void
$name string Name of the property
$type string Type of the property
$lazy boolean Whether the property should be lazy-loaded when reconstituting
$transient boolean Whether the property should not be considered for persistence
return void
Exemplo n.º 1
0
 /**
  * @param ClassSchema $classSchema
  * @param string $propertyName
  * @return boolean
  * @throws InvalidPropertyTypeException
  * @throws \InvalidArgumentException
  */
 protected function evaluateClassPropertyAnnotationsForSchema(ClassSchema $classSchema, $propertyName)
 {
     $skipArtificialIdentity = false;
     $className = $classSchema->getClassName();
     if ($this->isPropertyAnnotatedWith($className, $propertyName, Flow\Transient::class)) {
         return false;
     }
     if ($this->isPropertyAnnotatedWith($className, $propertyName, Flow\Inject::class)) {
         return false;
     }
     if (!$this->isPropertyTaggedWith($className, $propertyName, 'var')) {
         return false;
     }
     $varTagValues = $this->getPropertyTagValues($className, $propertyName, 'var');
     if (count($varTagValues) > 1) {
         throw new InvalidPropertyTypeException('More than one @var annotation given for "' . $className . '::$' . $propertyName . '"', 1367334366);
     }
     $declaredType = strtok(trim(current($varTagValues), " \n\t"), " \n\t");
     try {
         TypeHandling::parseType($declaredType);
     } catch (InvalidTypeException $exception) {
         throw new \InvalidArgumentException(sprintf($exception->getMessage(), 'class "' . $className . '" for property "' . $propertyName . '"'), 1315564475);
     }
     if ($this->isPropertyAnnotatedWith($className, $propertyName, ORM\Id::class)) {
         $skipArtificialIdentity = true;
     }
     $classSchema->addProperty($propertyName, $declaredType, $this->isPropertyAnnotatedWith($className, $propertyName, Flow\Lazy::class), $this->isPropertyAnnotatedWith($className, $propertyName, Flow\Transient::class));
     if ($this->isPropertyAnnotatedWith($className, $propertyName, Flow\Identity::class)) {
         $classSchema->markAsIdentityProperty($propertyName);
     }
     return $skipArtificialIdentity;
 }
 /**
  * @test
  */
 public function mapSplObjectStorageCreatesSplObjectStorage()
 {
     $objectData = [['value' => ['mappedObject1']], ['value' => ['mappedObject2']]];
     $classSchema = new ClassSchema('TYPO3\\Post');
     $classSchema->addProperty('firstProperty', 'SplObjectStorage');
     $dataMapper = $this->getAccessibleMock(Persistence\Generic\DataMapper::class, ['mapToObject']);
     $dataMapper->expects($this->at(0))->method('mapToObject')->with($objectData[0]['value'])->will($this->returnValue(new \stdClass()));
     $dataMapper->expects($this->at(1))->method('mapToObject')->with($objectData[1]['value'])->will($this->returnValue(new \stdClass()));
     $dataMapper->_call('mapSplObjectStorage', $objectData);
 }
 /**
  * @test
  * @dataProvider collectionTypes
  * @param string $type
  */
 public function isMultiValuedPropertyReturnsTrueForCollectionTypes($type)
 {
     $classSchema = new ClassSchema('SomeClass');
     $classSchema->addProperty('testProperty', $type);
     $this->assertTrue($classSchema->isMultiValuedProperty('testProperty'));
 }