LaravelPackages.net
Acme Inc.
Toggle sidebar
uedehua/laravel5-doctrine

The Doctrine Orm Form Laravel Framework.

0
0
About uedehua/laravel5-doctrine

uedehua/laravel5-doctrine is a Laravel package for the doctrine orm form laravel framework.. It currently has 0 GitHub stars and 0 downloads on Packagist. Install it with composer require uedehua/laravel5-doctrine. Discover more Laravel packages by uedehua or browse all Laravel packages to compare alternatives.

Last updated

Doctrine 2 for Laravel5

Latest Stable Version License Total Downloads

A Doctrine 2 implementation that melts with Laravel 5.1.X.

Documentation

Begin reading the full documentation here or go to a specific chapter right away.

  1. Installation
  2. How It Works
  3. Basics
  4. Entity Manager
  5. Timestamps
  6. Soft Deleting
  7. Authentication
  8. Schemas
  9. Doctrine Configuration
  10. Metadata Configuration
  11. Annotation Reader
  12. Metadata
  13. MIT License

Caveats

As a result the composer install may require you to change the minimum-stability in your composer.json to dev.

如果你不想影响其他包的稳定性, 您可以在您的 composer.json增加下面的属性:

"prefer-stable": true

安装

通过Composer安装之前,编辑你项目的 composer.json 文件,添加 uedehua/laravel5-doctrine.

这个代码还处于早期阶段,但功能齐全。可以预料会有一些小得变化,不会有大得变动.

"require": {
    "uedehua/laravel5-doctrine": "5.1.*"
}

接下来,通过Composer命令更新你得项目:

php composer update

一旦安装了包,您需要添加服务供应商. 打开项目 app/config/app.php 配置文件, 在providers数组内添加新的项目.

'UeDehua\LaravelDoctrine\Provider\DoctrineOrmProvider'

接下来添加Facade. 打开 app/config/app.php 配置文件, 在aliases数组内添加新的项目.

'DoctrineOrm' => 'UeDehua\LaravelDoctrine\Facade\DoctrineOrm'

别忘记发布你的配置.

php artisan config:publish uedehua/laravel5-doctrine --path=vendor/uedehua/laravel5-doctrine/config

2 Minutes

This package uses the Laravel database configuration and thus it works right out of the box. With the Entity Manager facade (or service locator) you can interact with repositories. It might be wise to check out the Doctrine 2 docs to know how it works. The little example below shows how to use the EntityManager in it simplest form.

<?php

$user = new User;
$user->setName('Mitchell');

EntityManager::persist($user);
EntityManager::flush();

The User used in the example above looks like this.

<?php

use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="hk_user")
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string")
     */
    private $name;

    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }
}

If you've only used Eloquent and its models this might look bloated or frightening, but it's actually very simple. Let me break the class down.

<?php

use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="hk_user")
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string")
     */
    private $name;
}

The only thing that's actually important in this entity are the properties. This shows you which data the entity holds.

With Doctrine 2 you can't interact with database by using the entity User. You'll have to use Entity Manager and repositories. This does create less overhead since your entities aren't extending the whole Eloquent model class. Which can dramatically slow down your application a lot if you're working with thousands or millions of records.

License

This package is licensed under the MIT license.

Comments