{"id":15658767,"url":"https://github.com/adamwojs/ezplatform-location-reference","last_synced_at":"2025-08-19T09:15:06.170Z","repository":{"id":56940511,"uuid":"194519620","full_name":"adamwojs/ezplatform-location-reference","owner":"adamwojs","description":" Domain Specific Language for referencing eZ Platform locations","archived":false,"fork":false,"pushed_at":"2019-08-21T17:52:44.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-30T02:43:24.319Z","etag":null,"topics":["domain-specific-language","dsl","expression-language","ezplatform","ezplatform-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamwojs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-30T13:33:30.000Z","updated_at":"2019-08-21T17:52:45.000Z","dependencies_parsed_at":"2022-08-21T06:20:55.766Z","dependency_job_id":null,"html_url":"https://github.com/adamwojs/ezplatform-location-reference","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/adamwojs/ezplatform-location-reference","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamwojs%2Fezplatform-location-reference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamwojs%2Fezplatform-location-reference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamwojs%2Fezplatform-location-reference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamwojs%2Fezplatform-location-reference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamwojs","download_url":"https://codeload.github.com/adamwojs/ezplatform-location-reference/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamwojs%2Fezplatform-location-reference/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271129065,"owners_count":24703879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["domain-specific-language","dsl","expression-language","ezplatform","ezplatform-bundle"],"created_at":"2024-10-03T13:13:55.738Z","updated_at":"2025-08-19T09:15:06.143Z","avatar_url":"https://github.com/adamwojs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ezplatform-location-reference\n\n## Problem\n\nThe common case in the eZ Platform configuration is referencing to some location, usually using Location ID e.g.\n\n* Content root for Site Access (https://doc.ezplatform.com/en/latest/guide/multisite/#location_id)\n* Folder used to store Image Assets (https://doc.ezplatform.com/en/latest/api/field_type_reference/#configuration)\n\nThere are several issues in this approaches:\n\n* Location IDs differ between environments\n* Using [Magic numbers](https://en.wikipedia.org/wiki/Magic_number_%28programming%29) is a [code smell](https://en.wikipedia.org/wiki/Code_smell)\n\nThis package introduces [Domain Specific Language](https://en.wikipedia.org/wiki/Domain-specific_language), based on Symfony [Expression Language](https://symfony.com/doc/current/components/expression_language.html) component, allowing to refer locations using meaningful and descriptive expressions. \n\n## Usage\n\n### Resolve location references\n\nLocation reference expressions could be resolved using `LocationReferenceResolver` e.g.\n\n```php\n\u003c?php\n\nnamespace App\\Service; \n\nclass FooService \n{\n    /**\n     * @var \\AdamWojs\\EzPlatformLocationReference\\LocationReferenceResolverInterface  \n     */\n    private $locationReferenceResolver;\n\n    public function __construct(LocationReferenceResolverInterface $locationReferenceResolver)\n    {\n        $this-\u003elocationReferenceResolver = $locationReferenceResolver;\n    }\n\n    public function foo(): void\n    {\n        $location = $this-\u003elocationReferenceResolver-\u003eresolve(\n            'remote_id(\"babe4a915b1dd5d369e79adb9d6c0c6a\")'\n        );\n\n        // ...\n    }\n}\n```\n\n### Retrieving location reference from SiteAccess aware configuration\n\nLocation references could be retrieved from the SiteAccess aware configuration \nusing `LocationConfigResolver`:  \n\n```php\n\u003c?php \n\ninterface LocationConfigResolverInterface\n{\n    public function getLocation(string $name, ?string $namespace = null, ?string $scope = null): Location;\n\n    public function getLocationReference(string $name, ?string $namespace = null, ?string $scope = null): LocationReference;\n}\n```\n\n\nArguments for both `getLocation` and `getLocationReference` methods are exactly the same as for \n`\\eZ\\Publish\\Core\\MVC\\ConfigResolverInterface::getParameter`. \n\n\nExample:\n\n```php\n\u003c?php \n\nclass BarService \n{\n    /**\n     * @var \\AdamWojs\\EzPlatformLocationReference\\ConfigResolver\\LocationConfigResolverInterface  \n     */\n    private $locationConfigResolver;\n\n    public function __construct(LocationConfigResolverInterface $locationConfigResolver)\n    {\n        $this-\u003elocationConfigResolver = $locationConfigResolver;\n    }\n\n    // ...\n\n    public function foo(): void\n    {\n        // Get reference to location \n        $reference = $this-\u003elocationConfigResolver-\u003egetLocationReference('content.tree_root.location_id');\n        \n        // Resolve location reference \n        $location = $reference-\u003egetLocation();\n        // Return null if location is not available (not found or unauthorized)  \n        $location = $reference-\u003egetLocationOrNull();\n        // Return $defaultLocation if location is not available (not found or unauthorized)\n        $location = $reference-\u003egetLocationOrDefault($defaultLocation);\n        \n        // Get reference and immediately resolve\n        $location = $this-\u003elocationConfigResolver-\u003egetLocation('fieldtypes.ezimageasset.parent_location');\n    }\n}\n```\n\n### Available functions\n\n| Function    | Description                  | Example                                         |\n|-------------|------------------------------|-------------------------------------------------|\n| `root`      | Load root location           | `root()`                                        |\n| `parent`    | Load parent location         | `parent(local_id(54))`                          |\n| `local_id`  | Load location by ID          | `local_id(54)`                                  |\n| `remote_id` | Load location by remote ID   | `remote_id(\"babe4a915b1dd5d369e79adb9d6c0c6a\")` |\n| `path`      | Load location by path string | `path(\"/1/2/54\")`                               |\n| `named`     | Load named reference         | `named(\"MEDIA\")`                                |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamwojs%2Fezplatform-location-reference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamwojs%2Fezplatform-location-reference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamwojs%2Fezplatform-location-reference/lists"}