1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-13 09:57:25 +01:00
PHP-Parser/lib/PhpParser/BuilderFactory.php

91 lines
2.3 KiB
PHP
Raw Normal View History

2012-03-10 17:56:56 +01:00
<?php
namespace PhpParser;
use PhpParser\Builder;
2012-03-10 17:56:56 +01:00
/**
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
*
* @method Builder\Class_ class(string $name) Creates a class builder.
* @method Builder\Function_ function(string $name) Creates a function builder
* @method Builder\Interface_ interface(string $name) Creates an interface builder.
2012-03-10 17:56:56 +01:00
*/
class BuilderFactory
2012-03-10 17:56:56 +01:00
{
2012-03-11 09:02:52 +01:00
/**
* Creates a class builder.
*
* @param string $name Name of the class
*
* @return Builder\Class_ The created class builder
2012-03-10 17:56:56 +01:00
*/
protected function _class($name) {
return new Builder\Class_($name);
2012-03-10 17:56:56 +01:00
}
2013-05-23 10:31:59 +02:00
/**
* Creates a interface builder.
*
* @param string $name Name of the interface
*
* @return Builder\Interface_ The created interface builder
2013-05-23 10:31:59 +02:00
*/
protected function _interface($name) {
return new Builder\Interface_($name);
2013-05-23 10:31:59 +02:00
}
2012-03-10 23:25:26 +01:00
/**
* Creates a method builder.
*
* @param string $name Name of the method
*
* @return Builder\Method The created method builder
2012-03-10 23:25:26 +01:00
*/
public function method($name) {
return new Builder\Method($name);
2012-03-10 23:25:26 +01:00
}
2012-03-11 00:06:02 +01:00
/**
* Creates a parameter builder.
*
* @param string $name Name of the parameter
*
* @return Builder\Param The created parameter builder
2012-03-11 00:06:02 +01:00
*/
public function param($name) {
return new Builder\Param($name);
2012-03-11 00:06:02 +01:00
}
2012-03-11 08:42:13 +01:00
/**
* Creates a property builder.
*
* @param string $name Name of the property
*
* @return Builder\Property The created property builder
2012-03-11 08:42:13 +01:00
*/
public function property($name) {
return new Builder\Property($name);
2012-03-11 08:42:13 +01:00
}
2012-03-11 09:02:52 +01:00
/**
* Creates a function builder.
*
* @param string $name Name of the function
*
* @return Builder\Function_ The created function builder
2012-03-11 09:02:52 +01:00
*/
protected function _function($name) {
return new Builder\Function_($name);
2012-03-11 09:02:52 +01:00
}
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));
2012-03-10 17:56:56 +01:00
}
}