Skip to content

Commit

Permalink
laravel 5 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
milanandjelkovic committed Mar 17, 2015
1 parent 05ba665 commit 66f81de
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 14 deletions.
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.x"
"php": ">=5.3.0"
},
"require-dev": {
"mockery/mockery": "dev-master",
"illuminate/console": "4.x",
"illuminate/filesystem": "4.x"
"illuminate/filesystem": "5.x"
},
"autoload": {
"psr-0": {
Expand All @@ -27,4 +25,4 @@
]
},
"minimum-stability": "dev"
}
}
12 changes: 6 additions & 6 deletions src/Orangehill/Iseed/Iseed.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Orangehill\Iseed;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Config;

class Iseed {

Expand All @@ -22,7 +23,7 @@ public function __construct(Filesystem $filesystem = null)
public function generateSeed($table, $database = null, $max = 0)
{
if(!$database) {
$database = \Config::get('database.default');
$database = config('database.default');
}

$this->connection = $database;
Expand Down Expand Up @@ -64,7 +65,7 @@ public function generateSeed($table, $database = null, $max = 0)
*/
public function getSeedPath()
{
return app_path() . \Config::get('iseed::path');
return base_path() . config('iseed::config.path');
}

/**
Expand Down Expand Up @@ -146,8 +147,7 @@ public function getStubPath()
*/
public function populateStub($class, $stub, $table, $data, $chunkSize = null)
{
$chunkSize = $chunkSize ?: \Config::get('iseed::chunk_size');

$chunkSize = $chunkSize ?: config('iseed::config.chunk_size');
$inserts = '';
$chunks = array_chunk($data, $chunkSize);
foreach ($chunks as $chunk) {
Expand Down Expand Up @@ -232,7 +232,7 @@ protected function prettifyArray($array)
*/
public function cleanSection()
{
$databaseSeederPath = app_path() . \Config::get('iseed::path') . '/DatabaseSeeder.php';
$databaseSeederPath = base_path() . config('iseed::config.path') . '/DatabaseSeeder.php';

$content = $this->files->get($databaseSeederPath);

Expand All @@ -249,7 +249,7 @@ public function cleanSection()
*/
public function updateDatabaseSeederRunMethod($className)
{
$databaseSeederPath = app_path() . \Config::get('iseed::path') . '/DatabaseSeeder.php';
$databaseSeederPath = base_path() . config('iseed::config.path') . '/DatabaseSeeder.php';

$content = $this->files->get($databaseSeederPath);
if(strpos($content, "\$this->call('{$className}')")===false)
Expand Down
4 changes: 2 additions & 2 deletions src/Orangehill/Iseed/IseedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function fire()

// generate file and class name based on name of the table
list($fileName, $className) = $this->generateFileName($table);

// if file does not exist or force option is turned on generate seeder
if(!\File::exists($fileName) || $this->option('force')) {
$this->printResult(app('iseed')->generateSeed($table, $this->option('database'), $chunkSize), $table);
Expand Down Expand Up @@ -129,7 +129,7 @@ protected function generateFileName($table)

// Generate class name and file name
$className = app('iseed')->generateClassName($table);
$seedPath = app_path() . \Config::get('iseed::path');
$seedPath = base_path() . config('iseed::config.path');
return [$seedPath . '/' . $className . '.php', $className . '.php'];

}
Expand Down
23 changes: 22 additions & 1 deletion src/Orangehill/Iseed/IseedServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class IseedServiceProvider extends ServiceProvider {
*/
public function boot()
{
$this->package('orangehill/iseed');
require base_path() . '/vendor/autoload.php';
}

/**
Expand All @@ -28,6 +28,8 @@ public function boot()
*/
public function register()
{
$this->registerResources();

$this->app['iseed'] = $this->app->share(function($app)
{
return new Iseed;
Expand Down Expand Up @@ -55,4 +57,23 @@ public function provides()
return array('iseed');
}

/**
* Register the package resources.
*
* @return void
*/
protected function registerResources()
{
$userConfigFile = app()->configPath().'/iseed.php';
$packageConfigFile = __DIR__.'/../../config/config.php';
$config = $this->app['files']->getRequire($packageConfigFile);

if (file_exists($userConfigFile)) {
$userConfig = $this->app['files']->getRequire($userConfigFile);
$config = array_replace_recursive($config, $userConfig);
}

$this->app['config']->set('iseed::config', $config);
}

}
2 changes: 2 additions & 0 deletions src/Orangehill/Iseed/Stubs/seed.stub
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Database\Seeder;

class {{class}} extends Seeder {

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Stubs/seed.stub
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Database\Seeder;

class test_class extends Seeder {

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Stubs/seed_5.stub
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Database\Seeder;

class test_class extends Seeder {

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Stubs/seed_505.stub
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Database\Seeder;

class test_class extends Seeder {

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Stubs/seed_blank.stub
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Database\Seeder;

class test_class extends Seeder {

/**
Expand Down

0 comments on commit 66f81de

Please sign in to comment.