承接 samj/doctrine-sluggable-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

samj/doctrine-sluggable-bundle

Composer 安装命令:

composer require samj/doctrine-sluggable-bundle

包简介

Implementation for Doctrine2 sluggable behaviour for Symfony entities

README 文档

README

The DoctrineSluggableBundle provides a neat implementation for Doctrine2 sluggable behaviour for your entities.

  • Simple behaviour for generating unique slugs for your entities
  • Neatly done by implementing an interface
  • Ensures slugs don't duplicate
  • Support iconv/transliterate e.g. é -> e
  • Uses dependency injection allowing you to implement custom slugger

The DoctrineSluggableBundle takes care of ensuring your slugs generated for your entity are unique. Simply have your entity implement the SluggableInterface interface your entities will automatically have slugs generated.

This uses the service container and dependency injection which allows you to easily create your own "Slugger" class. This supports you creating custom slugs to suit your domain problem.

This documentation is still under construction. However, an example is provided for any interested parties to begin experimenting with the package.

Contributors

Installation

Simply run assuming you have installed composer.phar or composer binary :

$ php composer.phar require samj/doctrine-sluggable-bundle 2.0

Then add this in app/AppKernel.php :

new SamJ\DoctrineSluggableBundle\SamJDoctrineSluggableBundle(),

Example Entities

Example 1

In this example, the slug is built based on a single field: Note: Make sure you implement the accessor methods getId and getTitle

Code

<?php

// --- YOUR NAMESPACE HERE ---
namespace SamJ\ExampleBundle\Entity;

use SamJ\DoctrineSluggableBundle\SluggableInterface;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table
 */
class SingleFieldExample implements SluggableInterface {
	/**
	 * @ORM\Id
	 * @ORM\Column(type="integer")
	 * @ORM\GeneratedValue
	 */
	protected $id;

	/**
	 * @ORM\Column(type="string")
	 */
	protected $title;

	/**
	 * @ORM\Column(type="string")
	 */
	protected $slug;
	
	// Implement methods for $id, $title, etc
		
	public function getSlug()
	{
		return $this->slug;
	}

	public function setSlug($slug)
	{
		if (!empty($this->slug)) return false;
		$this->slug = $slug;
	}

	public function getSlugFields() {
		return $this->getTitle();
	}
}

Outcome

When the entity is persisted, the $slug field will be populated to be a 0-9, a-z only, with spaces converted to hyphens ("-"), based upon the title field.

i.e.: an entity with a title of Test Post will have a slug of test-post.

Example 2

In this example, the slug is built based on multiple single fields: Note: Make sure you implement the accessor methods getId, getTitle and getAuthor

Code

<?php

// --- YOUR NAMESPACE HERE ---
namespace SamJ\ExampleBundle\Entity;

use SamJ\DoctrineSluggableBundle\SluggableInterface;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table
 */
class MultipleSingleFieldExample implements SluggableInterface {
	/**
	 * @ORM\Id
	 * @ORM\Column(type="integer")
	 * @ORM\GeneratedValue
	 */
	protected $id;

	/**
	 * @ORM\Column(type="string")
	 */
	protected $title;

	/**
	 * @ORM\Column(type="string")
	 */
	protected $author;

	/**
	 * @ORM\Column(type="string")
	 */
	protected $slug;
	
	// Implement methods for $id, $title, $author, etc
		
	public function getSlug()
	{
		return $this->slug;
	}

	public function setSlug($slug)
	{
		if (!empty($this->slug)) return false;
		$this->slug = $slug;
	}

	public function getSlugFields() {
		return array($this->getAuthor(), $this->getTitle());
	}
}

Outcome

When the entity is persisted, the $slug field will be populated to be a 0-9, a-z only, with spaces converted to hyphens ("-"), based upon the author and title field.

i.e.: an entity with a author of Sam Jarrett and a title of Test Post will have a slug of sam-jarrett-test-post.

Further Notes

This bundle uses a service called the "Slugger". You can implement your own slugger behaviour (such as dealing with specific field ordering etc) by implementing the SluggerInterface->getSlug($fields) method. Configure your service container to specific the class in the parameter "sluggable.slugger.class" in your service.xml.

samj/doctrine-sluggable-bundle 适用场景与选型建议

samj/doctrine-sluggable-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.62k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2012 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 samj/doctrine-sluggable-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 samj/doctrine-sluggable-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 samj/doctrine-sluggable-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 16
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-05-15