2017-12-04 14:58:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tainacan\Tests\Factories;
|
|
|
|
|
|
|
|
class Field_Factory {
|
|
|
|
private $field;
|
|
|
|
protected $field_type;
|
|
|
|
|
|
|
|
public function create_field($type, $primitive_type = []){
|
|
|
|
if(empty($type)){
|
2017-12-12 14:01:41 +00:00
|
|
|
throw new \InvalidArgumentException('The type can\'t be empty');
|
2017-12-04 14:58:19 +00:00
|
|
|
} elseif(!strrchr($type, '_')){
|
|
|
|
$type = ucfirst(strtolower($type));
|
|
|
|
} else {
|
|
|
|
$type = ucwords(strtolower($type), '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->field_type = "\Tainacan\Field_Types\\$type";
|
|
|
|
$this->field = new $this->field_type(/* Here goes the primitive type */);
|
|
|
|
|
|
|
|
return $this->field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|