-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ba4320f
Showing
19 changed files
with
589 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
|
||
before_script: | ||
- composer self-update | ||
- composer install --prefer-source --no-interaction --dev | ||
|
||
script: phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 - Mitchell van Wijngaarden <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Doctrine for Laravel | ||
|
||
Doctrine implementation for Laravel 4 | ||
|
||
## Installation | ||
|
||
Begin by installing the package through Composer. Edit your project's `composer.json` file to require `mitch/laravel-doctrine`. | ||
|
||
```php | ||
"require": { | ||
"mitch/laravel-doctrine": "0.1.x" | ||
} | ||
``` | ||
|
||
Next use Composer to update your project from the the Terminal: | ||
|
||
```php | ||
php composer.phar update | ||
``` | ||
|
||
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. | ||
|
||
```php | ||
'Mitch\LaravelDoctrine\LaravelDoctrineServiceProvider' | ||
``` | ||
|
||
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. | ||
|
||
```php | ||
'EntityManager' => 'Mitch\LaravelDoctrine\EntityManagerFacade' | ||
``` | ||
|
||
It's recommended to publish the package configuration. | ||
|
||
```php | ||
php artisan config:publish mitch/laravel-doctrine | ||
``` | ||
|
||
## How It Works | ||
|
||
This package gives you possibility to access the entity manager through the `EntityManager` facade. | ||
|
||
```php | ||
$product = new Product; | ||
$product->setName('thinkpad'); | ||
$product->setPrice(1200); | ||
|
||
EntityManager::persist($product); | ||
EntityManager::flush(); | ||
``` | ||
|
||
For the full documentation on Doctrine [check out their docs](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html) | ||
|
||
## Commands | ||
|
||
This package provides three artisan commands for your schema: | ||
|
||
* doctrine:schema:create - Create database schema from models | ||
* doctrine:schema:update - Update database schema to match models | ||
* doctrine:schema:drop - Drop database schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "mitch/laravel-doctrine", | ||
"description": "Doctrine implementation for Laravel 4", | ||
"keywords": ["doctrine", "laravel"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Mitchell van Wijngaarden", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/support": "4.1.*", | ||
"doctrine/orm": "2.5.*", | ||
"doctrine/migrations": "1.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Mitch\\LaravelDoctrine\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
return [ | ||
// Available: APC, Xcache, Redis, Memcache | ||
'provider' => null, | ||
|
||
'connection' => [ | ||
'driver' => 'pdo_mysql', | ||
'host' => 'localhost', | ||
'database' => 'database', | ||
'username' => 'root', | ||
'password' => '', | ||
'prefix' => '' | ||
], | ||
|
||
'metadata' => [ | ||
base_path('app/models') | ||
], | ||
|
||
'proxy' => [ | ||
'auto_generate' => false, | ||
'directory' => null, | ||
'namespace' => null | ||
], | ||
|
||
'cache' => [ | ||
'redis' => [ | ||
'host' => '127.0.0.1', | ||
'port' => 6379, | ||
'database' => 1 | ||
], | ||
'memcache' => [ | ||
'host' => '127.0.0.1', | ||
'port' => 11211 | ||
] | ||
], | ||
|
||
'migrations' => [ | ||
'directory' => 'database/doctrine-migrations', | ||
'table' => 'doctrine_migrations' | ||
], | ||
|
||
'repository' => 'Doctrine\ORM\EntityRepository', | ||
|
||
'logger' => null | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php namespace Mitch\LaravelDoctrine; | ||
|
||
class CacheManager | ||
{ | ||
private $provider; | ||
private $config; | ||
|
||
public function __construct($provider, $config) | ||
{ | ||
$this->provider = $provider; | ||
$this->config = $config; | ||
} | ||
|
||
public function getCache() | ||
{ | ||
return $this->provider ? $this->getCacheProvider($this->provider)->provide($this->getCacheConfig($this->provider)) : null; | ||
} | ||
|
||
private function getCacheProvider($provider) | ||
{ | ||
$provider = ucfirst($provider); | ||
$class = $this->getFullClassName("{$provider}Provider"); | ||
return new $class; | ||
} | ||
|
||
private function getFullClassName($class) | ||
{ | ||
return "Mitch\\LaravelDoctrine\\CacheProviders\\{$class}"; | ||
} | ||
|
||
private function getCacheConfig($provider) | ||
{ | ||
return $this->config[$provider]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php namespace Mitch\LaravelDoctrine\CacheProviders; | ||
|
||
use Doctrine\Common\Cache\ApcCache; | ||
|
||
class ApcProvider implements Provider | ||
{ | ||
public function provide($config = null) | ||
{ | ||
return new ApcCache; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php namespace Mitch\LaravelDoctrine\CacheProviders; | ||
|
||
use Doctrine\Common\Cache\MemcacheCache; | ||
use Memcache; | ||
|
||
class MemcacheProvider implements Provider | ||
{ | ||
public function provide($config = null) | ||
{ | ||
$memcache = new Memcache; | ||
$memcache->connect($config['host'], $config['port']); | ||
|
||
$cache = new MemcacheCache; | ||
$cache->setMemcache($memcache); | ||
return $cache; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php namespace Mitch\LaravelDoctrine\CacheProviders; | ||
|
||
interface Provider | ||
{ | ||
public function provide($config = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php namespace Mitch\LaravelDoctrine\CacheProviders; | ||
|
||
use Doctrine\Common\Cache\RedisCache; | ||
use Redis; | ||
|
||
class RedisProvider implements Provider | ||
{ | ||
public function provide($config = null) | ||
{ | ||
$redis = new Redis(); | ||
$redis->connect($config['host'], $config['port']); | ||
|
||
if (isset($config['database'])) { | ||
$redis->select($config['database']); | ||
} | ||
|
||
$cache = new RedisCache(); | ||
$cache->setRedis($redis); | ||
return $cache; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php namespace Mitch\LaravelDoctrine\CacheProviders; | ||
|
||
use Doctrine\Common\Cache\XcacheCache; | ||
|
||
class XcacheProvider implements Provider | ||
{ | ||
public function provider($config = null) | ||
{ | ||
return new XcacheCache; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php namespace Mitch\LaravelDoctrine\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
use Doctrine\ORM\Mapping\ClassMetadataFactory; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class SchemaCreateCommand extends Command | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'doctrine:schema:create'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create database schema from models'; | ||
|
||
/** | ||
* The schema tool. | ||
* | ||
* @var \Doctrine\ORM\Tools\SchemaTool | ||
*/ | ||
private $tool; | ||
|
||
/** | ||
* The class metadata factory | ||
* | ||
* @var \Doctrine\ORM\Tools\SchemaTool | ||
*/ | ||
private $metadata; | ||
|
||
public function __construct(SchemaTool $tool, ClassMetadataFactory $metadata) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->tool = $tool; | ||
$this->metadata = $metadata; | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function fire() | ||
{ | ||
if ($this->option('sql')) { | ||
$this->info('Outputting create query:'); | ||
$sql = $this->tool->getCreateSchemaSql($this->metadata->getAllMetadata()); | ||
$this->info(implode(';' . PHP_EOL, $sql)); | ||
} else { | ||
$this->info('Creating database schema...'); | ||
$this->tool->createSchema($this->metadata->getAllMetadata()); | ||
$this->info('Schema has been created!'); | ||
} | ||
} | ||
|
||
protected function getOptions() | ||
{ | ||
return [ | ||
['sql', null, InputOption::VALUE_OPTIONAL, 'Dumps SQL query and does not execute creation.'] | ||
]; | ||
} | ||
} |
Oops, something went wrong.