定制 zenify/doctrine-filters 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

zenify/doctrine-filters

最新稳定版本:v4.5.0

Composer 安装命令:

composer require zenify/doctrine-filters

包简介

Doctrine Filters integration into Nette

README 文档

README

Build Status Quality Score Code Coverage Downloads Latest stable

What are Doctrine Filters? Check these few slides or see Usage to get the knowledge.

They are present in Doctrine by default. This package only simplifies their use in modular application.

Install

$ composer require zenify/doctrine-filters

Register extension in config.neon:

extensions:
	- Zenify\DoctrineFilters\DI\FiltersExtension
	- Symplify\SymfonyEventDispatcher\Adapter\Nette\DI\SymfonyEventDispatcherExtension
	
	# Kdyby\Doctrine or another Doctrine to Nette implementation

Usage

Let's create our first filter, which will hide all deleted items on front. So called "soft delete" - data remains in database, but are filtered out in frontend.

First, we create class implementing Zenify\DoctrineFilters\Contract\FilterInterface.

use Doctrine\ORM\Mapping\ClassMetadata;
use Zenify\DoctrineFilters\Contract\FilterInterface;


final class SoftdeletableFilter implements FilterInterface
{

	public function addFilterConstraint(ClassMetadata $entity, string $alias) : string
	{
		if ($entity->getReflectionClass()->hasProperty('isDeleted')) {
			return "$alias.isDeleted = 0");
		}

		return '';
	}

}

Then register as service:

# app/config/config.neon
services:
	- SoftdeletableFilter

And that's it!

Limit Access by Role

The management wants to show deleted content only to logged user with admin role.

To setup condition, we just implement Zenify\DoctrineFilters\Contract\ConditionalFilterInterface.

use Nette\Security\User;
use Zenify\DoctrineFilters\Contract\ConditionalFilterInterface;


final class SoftdeletableFilter implements ConditionalFilterInterface
{

	/**
	 * @var User
	 */
	private $user;
	

	public function __construct(User $user)
	{
		$this->user = $user;
	}

	
	public function addFilterConstraint(ClassMetadata $entity, string $alias) : string
	{
		// same as above
	}
	
	
	public function isEnabled() : bool
	{
		if ($this->user->isLoggedIn() && $this->user->hasRole('admin')) {
			return FALSE;
		}
		return TRUE;
	}
	
}

Voilá!

Testing

composer check-cs
vendor/bin/phpunit

Contributing

Rules are simple:

  • new feature needs tests
  • all tests must pass
  • 1 feature per PR

We would be happy to merge your feature then!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固