<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adamwojs / ezplatform-location-reference example snippets
namespace App\Service;
class FooService
{
/**
* @var \AdamWojs\EzPlatformLocationReference\LocationReferenceResolverInterface
*/
private $locationReferenceResolver;
public function __construct(LocationReferenceResolverInterface $locationReferenceResolver)
{
$this->locationReferenceResolver = $locationReferenceResolver;
}
public function foo(): void
{
$location = $this->locationReferenceResolver->resolve(
'remote_id("babe4a915b1dd5d369e79adb9d6c0c6a")'
);
// ...
}
}
interface LocationConfigResolverInterface
{
public function getLocation(string $name, ?string $namespace = null, ?string $scope = null): Location;
public function getLocationReference(string $name, ?string $namespace = null, ?string $scope = null): LocationReference;
}
class BarService
{
/**
* @var \AdamWojs\EzPlatformLocationReference\ConfigResolver\LocationConfigResolverInterface
*/
private $locationConfigResolver;
public function __construct(LocationConfigResolverInterface $locationConfigResolver)
{
$this->locationConfigResolver = $locationConfigResolver;
}
// ...
public function foo(): void
{
// Get reference to location
$reference = $this->locationConfigResolver->getLocationReference('content.tree_root.location_id');
// Resolve location reference
$location = $reference->getLocation();
// Return null if location is not available (not found or unauthorized)
$location = $reference->getLocationOrNull();
// Return $defaultLocation if location is not available (not found or unauthorized)
$location = $reference->getLocationOrDefault($defaultLocation);
// Get reference and immediately resolve
$location = $this->locationConfigResolver->getLocation('fieldtypes.ezimageasset.parent_location');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.