-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#33 Major refactor with PhpClassPropertyType typing
- Loading branch information
Pavel Alexeev
authored and
Pavel Alexeev
committed
Jan 8, 2022
1 parent
f770360
commit cf63d4d
Showing
18 changed files
with
558 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
<?php | ||
|
||
/** | ||
* Inheritance: no | ||
* Variants: no | ||
Fields Summary: | ||
- code [input] | ||
- name [input] | ||
- fullName [input] | ||
- masterSystem [multiselect] | ||
- roleSubject [select] | ||
- roleObject [multiselect] | ||
- topic [multiselect] | ||
- description [textarea] | ||
*/ | ||
|
||
namespace PhpKafka\PhpAvroSchemaGenerator\Example\Minimal; | ||
|
||
/** | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing getList() | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing|\PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole|null getByCode($value, $limit = 0, $offset = 0, $objectTypes = null) | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing|\PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole|null getByName($value, $limit = 0, $offset = 0, $objectTypes = null) | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing|\PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole|null getByFullName($value, $limit = 0, $offset = 0, $objectTypes = null) | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing|\PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole|null getByMasterSystem($value, $limit = 0, $offset = 0, $objectTypes = null) | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing|\PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole|null getByRoleSubject($value, $limit = 0, $offset = 0, $objectTypes = null) | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing|\PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole|null getByRoleObject($value, $limit = 0, $offset = 0, $objectTypes = null) | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing|\PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole|null getByTopic($value, $limit = 0, $offset = 0, $objectTypes = null) | ||
* @method static \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole\Listing|\PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole|null getByDescription($value, $limit = 0, $offset = 0, $objectTypes = null) | ||
*/ | ||
|
||
class EpamRole { | ||
protected $o_classId = "6"; | ||
protected $o_className = "EpamRole"; | ||
protected $code; | ||
protected $name; | ||
protected $fullName; | ||
/** | ||
* @var string[] | ||
**/ | ||
protected $masterSystem; | ||
protected $roleSubject; | ||
protected $roleObject; | ||
protected $topic; | ||
protected $description; | ||
|
||
|
||
/** | ||
* @param array $values | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public static function create($values = array()) { | ||
$object = new static(); | ||
return $object; | ||
} | ||
|
||
/** | ||
* Get code - code | ||
* @return string|null | ||
*/ | ||
public function getCode(): ?string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
/** | ||
* Set code - code | ||
* @param string|null $code | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public function setCode(?string $code) | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get name - name | ||
* @return string|null | ||
*/ | ||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Set name - name | ||
* @param string|null $name | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public function setName(?string $name) | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get fullName - fullName | ||
* @return string|null | ||
*/ | ||
public function getFullName(): ?string | ||
{ | ||
return $this->fullName; | ||
} | ||
|
||
/** | ||
* Set fullName - fullName | ||
* @param string|null $fullName | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public function setFullName(?string $fullName) | ||
{ | ||
$this->fullName = $fullName; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get masterSystem - masterSystem | ||
* @return string[]|null | ||
*/ | ||
public function getMasterSystem(): ?array | ||
{ | ||
$data = $this->masterSystem; | ||
return $data; | ||
} | ||
|
||
/** | ||
* Set masterSystem - masterSystem | ||
* @param string[]|null $masterSystem | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public function setMasterSystem(?array $masterSystem) | ||
{ | ||
$this->masterSystem = $masterSystem; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get roleSubject - subject | ||
* @return string|null | ||
*/ | ||
public function getRoleSubject(): ?string | ||
{ | ||
$data = $this->roleSubject; | ||
return $data; | ||
} | ||
|
||
/** | ||
* Set roleSubject - subject | ||
* @param string|null $roleSubject | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public function setRoleSubject(?string $roleSubject) | ||
{ | ||
$this->roleSubject = $roleSubject; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get roleObject - roleObject | ||
* @return string[]|null | ||
*/ | ||
public function getRoleObject(): ?array | ||
{ | ||
$data = $this->roleObject; | ||
return $data; | ||
} | ||
|
||
/** | ||
* Set roleObject - roleObject | ||
* @param string[]|null $roleObject | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public function setRoleObject(?array $roleObject) | ||
{ | ||
$this->roleObject = $roleObject; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get topic - topic | ||
* @return string[]|null | ||
*/ | ||
public function getTopic(): ?array | ||
{ | ||
$data = $this->topic; | ||
return $data; | ||
} | ||
|
||
/** | ||
* Set topic - topic | ||
* @param string[]|null $topic | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public function setTopic(?array $topic) | ||
{ | ||
$this->topic = $topic; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get description - description | ||
* @return string|null | ||
*/ | ||
public function getDescription(): ?string | ||
{ | ||
$data = $this->description; | ||
return $data; | ||
} | ||
|
||
/** | ||
* Set description - description | ||
* @param string|null $description | ||
* @return \PhpKafka\PhpAvroSchemaGenerator\Example\Minimal\EpamRole | ||
*/ | ||
public function setDescription(?string $description) | ||
{ | ||
$this->description = $description; | ||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace PhpKafka\PhpAvroSchemaGenerator\Exception; | ||
|
||
class SchemaGeneratorException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace PhpKafka\PhpAvroSchemaGenerator\Exception; | ||
|
||
class SkipPropertyException extends \Exception { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace PhpKafka\PhpAvroSchemaGenerator\Parser; | ||
|
||
use PhpKafka\PhpAvroSchemaGenerator\Exception\SkipPropertyException; | ||
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassPropertyParser; | ||
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassProperty; | ||
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassPropertyInterface; | ||
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassPropertyType; | ||
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassPropertyTypeItem; | ||
|
||
/** | ||
* We will skip transient and private properties like starting at 'o_', '_', 'omitMandatoryCheck', 'allLazyKeysMarkedAsLoaded' | ||
*/ | ||
class AvroClassPropertyParser extends ClassPropertyParser { | ||
|
||
/** | ||
* @throws SkipPropertyException | ||
*/ | ||
public function parseProperty($property): PhpClassPropertyInterface { | ||
$prop = parent::parseProperty($property); | ||
if (str_starts_with($prop->getPropertyName(), 'o_') or str_starts_with($prop->getPropertyName(), '_') | ||
or in_array($prop->getPropertyName(), ['omitMandatoryCheck', 'allLazyKeysMarkedAsLoaded'])) { | ||
throw new SkipPropertyException(); | ||
} | ||
// return $prop; | ||
$prop_ = new PhpClassProperty( | ||
$prop->getPropertyName(), | ||
// make type nullable. Can't now in array. See https://github.com/php-kafka/php-avro-schema-generator/issues/33#issuecomment-1007490595 | ||
$prop->getPropertyType()->isNullable() ? $prop->getPropertyType() : new PhpClassPropertyType(new PhpClassPropertyTypeItem('null'), ...$prop->getPropertyType()->getTypeItems()), | ||
// 'null|' . $prop->getPropertyType(), // make type nullable // See https://github.com/php-kafka/php-avro-schema-generator/issues/33#issuecomment-1007551821 | ||
// and only in string work. See https://github.com/php-kafka/php-avro-schema-generator/issues/33#issuecomment-1007490595 | ||
($prop->getPropertyDefault() != PhpClassPropertyInterface::NO_DEFAULT ?: null), | ||
$prop->getPropertyDoc(), | ||
$prop->getPropertyLogicalType() | ||
); | ||
return $prop_; | ||
} | ||
} |
Oops, something went wrong.