Skip to content

Commit

Permalink
Merge pull request #47 from andjelicsasa/master
Browse files Browse the repository at this point in the history
prerun/postrun seed events support and PSR-2 code standard
  • Loading branch information
andjelicsasa committed Jan 22, 2016
2 parents 0886919 + bc337f1 commit 1847f70
Show file tree
Hide file tree
Showing 13 changed files with 3,828 additions and 3,581 deletions.
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,88 @@ If you wish to install it on Laravel 4 you should require 1.1 version:

composer update

## Artisan command options

### [table_name]
Mandatory parameter which defines which table/s will be used for seed creation.
Use CSV notation for multiple tables. Seed file will be generated for each table.

Examples:
```
php artisan iseed my_table
```
```
php artisan iseed my_table,another_table
```

### force
Optional parameter which is used to automatically overwrite any existing seeds for desired tables

Example:
The following command will overwrite `UsersTableSeeder.php` if it already exists in laravel's seeds directory.
```
php artisan iseed users --force
```

### clean
Optional parameter which will clean `app/database/seeds/DatabaseSeeder.php` before creating new seed class.

Example:
```
php artisan iseed users --clean
```

### database
Optional parameter which specifies the DB connection name.

Example:
```
php artisan iseed users --database=mysql2
```

### max
Optional parameter which defines the maximum number of entries seeded from a specified table. In case of multiple tables, limit will be applied to all of them.

Example:
```
artisan iseed users --max=10
```

### prerun
Optional parameter which assigns a laravel event name to be fired before seeding takes place. If an event listener returns `false`, seed will fail automatically.
You can assign multiple preruns for multiple table names by passing an array of comma separated DB names and respectively passing a comma separated array of prerun event names.

Example:
The following command will make a seed file which will fire an event named 'someEvent' before seeding takes place.
```
artisan iseed users --prerun=someEvent
```
The following example will assign `someUserEvent` to `users` table seed, and `someGroupEvent` to `groups` table seed, to be executed before seeding.
```
artisan iseed users,groups --prerun=someUserEvent,someGroupEvent
```
The following example will only assign a `someGroupEvent` to `groups` table seed, to be executed before seeding. Value for the users table prerun was omitted here, so `users` table seed will have no prerun event assigned.
```
artisan iseed users,groups --prerun=,someGroupEvent
```

### postrun
Optional parameter which assigns a laravel event name to be fired after seeding takes place. If an event listener returns `false`, seed will be executed, but an exception will be thrown that the postrun failed.
You can assign multiple postruns for multiple table names by passing an array of comma separated DB names and respectively passing a comma separated array of postrun event names.

Example:
The following command will make a seed file which will fire an event named 'someEvent' after seeding was completed.
```
artisan iseed users --postrun=someEvent
```
The following example will assign `someUserEvent` to `users` table seed, and `someGroupEvent` to `groups` table seed, to be executed after seeding.
```
artisan iseed users,groups --postrun=someUserEvent,someGroupEvent
```
The following example will only assign a `someGroupEvent` to `groups` table seed, to be executed after seeding. Value for the users table postrun was omitted here, so `users` table seed will have no postrun event assigned.
```
artisan iseed users,groups --postrun=,someGroupEvent
```

## Usage

Expand Down
9 changes: 7 additions & 2 deletions src/Orangehill/Iseed/Exceptions.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php namespace Orangehill\Iseed;
<?php

class TableNotFoundException extends \RuntimeException {}
namespace Orangehill\Iseed;

class TableNotFoundException extends \RuntimeException
{

}
25 changes: 15 additions & 10 deletions src/Orangehill/Iseed/Facades/Iseed.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php namespace Orangehill\Iseed\Facades;
<?php

use Illuminate\Support\Facades\Facade;
namespace Orangehill\Iseed\Facades;

class Iseed extends Facade {
use Illuminate\Support\Facades\Facade;

/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'iseed'; }
class Iseed extends Facade
{

}
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'iseed';
}
}
Loading

0 comments on commit 1847f70

Please sign in to comment.