承接 id009/neo4jbundle 相关项目开发

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

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

id009/neo4jbundle

Composer 安装命令:

composer require id009/neo4jbundle

包简介

This bundle integrates Neo4j OGM library into Symfony with basic user provider and form integration

README 文档

README

Provides integration Neo4j PHP Object Graph Mapper with Symfony

Installation with Composer

To install this bundle just add following line to "require" section of your composer.json file: "id009/neo4jbundle": "dev-master"

Run php composer.phar update command. After updating is finished, register the bundle in your AppKernel.php:

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new id009\Neo4jBundle\id009Neo4jBundle(),
    );
    // ...
}

Configuration

To finish bundle installation, you need configuration that sets up entity managers and connections. Quite full configuration shown below.

id009_neo4j:
  connections:
        default:
            host: localhost
            port: 7474
            username: user
            password: pass
    entity_managers:
        default:
            debug: true
            #For pathfinding algorithms refer to Everyman\Neo4j\PathFinder
            pathfinder_algorithm: allSimplePaths
            pathfinder_maxdepth: 5

But in most common cases you'll need something looks like this:

id009_neo4j:
    connections:
        default:
    entity_managers:
        default:

And that's all. In configuration above host is localhost and port is 7474 by default. Debug mode is taken from global debug parameter. Now, after the bundle is installed and configured properly, you can start using it.

Basics

Please, refer to Neo4j PHP Object Graph Mapper readme to understand how OGM works.

If you have a deal with Doctrine ORM Bundle you'll see that basic usage of Neo4j Bundle is pretty straightforward:

// Your controller...
$em = $this->get('id009_neo4j.entity_manager');
// Now you have an instance of HireVoice\Neo4j\EntityManager class. You can do whatever you want with it.
$em->getRepository('Acme\AcmeBundle\Entity')->findOneByUsername('ivanpetrov99'); // and so on...

Security

This bundle provides basic OGMUser class and Security provider, working the same as the entity provider described in the cookbook. Basic security configuration shown below.

providers:
      neo4j_provider:
          neo4j: {class: id009\Neo4jBundle\Security\User\OGMUser}

Forms

The bundle wouldn't be useful enough without integration with Symfony forms. So lets get down to it.

For instance you have a Person and City classes as shown below.

// Acme\AcmeBundle\Entity\Person

/**
 * @OGM\Entity
 */
class Person
{
    //...

    /**
     * @OGM\ManyToOne
     */
    protected $city;

    //...
}

// Acme\AcmeBundle\Entity\City

/**
 * @OGM\Entity
 */
class City
{
    //...
}

It's a good idea to have a form type to select City when editing Person, isn't it? Here is an example:

// Acme\AcmeBundle\Form\Type\PersonType

public function buildForm(FormBuilderInterface $builder, array $options)
{
    //...

    $builder->add('city', null, array(
        'class' => 'Acme\AcmeBundle\Entity\City'
    ));

    //...
}

Form type will be automatically detected as neo4j_entity with options array('multiple' => false, 'expanded' => false), and it will be rendered as dropdown list.

Events

OGM provides three types of events:

  • Entity create
  • Relation create
  • Query run

Please, refer to HireVoice\Neo4j\EntityManager for details on these events.

If you want to subscribe on these events you can create your own Subscriber class that implements Symfony\Component\EventDispatcher\EventSubscriberInterface. But for convenience the bundle has an abstract class id009\Neo4jBundle\Event\AbstractSubscriber, and you can inherit your subscribers from it. For example:

namespace Acme\AcmeBundle\Event

//...

class MySubscriber extends AbstractSubscriber
{
    public function onEntityCreate($entity)
    {
        //...
    }

    public function onRelationCreate($relation, $a, $b, $relationship)
    {
        //...
    }

    public function onQueryRun($query, $parameters, $time)
    {
        //...
    }
}

Now, after your subscriber is done, register it in your services.yml file:

acme_acmebundle.event.subscriber:
    class: 'Acme\AcmeBundle\Event\MySubscriber'
    tags:
        - {name: id009_neo4j.subscriber}

If you have several entity manager within your project just add attribute manager with entity manager name to the tag

Contributors

Alex Belyaev @lex009

You are always welcome to contribute!

I would appreciate any feedback.

License

MIT

id009/neo4jbundle 适用场景与选型建议

id009/neo4jbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 3, 最近一次更新时间为 2012 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「graph」 「neo4j」 「ogm」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 id009/neo4jbundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-12-10