89 lines
1.5 KiB
PHP
Raw Normal View History

2020-11-19 09:42:54 +08:00
<?php
2020-11-19 17:31:31 +08:00
namespace catcher\generate\build\classes;
2020-11-19 09:42:54 +08:00
2020-11-19 17:31:31 +08:00
use PhpParser\BuilderFactory;
class Traits
2020-11-19 09:42:54 +08:00
{
2020-11-19 17:31:31 +08:00
protected $traitBuild;
protected $build;
2020-11-19 09:42:54 +08:00
2020-11-19 17:31:31 +08:00
public function use(...$names)
2020-11-19 09:42:54 +08:00
{
2020-11-19 17:31:31 +08:00
$this->build = new BuilderFactory;
$this->traitBuild = call_user_func_array([$this->build, 'useTrait'], $names);
2020-11-19 09:42:54 +08:00
2020-11-19 17:31:31 +08:00
return $this;
}
public function and($name)
{
$this->traitBuild->and($name);
return $this;
}
/**
* with
*
* @time 2020年11月19日
* @param \Closure|null $closure
* @return $this
*/
public function with(\Closure $closure = null)
{
if ($closure instanceof \Closure) {
$this->traitBuild->withe($closure($this));
2020-11-19 09:42:54 +08:00
return $this;
}
2020-11-19 17:31:31 +08:00
return $this;
}
/**
* @time 2020年11月19日
* @param $name
* @param null $method
* @return $this
*/
public function adaptation($name, $method = null)
{
$this->build = $this->build->traitUseAdaptation($name. $method);
2020-11-19 09:42:54 +08:00
return $this;
}
2020-11-19 17:31:31 +08:00
/**
* @time 2020年11月19日
* @param $name
* @return $this
*/
public function as($name)
2020-11-19 09:42:54 +08:00
{
2020-11-19 17:31:31 +08:00
$this->build->as($name);
return $this;
2020-11-19 09:42:54 +08:00
}
2020-11-19 17:31:31 +08:00
/**
* @time 2020年11月19日
* @param $name
* @return $this
*/
2020-11-19 09:42:54 +08:00
public function insteadof($name)
{
2020-11-19 17:31:31 +08:00
$this->build->insteadof($name);
return $this;
2020-11-19 09:42:54 +08:00
}
2020-11-19 17:31:31 +08:00
public function build()
2020-11-19 09:42:54 +08:00
{
2020-11-19 17:31:31 +08:00
return $this->traitBuild;
2020-11-19 09:42:54 +08:00
}
}