Skip to content

Commit

Permalink
Introduced Value Object strict getters and deprecated magic ones
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed May 23, 2024
1 parent aa9a7a4 commit 65bb33d
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/contracts/Repository/Values/Content/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* this class represents a content object in a specific version.
*
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo convenience getter for getVersionInfo()->getContentInfo()
* @property-read int $id convenience getter for retrieving the contentId: $versionInfo->contentInfo->id
* @property-read int $id @deprecated use {@see Content::getId()} instead.
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo calls getVersionInfo()
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\Field[] $fields access fields, calls getFields()
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\Thumbnail|null $thumbnail calls getThumbnail()
Expand Down
12 changes: 11 additions & 1 deletion src/contracts/Repository/Values/Content/ContentInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @property-read string $mainLanguageCode The main language code of the Content object. If the available flag is set to true the Content is shown in this language if the requested language does not exist.
* @property-read int|null $mainLocationId @deprecated Use {@see ContentInfo::getMainLocationId} instead
* @property-read int $status status of the Content object
* @property-read bool $isHidden status of the Content object
* @property-read bool $isHidden @deprecated Use {@see ContentInfo::$isHidden} instead
*/
class ContentInfo extends ValueObject
{
Expand Down Expand Up @@ -185,6 +185,11 @@ public function isTrashed(): bool
return $this->status === self::STATUS_TRASHED;
}

public function isHidden(): bool
{
return $this->isHidden;
}

public function getContentType(): ContentType
{
return $this->contentType;
Expand Down Expand Up @@ -229,6 +234,11 @@ public function getId(): int
{
return $this->id;
}

public function getName(): string
{
return $this->name;
}
}

class_alias(ContentInfo::class, 'eZ\Publish\API\Repository\Values\Content\ContentInfo');
44 changes: 38 additions & 6 deletions src/contracts/Repository/Values/Content/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
* This class represents a location in the repository.
*
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo calls getContentInfo()
* @property-read int $contentId calls getContentInfo()->id
* @property-read int $id the id of the location
* @property-read int $contentId @deprecated use {@see Location::getContentId()} instead.
* @property-read int $id @deprecated use {@see Location::getId()} instead.
* @property-read int $priority Position of the Location among its siblings when sorted using priority
* @property-read bool $hidden Indicates that the Location entity is hidden (explicitly or hidden by content).
* @property-read bool $invisible Indicates that the Location is not visible, being either marked as hidden itself, or implicitly hidden by its Content or an ancestor Location
* @property-read bool $hidden @deprecated use {@see Location::isHidden()} instead.
* @property-read bool $invisible @deprecated use {@see Location::isInvisible()} instead.
* @property-read bool $explicitlyHidden Indicates that the Location entity has been explicitly marked as hidden.
* @property-read string $remoteId a global unique id of the content object
* @property-read int $parentLocationId the id of the parent location
* @property-read string $pathString @deprecated use {@see Location::getPathString()} instead.
* @property-read array $path Same as $pathString but as array, e.g. [ 1, 2, 4, 23 ]
* @property-read int $depth Depth location has in the location tree
* @property-read int $depth @deprecated use {@see Location::getDepth()} instead.
* @property-read int $sortField Specifies which property the child locations should be sorted on. Valid values are found at {@link Location::SORT_FIELD_*}
* @property-read int $sortOrder Specifies whether the sort order should be ascending or descending. Valid values are {@link Location::SORT_ORDER_*}
*/
Expand Down Expand Up @@ -194,12 +194,22 @@ abstract class Location extends ValueObject
abstract public function getContentInfo(): ContentInfo;

/**
* Return the parent location of of this location.
* Return the parent location of this location.
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Location|null
*/
abstract public function getParentLocation(): ?Location;

public function getId(): int
{
return $this->id;
}

public function getContentId(): int
{
return $this->getContentInfo()->getId();
}

/**
* Returns true if current location is a draft.
*
Expand Down Expand Up @@ -248,6 +258,28 @@ public function getPathString(): string
{
return $this->pathString;
}

/**
* Indicates that the Location is not visible, being either marked as hidden itself, or implicitly hidden by
* its Content or an ancestor Location.
*/
public function isInvisible(): bool
{
return $this->invisible;
}

/**
* Indicates that the Location is hidden either explicitly or by content.
*/
public function isHidden(): bool
{
return $this->hidden;
}

public function getDepth(): int
{
return $this->depth;
}
}

class_alias(Location::class, 'eZ\Publish\API\Repository\Values\Content\Location');
7 changes: 6 additions & 1 deletion src/contracts/Repository/Values/Content/VersionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo calls getContentInfo()
* @property-read mixed $id the internal id of the version
* @property-read int $versionNo the version number of this version (which only increments in scope of a single Content object)
* @property-read int $versionNo @deprecated use {@see VersionInfo::getVersionNo()} instead.
* @property-read \DateTime $modificationDate the last modified date of this version
* @property-read \DateTime $creationDate the creation date of this version
* @property-read mixed $creatorId the user id of the user which created this version
Expand Down Expand Up @@ -115,6 +115,11 @@ public function getLanguageCodes(): array
return $this->languageCodes;
}

public function getVersionNo(): int
{
return $this->versionNo;
}

/**
* Returns true if version is a draft.
*
Expand Down
7 changes: 6 additions & 1 deletion src/contracts/Repository/Values/ContentType/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @property-read \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCollection $fieldDefinitions calls getFieldDefinitions() or on access getFieldDefinition($fieldDefIdentifier)
* @property-read mixed $id the id of the content type
* @property-read int $status the status of the content type. One of ContentType::STATUS_DEFINED|ContentType::STATUS_DRAFT|ContentType::STATUS_MODIFIED
* @property-read string $identifier the identifier of the content type
* @property-read string $identifier @deprecated use {@see ContentType::getIdentifier()} instead.
* @property-read \DateTime $creationDate the date of the creation of this content type
* @property-read \DateTime $modificationDate the date of the last modification of this content type
* @property-read mixed $creatorId the user id of the creator of this content type
Expand Down Expand Up @@ -176,6 +176,11 @@ abstract public function getContentTypeGroups();
*/
abstract public function getFieldDefinitions(): FieldDefinitionCollection;

public function getIdentifier(): string
{
return $this->identifier;
}

/**
* This method returns the field definition for the given identifier.
*
Expand Down
66 changes: 63 additions & 3 deletions src/contracts/Repository/Values/ContentType/FieldDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
* @property-read array $fieldSettings calls getFieldSettings()
* @property-read array $validatorConfiguration calls getValidatorConfiguration()
* @property-read int $id the id of the field definition
* @property-read string $identifier the identifier of the field definition
* @property-read string $identifier @deprecated use {@see FieldDefinition::getIdentifier()} instead.
* @property-read string $fieldGroup the field group name
* @property-read int $position the position of the field definition in the content type
* @property-read string $fieldTypeIdentifier String identifier of the field type
* @property-read string $fieldTypeIdentifier @deprecated {@see FieldDefinition::getFieldTypeIdentifier()} instead.
* @property-read bool $isTranslatable indicates if fields of this definition are translatable
* @property-read bool $isRequired indicates if this field is required in the content object
* @property-read bool $isSearchable indicates if the field is searchable
* @property-read bool $isThumbnail indicates if the field can be thumbnail
* @property-read bool $isThumbnail @deprecated use {@see FieldDefinition::isThumbnail()} instead.
* @property-read bool $isInfoCollector indicates if this field is used for information collection
* @property-read mixed $defaultValue the default value of the field
* @property-read string $mainLanguageCode main Translation (language code) of a multilingual Field Definition
Expand Down Expand Up @@ -129,6 +129,66 @@ abstract public function getFieldSettings(): array;
* @var string
*/
protected $mainLanguageCode;

public function getId(): int
{
return $this->id;
}

public function getFieldGroup(): string
{
return $this->fieldGroup;
}

public function getPosition(): int
{
return $this->position;
}

public function isTranslatable(): bool
{
return $this->isTranslatable;
}

public function isRequired(): bool
{
return $this->isRequired;
}

public function isInfoCollector(): bool
{
return $this->isInfoCollector;
}

public function getDefaultValue()
{
return $this->defaultValue;
}

public function isSearchable(): bool
{
return $this->isSearchable;
}

public function getMainLanguageCode(): string
{
return $this->mainLanguageCode;
}

public function isThumbnail(): bool
{
return $this->isThumbnail;
}

public function getIdentifier(): string
{
return $this->identifier;
}

public function getFieldTypeIdentifier(): string
{
return $this->fieldTypeIdentifier;
}
}

class_alias(FieldDefinition::class, 'eZ\Publish\API\Repository\Values\ContentType\FieldDefinition');
22 changes: 13 additions & 9 deletions src/contracts/Repository/Values/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Content;

/**
* This class represents a user value.
*
* @property-read string $login
* @property-read string $login @deprecated {@see User::getLogin()} instead.
* @property-read string $email
* @property-read string $passwordHash
* @property-read string $passwordHash @deprecated {@see User::getPasswordHash()} instead.
* @property-read string $hashAlgorithm Hash algorithm used to hash the password
* @property-read \DateTimeInterface|null $passwordUpdatedAt
* @property-read bool $enabled User can not login if false
Expand Down Expand Up @@ -94,15 +92,21 @@ abstract class User extends Content implements UserReference
*/
protected $maxLogin;

/**
* The User id of the User.
*
* @return int
*/
public function getUserId(): int
{
// ATM User Id is the same as Content Id
return $this->getId();
}

public function getLogin(): string
{
return $this->login;
}

public function getPasswordHash(): string
{
return $this->passwordHash;
}
}

class_alias(User::class, 'eZ\Publish\API\Repository\Values\User\User');
72 changes: 65 additions & 7 deletions src/lib/MVC/Symfony/Routing/SimplifiedRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
use Ibexa\Contracts\Core\Repository\Values\ValueObject;

/**
* @property-read string $scheme The request scheme - http or https
* @property-read string $host The host name
* @property-read string $port The port the request is made on
* @property-read string $pathinfo The path being requested relative to the executed script
* @property-read array $queryParams Array of parameters extracted from the query string
* @property-read array $languages List of languages acceptable by the client browser
* @property-read array $headers Hash of request headers
* @property-read string $scheme @deprecated use {@see SimplifiedRequest::getScheme()} instead.
* @property-read string $host @deprecated use {@see SimplifiedRequest::getHost()} instead.
* @property-read string $port @deprecated use {@see SimplifiedRequest::getScheme()} instead.
* @property-read string $pathinfo @deprecated use {@see SimplifiedRequest::getPathInfo()} instead.
* @property-read array $queryParams @deprecated use {@see SimplifiedRequest::getQueryParams()} instead.
* @property-read array $languages @deprecated use {@see SimplifiedRequest::getLanguages()} instead.
* @property-read array $headers @deprecated use {@see SimplifiedRequest::getHeaders()} instead.
*/
class SimplifiedRequest extends ValueObject
{
Expand Down Expand Up @@ -158,6 +158,64 @@ public function __sleep()

return ['scheme', 'host', 'port', 'pathinfo', 'queryParams', 'languages', 'headers'];
}

/**
* The request scheme - http or https.
*/
public function getScheme(): string
{
return $this->scheme;
}

public function getHost(): string
{
return $this->host;
}

public function getPort(): string
{
return $this->port;
}

/**
* The path being requested relative to the executed script.
*/
public function getPathInfo(): string
{
return $this->pathinfo;
}

/**
* @return array<mixed>
*/
public function getQueryParams(): array
{
return $this->queryParams;
}

/**
* @return string[]
*/
public function getLanguages(): array
{
return $this->languages;
}

/**
* @return array<string>|null
*/
public function getHeader($headerName): ?array
{
return $this->headers[$headerName] ?? null;
}

/**
* @return array<string, array<string>>
*/
public function getHeaders(): array
{
return $this->headers;
}
}

class_alias(SimplifiedRequest::class, 'eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest');
Loading

0 comments on commit 65bb33d

Please sign in to comment.