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 Classes
|
2020-11-19 09:42:54 +08:00
|
|
|
{
|
2020-11-19 17:31:31 +08:00
|
|
|
protected $classBuild;
|
|
|
|
|
|
|
|
public function __construct(string $name)
|
|
|
|
{
|
|
|
|
$this->classBuild = (new BuilderFactory())->class($name);
|
|
|
|
}
|
|
|
|
|
2020-11-19 09:42:54 +08:00
|
|
|
/**
|
2020-11-19 17:31:31 +08:00
|
|
|
* 设置 comment
|
2020-11-19 09:42:54 +08:00
|
|
|
*
|
2020-11-19 17:31:31 +08:00
|
|
|
* @time 2020年11月19日
|
|
|
|
* @param string $comment
|
2020-11-19 09:42:54 +08:00
|
|
|
* @return $this
|
|
|
|
*/
|
2020-11-19 17:31:31 +08:00
|
|
|
public function docComment($comment="\r\n")
|
2020-11-19 09:42:54 +08:00
|
|
|
{
|
2020-11-19 17:31:31 +08:00
|
|
|
$this->classBuild->setDocComment($comment);
|
2020-11-19 09:42:54 +08:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @time 2020年11月17日
|
|
|
|
* @param $extend
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function extend($extend)
|
|
|
|
{
|
2020-11-19 17:31:31 +08:00
|
|
|
$this->classBuild->extend($extend);
|
2020-11-19 09:42:54 +08:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @time 2020年11月17日
|
|
|
|
* @param $interfaces
|
|
|
|
* @return $this
|
|
|
|
*/
|
2020-11-19 17:31:31 +08:00
|
|
|
public function implement($interfaces)
|
2020-11-19 09:42:54 +08:00
|
|
|
{
|
2020-11-19 17:31:31 +08:00
|
|
|
$this->classBuild->implement($interfaces);
|
2020-11-19 09:42:54 +08:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @time 2020年11月17日
|
|
|
|
* @return $this
|
|
|
|
*/
|
2020-11-19 17:31:31 +08:00
|
|
|
public function abstract()
|
2020-11-19 09:42:54 +08:00
|
|
|
{
|
2020-11-19 17:31:31 +08:00
|
|
|
$this->classBuild->makeAbstract();
|
2020-11-19 09:42:54 +08:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @time 2020年11月17日
|
|
|
|
* @return $this
|
|
|
|
*/
|
2020-11-19 17:31:31 +08:00
|
|
|
public function final()
|
2020-11-19 09:42:54 +08:00
|
|
|
{
|
2020-11-19 17:31:31 +08:00
|
|
|
$this->classBuild->makeFinal();
|
2020-11-19 09:42:54 +08:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:31:31 +08:00
|
|
|
public function build()
|
|
|
|
{
|
|
|
|
return $this->classBuild;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addMethod(Methods $method)
|
2020-11-19 09:42:54 +08:00
|
|
|
{
|
2020-11-19 17:31:31 +08:00
|
|
|
$this->classBuild->addStmt($method->build());
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addProperty(Property $property)
|
|
|
|
{
|
|
|
|
$this->classBuild->addStmt($property->build());
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addTrait(Traits $trait)
|
|
|
|
{
|
|
|
|
$this->classBuild->addStmt($trait->build());
|
|
|
|
|
|
|
|
return $this;
|
2020-11-19 09:42:54 +08:00
|
|
|
}
|
|
|
|
}
|