Skip to content

Commit ba4320f

Browse files
committed
Initial commit
0 parents  commit ba4320f

19 files changed

+589
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- hhvm
9+
10+
before_script:
11+
- composer self-update
12+
- composer install --prefer-source --no-interaction --dev
13+
14+
script: phpunit

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 - Mitchell van Wijngaarden <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Doctrine for Laravel
2+
3+
Doctrine implementation for Laravel 4
4+
5+
## Installation
6+
7+
Begin by installing the package through Composer. Edit your project's `composer.json` file to require `mitch/laravel-doctrine`.
8+
9+
```php
10+
"require": {
11+
"mitch/laravel-doctrine": "0.1.x"
12+
}
13+
```
14+
15+
Next use Composer to update your project from the the Terminal:
16+
17+
```php
18+
php composer.phar update
19+
```
20+
21+
Once the package has been installed you'll need to add the service provider. Open your `app/config/app.php` configuration file, and add a new item to the `providers` array.
22+
23+
```php
24+
'Mitch\LaravelDoctrine\LaravelDoctrineServiceProvider'
25+
```
26+
27+
After This you'll need to add the facade. Open your `app/config/app.php` configuration file, and add a new item to the `aliases` array.
28+
29+
```php
30+
'EntityManager' => 'Mitch\LaravelDoctrine\EntityManagerFacade'
31+
```
32+
33+
It's recommended to publish the package configuration.
34+
35+
```php
36+
php artisan config:publish mitch/laravel-doctrine
37+
```
38+
39+
## How It Works
40+
41+
This package gives you possibility to access the entity manager through the `EntityManager` facade.
42+
43+
```php
44+
$product = new Product;
45+
$product->setName('thinkpad');
46+
$product->setPrice(1200);
47+
48+
EntityManager::persist($product);
49+
EntityManager::flush();
50+
```
51+
52+
For the full documentation on Doctrine [check out their docs](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html)
53+
54+
## Commands
55+
56+
This package provides three artisan commands for your schema:
57+
58+
* doctrine:schema:create - Create database schema from models
59+
* doctrine:schema:update - Update database schema to match models
60+
* doctrine:schema:drop - Drop database schema

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "mitch/laravel-doctrine",
3+
"description": "Doctrine implementation for Laravel 4",
4+
"keywords": ["doctrine", "laravel"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Mitchell van Wijngaarden",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.4.0",
14+
"illuminate/support": "4.1.*",
15+
"doctrine/orm": "2.5.*",
16+
"doctrine/migrations": "1.*"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"Mitch\\LaravelDoctrine\\": "src/"
21+
}
22+
},
23+
"minimum-stability": "stable"
24+
}

config/doctrine.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
return [
4+
// Available: APC, Xcache, Redis, Memcache
5+
'provider' => null,
6+
7+
'connection' => [
8+
'driver' => 'pdo_mysql',
9+
'host' => 'localhost',
10+
'database' => 'database',
11+
'username' => 'root',
12+
'password' => '',
13+
'prefix' => ''
14+
],
15+
16+
'metadata' => [
17+
base_path('app/models')
18+
],
19+
20+
'proxy' => [
21+
'auto_generate' => false,
22+
'directory' => null,
23+
'namespace' => null
24+
],
25+
26+
'cache' => [
27+
'redis' => [
28+
'host' => '127.0.0.1',
29+
'port' => 6379,
30+
'database' => 1
31+
],
32+
'memcache' => [
33+
'host' => '127.0.0.1',
34+
'port' => 11211
35+
]
36+
],
37+
38+
'migrations' => [
39+
'directory' => 'database/doctrine-migrations',
40+
'table' => 'doctrine_migrations'
41+
],
42+
43+
'repository' => 'Doctrine\ORM\EntityRepository',
44+
45+
'logger' => null
46+
];

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

src/CacheManager.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php namespace Mitch\LaravelDoctrine;
2+
3+
class CacheManager
4+
{
5+
private $provider;
6+
private $config;
7+
8+
public function __construct($provider, $config)
9+
{
10+
$this->provider = $provider;
11+
$this->config = $config;
12+
}
13+
14+
public function getCache()
15+
{
16+
return $this->provider ? $this->getCacheProvider($this->provider)->provide($this->getCacheConfig($this->provider)) : null;
17+
}
18+
19+
private function getCacheProvider($provider)
20+
{
21+
$provider = ucfirst($provider);
22+
$class = $this->getFullClassName("{$provider}Provider");
23+
return new $class;
24+
}
25+
26+
private function getFullClassName($class)
27+
{
28+
return "Mitch\\LaravelDoctrine\\CacheProviders\\{$class}";
29+
}
30+
31+
private function getCacheConfig($provider)
32+
{
33+
return $this->config[$provider];
34+
}
35+
}

src/CacheProviders/ApcProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php namespace Mitch\LaravelDoctrine\CacheProviders;
2+
3+
use Doctrine\Common\Cache\ApcCache;
4+
5+
class ApcProvider implements Provider
6+
{
7+
public function provide($config = null)
8+
{
9+
return new ApcCache;
10+
}
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php namespace Mitch\LaravelDoctrine\CacheProviders;
2+
3+
use Doctrine\Common\Cache\MemcacheCache;
4+
use Memcache;
5+
6+
class MemcacheProvider implements Provider
7+
{
8+
public function provide($config = null)
9+
{
10+
$memcache = new Memcache;
11+
$memcache->connect($config['host'], $config['port']);
12+
13+
$cache = new MemcacheCache;
14+
$cache->setMemcache($memcache);
15+
return $cache;
16+
}
17+
}

0 commit comments

Comments
 (0)