| @@ 12-69 (lines=58) @@ | ||
| 9 | use LaravelDoctrine\Fluent\Builders\Field; |
|
| 10 | use LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadata; |
|
| 11 | ||
| 12 | class TreeLeft implements Buildable |
|
| 13 | { |
|
| 14 | const MACRO_METHOD = 'treeLeft'; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @var ExtensibleClassMetadata |
|
| 18 | */ |
|
| 19 | protected $classMetadata; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @var string |
|
| 23 | */ |
|
| 24 | protected $fieldName; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @param ExtensibleClassMetadata $classMetadata |
|
| 28 | * @param string $fieldName |
|
| 29 | */ |
|
| 30 | public function __construct(ExtensibleClassMetadata $classMetadata, $fieldName) |
|
| 31 | { |
|
| 32 | $this->classMetadata = $classMetadata; |
|
| 33 | $this->fieldName = $fieldName; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Enable TreeLeft |
|
| 38 | */ |
|
| 39 | public static function enable() |
|
| 40 | { |
|
| 41 | Field::macro(self::MACRO_METHOD, function (Field $field) { |
|
| 42 | return new static($field->getClassMetadata(), $field->getName()); |
|
| 43 | }); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Execute the build process |
|
| 48 | */ |
|
| 49 | public function build() |
|
| 50 | { |
|
| 51 | if (!(new Validator())->isValidField($this->classMetadata, $this->fieldName)) { |
|
| 52 | throw new InvalidMappingException("Tree left field must be 'integer' in class - {$this->classMetadata->name}"); |
|
| 53 | } |
|
| 54 | ||
| 55 | $this->classMetadata->appendExtension($this->getExtensionName(), [ |
|
| 56 | 'left' => $this->fieldName |
|
| 57 | ]); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * Return the name of the actual extension. |
|
| 62 | * |
|
| 63 | * @return string |
|
| 64 | */ |
|
| 65 | public function getExtensionName() |
|
| 66 | { |
|
| 67 | return FluentDriver::EXTENSION_NAME; |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||
| @@ 12-69 (lines=58) @@ | ||
| 9 | use LaravelDoctrine\Fluent\Builders\Field; |
|
| 10 | use LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadata; |
|
| 11 | ||
| 12 | class TreeLevel implements Buildable |
|
| 13 | { |
|
| 14 | const MACRO_METHOD = 'treeLevel'; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @var ExtensibleClassMetadata |
|
| 18 | */ |
|
| 19 | protected $classMetadata; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @var string |
|
| 23 | */ |
|
| 24 | protected $fieldName; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @param ExtensibleClassMetadata $classMetadata |
|
| 28 | * @param string $fieldName |
|
| 29 | */ |
|
| 30 | public function __construct(ExtensibleClassMetadata $classMetadata, $fieldName) |
|
| 31 | { |
|
| 32 | $this->classMetadata = $classMetadata; |
|
| 33 | $this->fieldName = $fieldName; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Enable TreeLevel |
|
| 38 | */ |
|
| 39 | public static function enable() |
|
| 40 | { |
|
| 41 | Field::macro(self::MACRO_METHOD, function (Field $field) { |
|
| 42 | return new static($field->getClassMetadata(), $field->getName()); |
|
| 43 | }); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Execute the build process |
|
| 48 | */ |
|
| 49 | public function build() |
|
| 50 | { |
|
| 51 | if (!(new Validator)->isValidField($this->classMetadata, $this->fieldName)) { |
|
| 52 | throw new InvalidMappingException("Tree level field must be 'integer' in class - {$this->classMetadata->name}"); |
|
| 53 | } |
|
| 54 | ||
| 55 | $this->classMetadata->appendExtension($this->getExtensionName(), [ |
|
| 56 | 'level' => $this->fieldName |
|
| 57 | ]); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * Return the name of the actual extension. |
|
| 62 | * |
|
| 63 | * @return string |
|
| 64 | */ |
|
| 65 | public function getExtensionName() |
|
| 66 | { |
|
| 67 | return FluentDriver::EXTENSION_NAME; |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||
| @@ 12-71 (lines=60) @@ | ||
| 9 | use LaravelDoctrine\Fluent\Builders\Field; |
|
| 10 | use LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadata; |
|
| 11 | ||
| 12 | class TreePathSource implements Buildable |
|
| 13 | { |
|
| 14 | const MACRO_METHOD = 'treePathSource'; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @var ExtensibleClassMetadata |
|
| 18 | */ |
|
| 19 | protected $classMetadata; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @var string |
|
| 23 | */ |
|
| 24 | protected $fieldName; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @param ExtensibleClassMetadata $classMetadata |
|
| 28 | * @param string $fieldName |
|
| 29 | */ |
|
| 30 | public function __construct(ExtensibleClassMetadata $classMetadata, $fieldName) |
|
| 31 | { |
|
| 32 | $this->classMetadata = $classMetadata; |
|
| 33 | $this->fieldName = $fieldName; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Enable TreePathSource |
|
| 38 | */ |
|
| 39 | public static function enable() |
|
| 40 | { |
|
| 41 | Field::macro(self::MACRO_METHOD, function (Field $field) { |
|
| 42 | return new static($field->getClassMetadata(), $field->getName()); |
|
| 43 | }); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Execute the build process |
|
| 48 | */ |
|
| 49 | public function build() |
|
| 50 | { |
|
| 51 | if (!(new Validator)->isValidFieldForPathSource($this->classMetadata, $this->fieldName)) { |
|
| 52 | throw new InvalidMappingException( |
|
| 53 | "Tree PathSource field - [{$this->fieldName}] type is not valid. It can be any of the integer variants, double, float or string in class - {$this->classMetadata->name}" |
|
| 54 | ); |
|
| 55 | } |
|
| 56 | ||
| 57 | $this->classMetadata->appendExtension($this->getExtensionName(), [ |
|
| 58 | 'path_source' => $this->fieldName |
|
| 59 | ]); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Return the name of the actual extension. |
|
| 64 | * |
|
| 65 | * @return string |
|
| 66 | */ |
|
| 67 | public function getExtensionName() |
|
| 68 | { |
|
| 69 | return FluentDriver::EXTENSION_NAME; |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||
| @@ 12-69 (lines=58) @@ | ||
| 9 | use LaravelDoctrine\Fluent\Builders\Field; |
|
| 10 | use LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadata; |
|
| 11 | ||
| 12 | class TreeRight implements Buildable |
|
| 13 | { |
|
| 14 | const MACRO_METHOD = 'treeRight'; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @var ExtensibleClassMetadata |
|
| 18 | */ |
|
| 19 | protected $classMetadata; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @var string |
|
| 23 | */ |
|
| 24 | protected $fieldName; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @param ExtensibleClassMetadata $classMetadata |
|
| 28 | * @param string $fieldName |
|
| 29 | */ |
|
| 30 | public function __construct(ExtensibleClassMetadata $classMetadata, $fieldName) |
|
| 31 | { |
|
| 32 | $this->classMetadata = $classMetadata; |
|
| 33 | $this->fieldName = $fieldName; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Enable TreeRight |
|
| 38 | */ |
|
| 39 | public static function enable() |
|
| 40 | { |
|
| 41 | Field::macro(self::MACRO_METHOD, function (Field $field) { |
|
| 42 | return new static($field->getClassMetadata(), $field->getName()); |
|
| 43 | }); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Execute the build process |
|
| 48 | */ |
|
| 49 | public function build() |
|
| 50 | { |
|
| 51 | if (!(new Validator)->isValidField($this->classMetadata, $this->fieldName)) { |
|
| 52 | throw new InvalidMappingException("Tree right field must be 'integer' in class - {$this->classMetadata->name}"); |
|
| 53 | } |
|
| 54 | ||
| 55 | $this->classMetadata->appendExtension($this->getExtensionName(), [ |
|
| 56 | 'right' => $this->fieldName |
|
| 57 | ]); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * Return the name of the actual extension. |
|
| 62 | * |
|
| 63 | * @return string |
|
| 64 | */ |
|
| 65 | public function getExtensionName() |
|
| 66 | { |
|
| 67 | return FluentDriver::EXTENSION_NAME; |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||