44
55namespace Pollora \Entity \Domain \Model ;
66
7- use Pollora \Entity \ Shared \ Traits \ ArgumentTranslater ;
7+ use Pollora \WordPressArgs \ ArgumentHelper ;
88
99/**
1010 * The Entity class is an abstract model that provides common functionality
1414 */
1515abstract class Entity
1616{
17- use ArgumentTranslater ;
17+ use ArgumentHelper ;
1818
1919 /**
2020 * Name of the post type or taxonomy shown in the menu. Usually plural.
@@ -164,22 +164,11 @@ abstract class Entity
164164 */
165165 public $ names ;
166166
167- /**
168- * Static collection to store entity instances to prevent garbage collection
169- * before registration happens.
170- */
171- protected static array $ instances = [];
172-
173167 /**
174168 * The entity name, used for registration.
175169 */
176170 protected string $ entity = '' ;
177171
178- /**
179- * Raw arguments that will be passed directly to WordPress.
180- */
181- protected array $ rawArgs = [];
182-
183172 /**
184173 * Retrieves the label for the entity.
185174 *
@@ -766,70 +755,6 @@ public function setAdminCols(array $adminCols): self
766755 return $ this ;
767756 }
768757
769- /**
770- * Build arguments for entity registration.
771- *
772- * @return array Array of arguments to be used for entity registration
773- */
774- public function buildArguments (): array
775- {
776- // Collect all properties that should be used in arguments
777- $ reflection = new \ReflectionClass ($ this );
778- $ properties = $ reflection ->getProperties (\ReflectionProperty::IS_PUBLIC );
779-
780- $ args = [];
781- foreach ($ properties as $ property ) {
782- // Skip properties that should not be in arguments
783- if (in_array ($ property ->getName (), ['slug ' , 'singular ' , 'plural ' , 'names ' ])) {
784- continue ;
785- }
786-
787- // Only include non-null properties
788- $ name = $ property ->getName ();
789- if (isset ($ this ->$ name )) {
790- $ args [$ name ] = $ this ->$ name ;
791- }
792- }
793-
794- // For taxonomies, include the objectType in the args
795- if ($ this ->getEntity () === 'taxonomies ' && $ this instanceof \Pollora \Entity \Domain \Model \Taxonomy) {
796- $ args ['object_type ' ] = $ this ->getObjectType ();
797- }
798-
799- // Merge with raw arguments if any are set
800- if (! empty ($ this ->rawArgs )) {
801- $ args = array_merge ($ args , $ this ->rawArgs );
802- }
803-
804- return $ args ;
805- }
806-
807- /**
808- * Sets raw arguments to be passed directly to WordPress.
809- *
810- * This method allows you to specify arguments that will be merged with
811- * automatically generated arguments during registration.
812- *
813- * @param array $args Raw arguments to pass to WordPress registration functions
814- * @return self Returns this object instance.
815- */
816- public function setRawArgs (array $ args ): self
817- {
818- $ this ->rawArgs = $ args ;
819-
820- return $ this ;
821- }
822-
823- /**
824- * Gets the raw arguments.
825- *
826- * @return array Array of raw arguments
827- */
828- public function getRawArgs (): array
829- {
830- return $ this ->rawArgs ;
831- }
832-
833758 /**
834759 * Gets the entity type name.
835760 *
@@ -850,6 +775,32 @@ public function getSlug(): string
850775 return $ this ->names ['slug ' ] ?? '' ;
851776 }
852777
778+ /**
779+ * Translate the arguments using the given entity and keys.
780+ *
781+ * This is a stub implementation that returns arguments unchanged.
782+ * Override this method in subclasses if translation is needed.
783+ *
784+ * @param array<string, mixed> $args The arguments to be translated
785+ * @param string $entity The translation domain/entity to use
786+ * @param array<int, string> $keyToTranslate The keys to be translated
787+ * @return array<string, mixed> The arguments (unchanged in this implementation)
788+ */
789+ public function translateArguments (
790+ array $ args ,
791+ string $ entity ,
792+ array $ keyToTranslate = [
793+ 'label ' ,
794+ 'labels.* ' ,
795+ 'names.singular ' ,
796+ 'names.plural ' ,
797+ ]
798+ ): array {
799+ // Stub implementation - returns arguments unchanged
800+ // This can be overridden in subclasses if translation is needed
801+ return $ args ;
802+ }
803+
853804 /**
854805 * Initializes the object by setting its singular and plural forms.
855806 *
@@ -858,4 +809,14 @@ public function getSlug(): string
858809 * @return void
859810 */
860811 abstract public function init ();
812+
813+ /**
814+ * Get the arguments for the entity.
815+ *
816+ * @return array|null The arguments for the entity.
817+ */
818+ public function getArgs (): ?array
819+ {
820+ return $ this ->buildArguments ();
821+ }
861822}
0 commit comments