adamwojs/ezplatform-location-reference 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adamwojs/ezplatform-location-reference

Composer 安装命令:

composer require adamwojs/ezplatform-location-reference

包简介

eZ Platform Location Reference

README 文档

README

Problem

The common case in the eZ Platform configuration is referencing to some location, usually using Location ID e.g.

There are several issues in this approaches:

This package introduces Domain Specific Language, based on Symfony Expression Language component, allowing to refer locations using meaningful and descriptive expressions.

Usage

Resolve location references

Location reference expressions could be resolved using LocationReferenceResolver e.g.

<?php

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")'
        );

        // ...
    }
}

Retrieving location reference from SiteAccess aware configuration

Location references could be retrieved from the SiteAccess aware configuration using LocationConfigResolver:

<?php 

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;
}

Arguments for both getLocation and getLocationReference methods are exactly the same as for \eZ\Publish\Core\MVC\ConfigResolverInterface::getParameter.

Example:

<?php 

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');
    }
}

Available functions

Function Description Example
root Load root location root()
parent Load parent location parent(local_id(54))
local_id Load location by ID local_id(54)
remote_id Load location by remote ID remote_id("babe4a915b1dd5d369e79adb9d6c0c6a")
path Load location by path string path("/1/2/54")
named Load named reference named("MEDIA")

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固