2012-03-10 17:56:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2013-05-23 10:31:59 +02:00
|
|
|
* "class", "interface" and "function" are reserved keywords, so the methods are defined as _class(),
|
|
|
|
* _interface() and _function() in the class and are made available as class(), interface() and function()
|
|
|
|
* through __call() magic.
|
2012-03-11 09:02:52 +01:00
|
|
|
*
|
2013-05-23 10:31:59 +02:00
|
|
|
* @method PHPParser_Builder_Class class(string $name) Creates a class builder.
|
|
|
|
* @method PHPParser_Builder_Function function(string $name) Creates a function builder
|
|
|
|
* @method PHPParser_Builder_Interface interface(string $name) Creates an interface builder.
|
2012-03-10 17:56:56 +01:00
|
|
|
*/
|
|
|
|
class PHPParser_BuilderFactory
|
|
|
|
{
|
2012-03-11 09:02:52 +01:00
|
|
|
/**
|
|
|
|
* Creates a class builder.
|
|
|
|
*
|
|
|
|
* @param string $name Name of the class
|
|
|
|
*
|
|
|
|
* @return PHPParser_Builder_Class The created class builder
|
2012-03-10 17:56:56 +01:00
|
|
|
*/
|
|
|
|
protected function _class($name) {
|
|
|
|
return new PHPParser_Builder_Class($name);
|
|
|
|
}
|
|
|
|
|
2013-05-23 10:31:59 +02:00
|
|
|
/**
|
|
|
|
* Creates a interface builder.
|
|
|
|
*
|
|
|
|
* @param string $name Name of the interface
|
|
|
|
*
|
|
|
|
* @return PHPParser_Builder_Class The created interface builder
|
|
|
|
*/
|
|
|
|
protected function _interface($name) {
|
|
|
|
return new PHPParser_Builder_Interface($name);
|
|
|
|
}
|
|
|
|
|
2012-03-10 23:25:26 +01:00
|
|
|
/**
|
|
|
|
* Creates a method builder.
|
|
|
|
*
|
|
|
|
* @param string $name Name of the method
|
|
|
|
*
|
2012-03-11 00:06:02 +01:00
|
|
|
* @return PHPParser_Builder_Method The created method builder
|
2012-03-10 23:25:26 +01:00
|
|
|
*/
|
|
|
|
public function method($name) {
|
|
|
|
return new PHPParser_Builder_Method($name);
|
|
|
|
}
|
|
|
|
|
2012-03-11 00:06:02 +01:00
|
|
|
/**
|
|
|
|
* Creates a parameter builder.
|
|
|
|
*
|
|
|
|
* @param string $name Name of the parameter
|
|
|
|
*
|
|
|
|
* @return PHPParser_Builder_Param The created parameter builder
|
|
|
|
*/
|
|
|
|
public function param($name) {
|
|
|
|
return new PHPParser_Builder_Param($name);
|
|
|
|
}
|
|
|
|
|
2012-03-11 08:42:13 +01:00
|
|
|
/**
|
|
|
|
* Creates a property builder.
|
|
|
|
*
|
|
|
|
* @param string $name Name of the property
|
|
|
|
*
|
|
|
|
* @return PHPParser_Builder_Property The created property builder
|
|
|
|
*/
|
|
|
|
public function property($name) {
|
|
|
|
return new PHPParser_Builder_Property($name);
|
|
|
|
}
|
|
|
|
|
2012-03-11 09:02:52 +01:00
|
|
|
/**
|
|
|
|
* Creates a function builder.
|
|
|
|
*
|
|
|
|
* @param string $name Name of the function
|
|
|
|
*
|
|
|
|
* @return PHPParser_Builder_Property The created function builder
|
|
|
|
*/
|
|
|
|
protected function _function($name) {
|
|
|
|
return new PHPParser_Builder_Function($name);
|
|
|
|
}
|
|
|
|
|
2012-03-10 17:56:56 +01:00
|
|
|
public function __call($name, array $args) {
|
2013-05-23 10:31:59 +02:00
|
|
|
if (method_exists($this, '_' . $name)) {
|
|
|
|
return call_user_func_array(array($this, '_' . $name), $args);
|
2012-03-10 17:56:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new LogicException(sprintf('Method "%s" does not exist', $name));
|
|
|
|
}
|
|
|
|
}
|