-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from sizuhiko/develop
For release 1.2
- Loading branch information
Showing
17 changed files
with
928 additions
and
159 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,27 @@ | ||
<?php | ||
|
||
/** | ||
* FabricateDefinition class | ||
*/ | ||
class FabricateDefinition { | ||
private $define = false; | ||
public $parent = false; | ||
|
||
/** | ||
* @param mixed $define callback or attributes | ||
*/ | ||
public function __construct($define) { | ||
$this->define = $define; | ||
} | ||
|
||
public function run($data, $world) { | ||
$result = []; | ||
if(is_callable($this->define)) { | ||
$callback = $this->define; | ||
$result = $callback($data, $world); | ||
} else if(is_array($this->define)) { | ||
$result = $this->define; | ||
} | ||
return $result; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ | |
class FabricateConfig { | ||
public $sequence_start = 1; | ||
public $auto_validate = false; | ||
public $filter_key = false; | ||
} |
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
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,59 @@ | ||
<?php | ||
|
||
/** | ||
* Fabricator Registry Class | ||
*/ | ||
class FabricateRegistry { | ||
private $name; | ||
private $items; | ||
|
||
/** | ||
* Construct with registry name | ||
* @param string $name registry name | ||
*/ | ||
public function __construct($name) { | ||
$this->name = $name; | ||
$this->items = []; | ||
} | ||
|
||
/** | ||
* Clear registerd entries | ||
*/ | ||
public function clear() { | ||
$this->items = []; | ||
} | ||
|
||
/** | ||
* Find from registred or model by name | ||
* @param string $name | ||
* @return mixed registerd object | ||
*/ | ||
public function find($name) { | ||
if($this->is_registered($name)) { | ||
return $this->items[$name]; | ||
} | ||
$model = ClassRegistry::init($name, true); | ||
if($model) { | ||
return $model; | ||
} | ||
throw new InvalidArgumentException("{$name} not registered"); | ||
} | ||
|
||
/** | ||
* Regist to registries | ||
* @param string $name | ||
* @param FabricateDefinition $item | ||
*/ | ||
public function register($name, $item) { | ||
$this->items[$name] = $item; | ||
} | ||
|
||
/** | ||
* Is registered? | ||
* @param string $name | ||
* @return boolean | ||
*/ | ||
public function is_registered($name) { | ||
return array_key_exists($name, $this->items); | ||
} | ||
} |
Oops, something went wrong.