RelationshipInterface.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php declare(strict_types=1);
  2. namespace Grav\Framework\Contracts\Relationships;
  3. use Countable;
  4. use Grav\Framework\Contracts\Object\IdentifierInterface;
  5. use IteratorAggregate;
  6. use JsonSerializable;
  7. use Serializable;
  8. /**
  9. * Interface Relationship
  10. *
  11. * @template T of IdentifierInterface
  12. * @template P of IdentifierInterface
  13. * @extends IteratorAggregate<string, T>
  14. */
  15. interface RelationshipInterface extends Countable, IteratorAggregate, JsonSerializable, Serializable
  16. {
  17. /**
  18. * @return string
  19. * @phpstan-pure
  20. */
  21. public function getName(): string;
  22. /**
  23. * @return string
  24. * @phpstan-pure
  25. */
  26. public function getType(): string;
  27. /**
  28. * @return bool
  29. * @phpstan-pure
  30. */
  31. public function isModified(): bool;
  32. /**
  33. * @return string
  34. * @phpstan-pure
  35. */
  36. public function getCardinality(): string;
  37. /**
  38. * @return P
  39. * @phpstan-pure
  40. */
  41. public function getParent(): IdentifierInterface;
  42. /**
  43. * @param string $id
  44. * @param string|null $type
  45. * @return bool
  46. * @phpstan-pure
  47. */
  48. public function has(string $id, string $type = null): bool;
  49. /**
  50. * @param T $identifier
  51. * @return bool
  52. * @phpstan-pure
  53. */
  54. public function hasIdentifier(IdentifierInterface $identifier): bool;
  55. /**
  56. * @param T $identifier
  57. * @return bool
  58. */
  59. public function addIdentifier(IdentifierInterface $identifier): bool;
  60. /**
  61. * @param T|null $identifier
  62. * @return bool
  63. */
  64. public function removeIdentifier(IdentifierInterface $identifier = null): bool;
  65. /**
  66. * @return iterable<T>
  67. */
  68. public function getIterator(): iterable;
  69. }