kitano/connection-bundle
Composer 安装命令:
composer require kitano/connection-bundle
包简介
Directed graph implementation to create any connection between two objects (ie. follower/following relation in a social network)
README 文档
README
State : Working. Unstable.
Implementation of a directed Graph for establishing connections between objects.
For instance, a connection may represent:
- follower/following relationship between two users on a social network
- an user "following" a "tag"
- in fact, any relation between any root objects which need to be connected for any reason ;-)
The purpose of this bundle is not to get a ready-to-use implementation but at the minimum a code base to ease the integration of such a system in a Symfony 2 application.
Use case
<?php namespace Acme\DemoBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class HomeController extends Controller { public function indexAction() { $connectionManager = $this->get("kitano_connection.manager.connection"); $userA = $userRepository->find(1); $userB = $bookRepository->find(42); // User A wants to "follow" User B activity // User A clics "follow" button on User B profile page $connectionManager->connect($userA, $userB, 'follow'); } public function newPostAction() { $connectionManager = $this->get("kitano_connection.manager.connection"); $userA = $userRepository->find(1); // User B does something like creating a new Post // We notify all users connected to B $connections = $connectionManager->getConnectionsFrom($userB, array('type' => 'follow')); foreach($connections as $connection) { // Notify ! } } }
Configuration
a) Short functional example
A simple configuration could be something like that
kitano_connection: persistence: type: doctrine_orm
Using this configuration, you can use KitanoConnectionBundle as the Use Case example.
After configuration, don't forget to update your RDBMS schema
$ php app/console doctrine:schema:update
b) Custom connection
If you want a custom connection entity.
kitano_connection: persistence: type: doctrine_orm managed_class: "Acme\Entity\Connection"
In this case, don't forget to define an entity schema for Acme\Entity\Connection
c) Custom connection with a custom persistance layer
If you want to use a custom repository, use the above configuration.
kitano_connection: persistence: type: custom managed_class: "Acme\Entity\Connection"
Define a service named : kitano_connection.repository.connection which implement Kitano\ConnectionBundle\Repository\ConnectionRepositoryInterface
Events
Events are availble if you want to hook the system.
namespace Acme\DemoBundle\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Kitano\ConnectionBundle\Event\ConnectionEvent; class ConnectionSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( ConnectionEvent::CONNECTED => array('onConnected', 0), ConnectionEvent::DISCONNECTED => array('onDisconnected', 0), ); } public function onConnected(ConnectionEvent $event) { $connection = $event->getConnection(); // ... } public function onDisconnected(ConnectionEvent $event) { $connection = $event->getConnection(); // ... } }
<?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <parameters> <parameter key="acme.demo.connection_subscriber.class">Acme\DemoBundle\Event\ConnectionSubscriber</parameter> </parameters> <services> <!-- listener --> <service id="acme.demo.connection_subscriber" class="%acme.demo.connection_subscriber.class%" public="false"> <tag name="kernel.event_subscriber" /> </service> </services> </container>
Limitations
- This bundle can deal with only one persistance layer. It means that you can't Connect a Document object with an Entity object.
License
This bundle is under the MIT license. See the complete license in the bundle:
Resources/meta/LICENSE
Testing
Require PHPUnit, phpunit/DbUnit
$ php composer.phar update --dev $ phpunit
kitano/connection-bundle 适用场景与选型建议
kitano/connection-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 100 次下载、GitHub Stars 达 13, 最近一次更新时间为 2013 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「social」 「Connection」 「friends」 「friendship」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kitano/connection-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kitano/connection-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kitano/connection-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
This package gives Eloquent models the ability to manage their followers.
LinkedIn integration for Social
Small service to parse database connection string into parts
This package gives Eloquent models the ability to manage their friendships.
统计信息
- 总下载量: 100
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-02-17