import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
147
libs/Zend/CodeGenerator/Abstract.php
Normal file
147
libs/Zend/CodeGenerator/Abstract.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_CodeGenerator_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_sourceContent = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isSourceDirty = true;
|
||||
|
||||
/**
|
||||
* __construct()
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
$this->_init();
|
||||
if ($options != null) {
|
||||
// use Zend_Config objects if provided
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
// pass arrays to setOptions
|
||||
if (is_array($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
$this->_prepare();
|
||||
}
|
||||
|
||||
/**
|
||||
* setConfig()
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @return Zend_CodeGenerator_Abstract
|
||||
*/
|
||||
public function setConfig(Zend_Config $config)
|
||||
{
|
||||
$this->setOptions($config->toArray());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setOptions()
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_CodeGenerator_Abstract
|
||||
*/
|
||||
public function setOptions(Array $options)
|
||||
{
|
||||
foreach ($options as $optionName => $optionValue) {
|
||||
$methodName = 'set' . $optionName;
|
||||
if (method_exists($this, $methodName)) {
|
||||
$this->{$methodName}($optionValue);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setSourceContent()
|
||||
*
|
||||
* @param string $sourceContent
|
||||
*/
|
||||
public function setSourceContent($sourceContent)
|
||||
{
|
||||
$this->_sourceContent = $sourceContent;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* getSourceContent()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSourceContent()
|
||||
{
|
||||
return $this->_sourceContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* _init() - this is called before the constuctor
|
||||
*
|
||||
*/
|
||||
protected function _init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* _prepare() - this is called at construction completion
|
||||
*
|
||||
*/
|
||||
protected function _prepare()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* generate() - must be implemented by the child
|
||||
*
|
||||
*/
|
||||
abstract public function generate();
|
||||
|
||||
/**
|
||||
* __toString() - casting to a string will in turn call generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final public function __toString()
|
||||
{
|
||||
return $this->generate();
|
||||
}
|
||||
|
||||
}
|
35
libs/Zend/CodeGenerator/Exception.php
Normal file
35
libs/Zend/CodeGenerator/Exception.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Exception extends Zend_Exception
|
||||
{}
|
91
libs/Zend/CodeGenerator/Php/Abstract.php
Normal file
91
libs/Zend/CodeGenerator/Php/Abstract.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_CodeGenerator_Php_Abstract extends Zend_CodeGenerator_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isSourceDirty = true;
|
||||
|
||||
/**
|
||||
* @var int|string
|
||||
*/
|
||||
protected $_indentation = ' ';
|
||||
|
||||
/**
|
||||
* setSourceDirty()
|
||||
*
|
||||
* @param bool $isSourceDirty
|
||||
* @return Zend_CodeGenerator_Php_Abstract
|
||||
*/
|
||||
public function setSourceDirty($isSourceDirty = true)
|
||||
{
|
||||
$this->_isSourceDirty = ($isSourceDirty) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* isSourceDirty()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSourceDirty()
|
||||
{
|
||||
return $this->_isSourceDirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* setIndentation()
|
||||
*
|
||||
* @param string|int $indentation
|
||||
* @return Zend_CodeGenerator_Php_Abstract
|
||||
*/
|
||||
public function setIndentation($indentation)
|
||||
{
|
||||
$this->_indentation = $indentation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getIndentation()
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function getIndentation()
|
||||
{
|
||||
return $this->_indentation;
|
||||
}
|
||||
|
||||
}
|
73
libs/Zend/CodeGenerator/Php/Body.php
Normal file
73
libs/Zend/CodeGenerator/Php/Body.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Body extends Zend_CodeGenerator_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_content = null;
|
||||
|
||||
/**
|
||||
* setContent()
|
||||
*
|
||||
* @param string $content
|
||||
* @return Zend_CodeGenerator_Php_Body
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->_content = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getContent()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return (string) $this->_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
return $this->getContent();
|
||||
}
|
||||
}
|
497
libs/Zend/CodeGenerator/Php/Class.php
Normal file
497
libs/Zend/CodeGenerator/Php/Class.php
Normal file
@ -0,0 +1,497 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Member_Container
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Member/Container.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Method
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Method.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Property
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Property.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Docblock.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
protected $_docblock = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isAbstract = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_extendedClass = null;
|
||||
|
||||
/**
|
||||
* @var array Array of string names
|
||||
*/
|
||||
protected $_implementedInterfaces = array();
|
||||
|
||||
/**
|
||||
* @var array Array of properties
|
||||
*/
|
||||
protected $_properties = null;
|
||||
|
||||
/**
|
||||
* @var array Array of methods
|
||||
*/
|
||||
protected $_methods = null;
|
||||
|
||||
/**
|
||||
* fromReflection() - build a Code Generation PHP Object from a Class Reflection
|
||||
*
|
||||
* @param Zend_Reflection_Class $reflectionClass
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Class $reflectionClass)
|
||||
{
|
||||
$class = new self();
|
||||
|
||||
$class->setSourceContent($class->getSourceContent());
|
||||
$class->setSourceDirty(false);
|
||||
|
||||
if ($reflectionClass->getDocComment() != '') {
|
||||
$class->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($reflectionClass->getDocblock()));
|
||||
}
|
||||
|
||||
$class->setAbstract($reflectionClass->isAbstract());
|
||||
$class->setName($reflectionClass->getName());
|
||||
|
||||
if ($parentClass = $reflectionClass->getParentClass()) {
|
||||
$class->setExtendedClass($parentClass->getName());
|
||||
$interfaces = array_diff($parentClass->getInterfaces(), $reflectionClass->getInterfaces());
|
||||
} else {
|
||||
$interfaces = $reflectionClass->getInterfaces();
|
||||
}
|
||||
|
||||
$class->setImplementedInterfaces($interfaces);
|
||||
|
||||
$properties = array();
|
||||
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
|
||||
if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) {
|
||||
$properties[] = Zend_CodeGenerator_Php_Property::fromReflection($reflectionProperty);
|
||||
}
|
||||
}
|
||||
$class->setProperties($properties);
|
||||
|
||||
$methods = array();
|
||||
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
|
||||
if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) {
|
||||
$methods[] = Zend_CodeGenerator_Php_Method::fromReflection($reflectionMethod);
|
||||
}
|
||||
}
|
||||
$class->setMethods($methods);
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDocblock() Set the docblock
|
||||
*
|
||||
* @param Zend_CodeGenerator_Php_Docblock|array|string $docblock
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public function setDocblock($docblock)
|
||||
{
|
||||
if (is_string($docblock)) {
|
||||
$docblock = array('shortDescription' => $docblock);
|
||||
}
|
||||
|
||||
if (is_array($docblock)) {
|
||||
$docblock = new Zend_CodeGenerator_Php_Docblock($docblock);
|
||||
} elseif (!$docblock instanceof Zend_CodeGenerator_Php_Docblock) {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('setDocblock() is expecting either a string, array or an instance of Zend_CodeGenerator_Php_Docblock');
|
||||
}
|
||||
|
||||
$this->_docblock = $docblock;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDocblock()
|
||||
*
|
||||
* @return Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
public function getDocblock()
|
||||
{
|
||||
return $this->_docblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* setName()
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getName()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* setAbstract()
|
||||
*
|
||||
* @param bool $isAbstract
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function setAbstract($isAbstract)
|
||||
{
|
||||
$this->_isAbstract = ($isAbstract) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* isAbstract()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAbstract()
|
||||
{
|
||||
return $this->_isAbstract;
|
||||
}
|
||||
|
||||
/**
|
||||
* setExtendedClass()
|
||||
*
|
||||
* @param string $extendedClass
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function setExtendedClass($extendedClass)
|
||||
{
|
||||
$this->_extendedClass = $extendedClass;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getExtendedClass()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExtendedClass()
|
||||
{
|
||||
return $this->_extendedClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* setImplementedInterfaces()
|
||||
*
|
||||
* @param array $implementedInterfaces
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function setImplementedInterfaces(Array $implementedInterfaces)
|
||||
{
|
||||
$this->_implementedInterfaces = $implementedInterfaces;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getImplementedInterfaces
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImplementedInterfaces()
|
||||
{
|
||||
return $this->_implementedInterfaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* setProperties()
|
||||
*
|
||||
* @param array $properties
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function setProperties(Array $properties)
|
||||
{
|
||||
foreach ($properties as $property) {
|
||||
$this->setProperty($property);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setProperty()
|
||||
*
|
||||
* @param array|Zend_CodeGenerator_Php_Property $property
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function setProperty($property)
|
||||
{
|
||||
if (is_array($property)) {
|
||||
$property = new Zend_CodeGenerator_Php_Property($property);
|
||||
$propertyName = $property->getName();
|
||||
} elseif ($property instanceof Zend_CodeGenerator_Php_Property) {
|
||||
$propertyName = $property->getName();
|
||||
} else {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('setProperty() expects either an array of property options or an instance of Zend_CodeGenerator_Php_Property');
|
||||
}
|
||||
|
||||
if (isset($this->_properties[$propertyName])) {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('A property by name ' . $propertyName . ' already exists in this class.');
|
||||
}
|
||||
|
||||
$this->_properties->append($property);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getProperties()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->_properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* getProperty()
|
||||
*
|
||||
* @param string $propertyName
|
||||
* @return Zend_CodeGenerator_Php_Property
|
||||
*/
|
||||
public function getProperty($propertyName)
|
||||
{
|
||||
foreach ($this->_properties as $property) {
|
||||
if ($property->getName() == $propertyName) {
|
||||
return $property;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* setMethods()
|
||||
*
|
||||
* @param array $methods
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function setMethods(Array $methods)
|
||||
{
|
||||
foreach ($methods as $method) {
|
||||
$this->setMethod($method);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setMethod()
|
||||
*
|
||||
* @param array|Zend_CodeGenerator_Php_Method $method
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
if (is_array($method)) {
|
||||
$method = new Zend_CodeGenerator_Php_Method($method);
|
||||
$methodName = $method->getName();
|
||||
} elseif ($method instanceof Zend_CodeGenerator_Php_Method) {
|
||||
$methodName = $method->getName();
|
||||
} else {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('setMethod() expects either an array of method options or an instance of Zend_CodeGenerator_Php_Method');
|
||||
}
|
||||
|
||||
if (isset($this->_methods[$methodName])) {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('A method by name ' . $methodName . ' already exists in this class.');
|
||||
}
|
||||
|
||||
$this->_methods->append($method);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getMethods()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMethods()
|
||||
{
|
||||
return $this->_methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* getMethod()
|
||||
*
|
||||
* @param string $methodName
|
||||
* @return Zend_CodeGenerator_Php_Method
|
||||
*/
|
||||
public function getMethod($methodName)
|
||||
{
|
||||
foreach ($this->_methods as $method) {
|
||||
if ($method->getName() == $methodName) {
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* hasMethod()
|
||||
*
|
||||
* @param string $methodName
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMethod($methodName)
|
||||
{
|
||||
return isset($this->_methods[$methodName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* isSourceDirty()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSourceDirty()
|
||||
{
|
||||
if (($docblock = $this->getDocblock()) && $docblock->isSourceDirty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->_properties as $property) {
|
||||
if ($property->isSourceDirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->_methods as $method) {
|
||||
if ($method->isSourceDirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::isSourceDirty();
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
if (!$this->isSourceDirty()) {
|
||||
return $this->getSourceContent();
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
if (null !== ($docblock = $this->getDocblock())) {
|
||||
$docblock->setIndentation('');
|
||||
$output .= $docblock->generate();
|
||||
}
|
||||
|
||||
if ($this->isAbstract()) {
|
||||
$output .= 'abstract ';
|
||||
}
|
||||
|
||||
$output .= 'class ' . $this->getName();
|
||||
|
||||
if (null !== ($ec = $this->_extendedClass)) {
|
||||
$output .= ' extends ' . $ec;
|
||||
}
|
||||
|
||||
$implemented = $this->getImplementedInterfaces();
|
||||
if (!empty($implemented)) {
|
||||
$output .= ' implements ' . implode(', ', $implemented);
|
||||
}
|
||||
|
||||
$output .= PHP_EOL . '{' . PHP_EOL . PHP_EOL;
|
||||
|
||||
$properties = $this->getProperties();
|
||||
if (!empty($properties)) {
|
||||
foreach ($properties as $property) {
|
||||
$output .= $property->generate() . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$methods = $this->getMethods();
|
||||
if (!empty($methods)) {
|
||||
foreach ($methods as $method) {
|
||||
$output .= $method->generate() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$output .= PHP_EOL . '}' . PHP_EOL;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* _init() - is called at construction time
|
||||
*
|
||||
*/
|
||||
protected function _init()
|
||||
{
|
||||
$this->_properties = new Zend_CodeGenerator_Php_Member_Container(Zend_CodeGenerator_Php_Member_Container::TYPE_PROPERTY);
|
||||
$this->_methods = new Zend_CodeGenerator_Php_Member_Container(Zend_CodeGenerator_Php_Member_Container::TYPE_METHOD);
|
||||
}
|
||||
|
||||
}
|
220
libs/Zend/CodeGenerator/Php/Docblock.php
Normal file
220
libs/Zend/CodeGenerator/Php/Docblock.php
Normal file
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Docblock_Tag
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Docblock/Tag.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Docblock extends Zend_CodeGenerator_Php_Abstract
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_shortDescription = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_longDescription = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_tags = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_indentation = '';
|
||||
|
||||
/**
|
||||
* fromReflection() - Build a docblock generator object from a reflection object
|
||||
*
|
||||
* @param Zend_Reflection_Docblock $reflectionDocblock
|
||||
* @return Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Docblock $reflectionDocblock)
|
||||
{
|
||||
$docblock = new self();
|
||||
|
||||
$docblock->setSourceContent($reflectionDocblock->getContents());
|
||||
$docblock->setSourceDirty(false);
|
||||
|
||||
$docblock->setShortDescription($reflectionDocblock->getShortDescription());
|
||||
$docblock->setLongDescription($reflectionDocblock->getLongDescription());
|
||||
|
||||
foreach ($reflectionDocblock->getTags() as $tag) {
|
||||
$docblock->setTag(Zend_CodeGenerator_Php_Docblock_Tag::fromReflection($tag));
|
||||
}
|
||||
|
||||
return $docblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* setShortDescription()
|
||||
*
|
||||
* @param string $shortDescription
|
||||
* @return Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
public function setShortDescription($shortDescription)
|
||||
{
|
||||
$this->_shortDescription = $shortDescription;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getShortDescription()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShortDescription()
|
||||
{
|
||||
return $this->_shortDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* setLongDescription()
|
||||
*
|
||||
* @param string $longDescription
|
||||
* @return Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
public function setLongDescription($longDescription)
|
||||
{
|
||||
$this->_longDescription = $longDescription;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getLongDescription()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLongDescription()
|
||||
{
|
||||
return $this->_longDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* setTags()
|
||||
*
|
||||
* @param array $tags
|
||||
* @return Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
public function setTags(Array $tags)
|
||||
{
|
||||
foreach ($tags as $tag) {
|
||||
$this->setTag($tag);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setTag()
|
||||
*
|
||||
* @param array|Zend_CodeGenerator_Php_Docblock_Tag $tag
|
||||
* @return Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
public function setTag($tag)
|
||||
{
|
||||
if (is_array($tag)) {
|
||||
$tag = new Zend_CodeGenerator_Php_Docblock_Tag($tag);
|
||||
} elseif (!$tag instanceof Zend_CodeGenerator_Php_Docblock_Tag) {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception(
|
||||
'setTag() expects either an array of method options or an '
|
||||
. 'instance of Zend_CodeGenerator_Php_Docblock_Tag'
|
||||
);
|
||||
}
|
||||
|
||||
$this->_tags[] = $tag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getTags
|
||||
*
|
||||
* @return array Array of Zend_CodeGenerator_Php_Docblock_Tag
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->_tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
if (!$this->isSourceDirty()) {
|
||||
return $this->_docCommentize($this->getSourceContent());
|
||||
}
|
||||
|
||||
$output = '';
|
||||
if (null !== ($sd = $this->getShortDescription())) {
|
||||
$output .= $sd . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
if (null !== ($ld = $this->getLongDescription())) {
|
||||
$output .= $ld . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
foreach ($this->getTags() as $tag) {
|
||||
$output .= $tag->generate();
|
||||
}
|
||||
|
||||
return $this->_docCommentize(trim($output));
|
||||
}
|
||||
|
||||
/**
|
||||
* _docCommentize()
|
||||
*
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
protected function _docCommentize($content)
|
||||
{
|
||||
$indent = $this->getIndentation();
|
||||
$output = '/**' . PHP_EOL;
|
||||
$content = wordwrap($content, 80, "\n");
|
||||
$lines = explode("\n", $content);
|
||||
foreach ($lines as $line) {
|
||||
$output .= $indent . ' * ' . $line . PHP_EOL;
|
||||
}
|
||||
$output .= $indent . ' */' . PHP_EOL;
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
184
libs/Zend/CodeGenerator/Php/Docblock/Tag.php
Normal file
184
libs/Zend/CodeGenerator/Php/Docblock/Tag.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Docblock_Tag_Param
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Docblock/Tag/Param.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Docblock_Tag_Return
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Docblock/Tag/Return.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Docblock_Tag extends Zend_CodeGenerator_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Zend_Loader_PluginLoader
|
||||
*/
|
||||
protected static $_pluginLoader = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_description = null;
|
||||
|
||||
/**
|
||||
* fromReflection()
|
||||
*
|
||||
* @param Zend_Reflection_Docblock_Tag $reflectionTag
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Docblock_Tag $reflectionTag)
|
||||
{
|
||||
$tagName = $reflectionTag->getName();
|
||||
|
||||
$codeGenDocblockTag = self::factory($tagName);
|
||||
|
||||
// transport any properties via accessors and mutators from reflection to codegen object
|
||||
$reflectionClass = new ReflectionClass($reflectionTag);
|
||||
foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
|
||||
if (substr($method->getName(), 0, 3) == 'get') {
|
||||
$propertyName = substr($method->getName(), 3);
|
||||
if (method_exists($codeGenDocblockTag, 'set' . $propertyName)) {
|
||||
$codeGenDocblockTag->{'set' . $propertyName}($reflectionTag->{'get' . $propertyName}());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $codeGenDocblockTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* setPluginLoader()
|
||||
*
|
||||
* @param Zend_Loader_PluginLoader $pluginLoader
|
||||
*/
|
||||
public static function setPluginLoader(Zend_Loader_PluginLoader $pluginLoader)
|
||||
{
|
||||
self::$_pluginLoader = $pluginLoader;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPluginLoader()
|
||||
*
|
||||
* @return Zend_Loader_PluginLoader
|
||||
*/
|
||||
public static function getPluginLoader()
|
||||
{
|
||||
if (self::$_pluginLoader == null) {
|
||||
require_once 'Zend/Loader/PluginLoader.php';
|
||||
self::setPluginLoader(new Zend_Loader_PluginLoader(array(
|
||||
'Zend_CodeGenerator_Php_Docblock_Tag' => dirname(__FILE__) . '/Tag/'))
|
||||
);
|
||||
}
|
||||
|
||||
return self::$_pluginLoader;
|
||||
}
|
||||
|
||||
public static function factory($tagName)
|
||||
{
|
||||
$pluginLoader = self::getPluginLoader();
|
||||
|
||||
try {
|
||||
$tagClass = $pluginLoader->load($tagName);
|
||||
} catch (Zend_Loader_Exception $exception) {
|
||||
$tagClass = 'Zend_CodeGenerator_Php_Docblock_Tag';
|
||||
}
|
||||
|
||||
$tag = new $tagClass(array('name' => $tagName));
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* setName()
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = ltrim($name, '@');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getName()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDescription()
|
||||
*
|
||||
* @param string $description
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->_description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDescription()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
return '@' . $this->_name . ' ' . $this->_description . PHP_EOL;
|
||||
}
|
||||
|
||||
}
|
98
libs/Zend/CodeGenerator/Php/Docblock/Tag/License.php
Normal file
98
libs/Zend/CodeGenerator/Php/Docblock/Tag/License.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Docblock_Tag
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Docblock/Tag.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Docblock_Tag_License extends Zend_CodeGenerator_Php_Docblock_Tag
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_url = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_description = null;
|
||||
|
||||
/**
|
||||
* fromReflection()
|
||||
*
|
||||
* @param Zend_Reflection_Docblock_Tag $reflectionTagReturn
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag_License
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Docblock_Tag $reflectionTagLicense)
|
||||
{
|
||||
$returnTag = new self();
|
||||
|
||||
$returnTag->setName('license');
|
||||
$returnTag->setUrl($reflectionTagLicense->getUrl());
|
||||
$returnTag->setDescription($reflectionTagLicense->getDescription());
|
||||
|
||||
return $returnTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* setUrl()
|
||||
*
|
||||
* @param string $url
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag_License
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->_url = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getUrl()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->_url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$output = '@license ' . $this->_url . ' ' . $this->_description . PHP_EOL;
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
125
libs/Zend/CodeGenerator/Php/Docblock/Tag/Param.php
Normal file
125
libs/Zend/CodeGenerator/Php/Docblock/Tag/Param.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Docblock_Tag
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Docblock/Tag.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Docblock_Tag_Param extends Zend_CodeGenerator_Php_Docblock_Tag
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_datatype = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_paramName = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_description = null;
|
||||
|
||||
/**
|
||||
* fromReflection()
|
||||
*
|
||||
* @param Zend_Reflection_Docblock_Tag $reflectionTagParam
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag_Param
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Docblock_Tag $reflectionTagParam)
|
||||
{
|
||||
$paramTag = new self();
|
||||
|
||||
$paramTag->setName('param');
|
||||
$paramTag->setDatatype($reflectionTagParam->getType()); // @todo rename
|
||||
$paramTag->setParamName($reflectionTagParam->getVariableName());
|
||||
$paramTag->setDescription($reflectionTagParam->getDescription());
|
||||
|
||||
return $paramTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDatatype()
|
||||
*
|
||||
* @param string $datatype
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag_Param
|
||||
*/
|
||||
public function setDatatype($datatype)
|
||||
{
|
||||
$this->_datatype = $datatype;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDatatype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDatatype()
|
||||
{
|
||||
return $this->_datatype;
|
||||
}
|
||||
|
||||
/**
|
||||
* setParamName()
|
||||
*
|
||||
* @param string $paramName
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag_Param
|
||||
*/
|
||||
public function setParamName($paramName)
|
||||
{
|
||||
$this->_paramName = $paramName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getParamName()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getParamName()
|
||||
{
|
||||
return $this->_paramName;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$output = '@param ' . $this->_datatype . ' ' . $this->_paramName . ' ' . $this->_description . PHP_EOL;
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
98
libs/Zend/CodeGenerator/Php/Docblock/Tag/Return.php
Normal file
98
libs/Zend/CodeGenerator/Php/Docblock/Tag/Return.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Docblock_Tag
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Docblock/Tag.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Docblock_Tag_Return extends Zend_CodeGenerator_Php_Docblock_Tag
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_datatype = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_description = null;
|
||||
|
||||
/**
|
||||
* fromReflection()
|
||||
*
|
||||
* @param Zend_Reflection_Docblock_Tag $reflectionTagReturn
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag_Return
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Docblock_Tag $reflectionTagReturn)
|
||||
{
|
||||
$returnTag = new self();
|
||||
|
||||
$returnTag->setName('return');
|
||||
$returnTag->setDatatype($reflectionTagReturn->getType()); // @todo rename
|
||||
$returnTag->setDescription($reflectionTagReturn->getDescription());
|
||||
|
||||
return $returnTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDatatype()
|
||||
*
|
||||
* @param string $datatype
|
||||
* @return Zend_CodeGenerator_Php_Docblock_Tag_Return
|
||||
*/
|
||||
public function setDatatype($datatype)
|
||||
{
|
||||
$this->_datatype = $datatype;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDatatype()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDatatype()
|
||||
{
|
||||
return $this->_datatype;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$output = '@return ' . $this->_datatype . ' ' . $this->_description . PHP_EOL;
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
37
libs/Zend/CodeGenerator/Php/Exception.php
Normal file
37
libs/Zend/CodeGenerator/Php/Exception.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Exception
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Exception extends Zend_CodeGenerator_Exception
|
||||
{
|
||||
|
||||
}
|
465
libs/Zend/CodeGenerator/Php/File.php
Normal file
465
libs/Zend/CodeGenerator/Php/File.php
Normal file
@ -0,0 +1,465 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Class.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array Array of Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
protected static $_fileCodeGenerators = array();
|
||||
|
||||
/**#@+
|
||||
* @var string
|
||||
*/
|
||||
protected static $_markerDocblock = '/* Zend_CodeGenerator_Php_File-DocblockMarker */';
|
||||
protected static $_markerRequire = '/* Zend_CodeGenerator_Php_File-RequireMarker: {?} */';
|
||||
protected static $_markerClass = '/* Zend_CodeGenerator_Php_File-ClassMarker: {?} */';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_filename = null;
|
||||
|
||||
/**
|
||||
* @var Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
protected $_docblock = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_requiredFiles = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_classes = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_body = null;
|
||||
|
||||
public static function registerFileCodeGenerator(Zend_CodeGenerator_Php_File $fileCodeGenerator, $fileName = null)
|
||||
{
|
||||
if ($fileName == null) {
|
||||
$fileName = $fileCodeGenerator->getFilename();
|
||||
}
|
||||
|
||||
if ($fileName == '') {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('FileName does not exist.');
|
||||
}
|
||||
|
||||
// cannot use realpath since the file might not exist, but we do need to have the index
|
||||
// in the same DIRECTORY_SEPARATOR that realpath would use:
|
||||
$fileName = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $fileName);
|
||||
|
||||
self::$_fileCodeGenerators[$fileName] = $fileCodeGenerator;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* fromReflectedFilePath() - use this if you intend on generating code generation objects based on the same file.
|
||||
* This will keep previous changes to the file in tact during the same PHP process
|
||||
*
|
||||
* @param string $filePath
|
||||
* @param bool $usePreviousCodeGeneratorIfItExists
|
||||
* @param bool $includeIfNotAlreadyIncluded
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public static function fromReflectedFileName($filePath, $usePreviousCodeGeneratorIfItExists = true, $includeIfNotAlreadyIncluded = true)
|
||||
{
|
||||
$realpath = realpath($filePath);
|
||||
|
||||
if ($realpath === false) {
|
||||
if ( ($realpath = Zend_Reflection_file::findRealpathInIncludePath($filePath)) === false) {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('No file for ' . $realpath . ' was found.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($usePreviousCodeGeneratorIfItExists && isset(self::$_fileCodeGenerators[$realpath])) {
|
||||
return self::$_fileCodeGenerators[$realpath];
|
||||
}
|
||||
|
||||
if ($includeIfNotAlreadyIncluded && !in_array($realpath, get_included_files())) {
|
||||
include $realpath;
|
||||
}
|
||||
|
||||
$codeGenerator = self::fromReflection(($fileReflector = new Zend_Reflection_File($realpath)));
|
||||
|
||||
if (!isset(self::$_fileCodeGenerators[$fileReflector->getFileName()])) {
|
||||
self::$_fileCodeGenerators[$fileReflector->getFileName()] = $codeGenerator;
|
||||
}
|
||||
|
||||
return $codeGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* fromReflection()
|
||||
*
|
||||
* @param Zend_Reflection_File $reflectionFile
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_File $reflectionFile)
|
||||
{
|
||||
$file = new self();
|
||||
|
||||
$file->setSourceContent($reflectionFile->getContents());
|
||||
$file->setSourceDirty(false);
|
||||
|
||||
$body = $reflectionFile->getContents();
|
||||
|
||||
// @todo this whole area needs to be reworked with respect to how body lines are processed
|
||||
foreach ($reflectionFile->getClasses() as $class) {
|
||||
$file->setClass(Zend_CodeGenerator_Php_Class::fromReflection($class));
|
||||
$classStartLine = $class->getStartLine(true);
|
||||
$classEndLine = $class->getEndLine();
|
||||
|
||||
$bodyLines = explode("\n", $body);
|
||||
$bodyReturn = array();
|
||||
for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) {
|
||||
if ($lineNum == $classStartLine) {
|
||||
$bodyReturn[] = str_replace('?', $class->getName(), self::$_markerClass); //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */';
|
||||
$lineNum = $classEndLine;
|
||||
} else {
|
||||
$bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion
|
||||
}
|
||||
}
|
||||
$body = implode("\n", $bodyReturn);
|
||||
unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine);
|
||||
}
|
||||
|
||||
if (($reflectionFile->getDocComment() != '')) {
|
||||
$docblock = $reflectionFile->getDocblock();
|
||||
$file->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($docblock));
|
||||
|
||||
$bodyLines = explode("\n", $body);
|
||||
$bodyReturn = array();
|
||||
for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) {
|
||||
if ($lineNum == $docblock->getStartLine()) {
|
||||
$bodyReturn[] = str_replace('?', $class->getName(), self::$_markerDocblock); //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */';
|
||||
$lineNum = $docblock->getEndLine();
|
||||
} else {
|
||||
$bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion
|
||||
}
|
||||
}
|
||||
$body = implode("\n", $bodyReturn);
|
||||
unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine);
|
||||
}
|
||||
|
||||
$file->setBody($body);
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDocblock() Set the docblock
|
||||
*
|
||||
* @param Zend_CodeGenerator_Php_Docblock|array|string $docblock
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public function setDocblock($docblock)
|
||||
{
|
||||
if (is_string($docblock)) {
|
||||
$docblock = array('shortDescription' => $docblock);
|
||||
}
|
||||
|
||||
if (is_array($docblock)) {
|
||||
$docblock = new Zend_CodeGenerator_Php_Docblock($docblock);
|
||||
} elseif (!$docblock instanceof Zend_CodeGenerator_Php_Docblock) {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('setDocblock() is expecting either a string, array or an instance of Zend_CodeGenerator_Php_Docblock');
|
||||
}
|
||||
|
||||
$this->_docblock = $docblock;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get docblock
|
||||
*
|
||||
* @return Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
public function getDocblock()
|
||||
{
|
||||
return $this->_docblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* setRequiredFiles
|
||||
*
|
||||
* @param array $requiredFiles
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public function setRequiredFiles($requiredFiles)
|
||||
{
|
||||
$this->_requiredFiles = $requiredFiles;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getRequiredFiles()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRequiredFiles()
|
||||
{
|
||||
return $this->_requiredFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* setClasses()
|
||||
*
|
||||
* @param array $classes
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public function setClasses(Array $classes)
|
||||
{
|
||||
foreach ($classes as $class) {
|
||||
$this->setClass($class);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getClass()
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function getClass($name = null)
|
||||
{
|
||||
if ($name == null) {
|
||||
reset($this->_classes);
|
||||
return current($this->_classes);
|
||||
}
|
||||
|
||||
return $this->_classes[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* setClass()
|
||||
*
|
||||
* @param Zend_CodeGenerator_Php_Class|array $class
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public function setClass($class)
|
||||
{
|
||||
if (is_array($class)) {
|
||||
$class = new Zend_CodeGenerator_Php_Class($class);
|
||||
$className = $class->getName();
|
||||
} elseif ($class instanceof Zend_CodeGenerator_Php_Class) {
|
||||
$className = $class->getName();
|
||||
} else {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('Expecting either an array or an instance of Zend_CodeGenerator_Php_Class');
|
||||
}
|
||||
|
||||
// @todo check for dup here
|
||||
|
||||
$this->_classes[$className] = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setFilename()
|
||||
*
|
||||
* @param string $filename
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public function setFilename($filename)
|
||||
{
|
||||
$this->_filename = $filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getFilename()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->_filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* getClasses()
|
||||
*
|
||||
* @return array Array of Zend_CodeGenerator_Php_Class
|
||||
*/
|
||||
public function getClasses()
|
||||
{
|
||||
return $this->_classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* setBody()
|
||||
*
|
||||
* @param string $body
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->_body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getBody()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->_body;
|
||||
}
|
||||
|
||||
/**
|
||||
* isSourceDirty()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSourceDirty()
|
||||
{
|
||||
if (($docblock = $this->getDocblock()) && $docblock->isSourceDirty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->_classes as $class) {
|
||||
if ($class->isSourceDirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::isSourceDirty();
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
if ($this->isSourceDirty() === false) {
|
||||
return $this->_sourceContent;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
// start with the body (if there), or open tag
|
||||
if (preg_match('#(?:\s*)<\?php#', $this->getBody()) == false) {
|
||||
$output = '<?php' . PHP_EOL;
|
||||
}
|
||||
|
||||
// if there are markers, put the body into the output
|
||||
$body = $this->getBody();
|
||||
if (preg_match('#/\* Zend_CodeGenerator_Php_File-(.*?)Marker:#', $body)) {
|
||||
$output .= $body;
|
||||
$body = '';
|
||||
}
|
||||
|
||||
// Add file docblock, if any
|
||||
if (null !== ($docblock = $this->getDocblock())) {
|
||||
$docblock->setIndentation('');
|
||||
$regex = preg_quote(self::$_markerDocblock, '#');
|
||||
if (preg_match('#'.$regex.'#', $output)) {
|
||||
$output = preg_replace('#'.$regex.'#', $docblock->generate(), $output, 1);
|
||||
} else {
|
||||
$output .= $docblock->generate() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
// newline
|
||||
$output .= PHP_EOL;
|
||||
|
||||
// process required files
|
||||
// @todo marker replacement for required files
|
||||
$requiredFiles = $this->getRequiredFiles();
|
||||
if (!empty($requiredFiles)) {
|
||||
foreach ($requiredFiles as $requiredFile) {
|
||||
$output .= 'require_once \'' . $requiredFile . '\';' . PHP_EOL;
|
||||
}
|
||||
|
||||
$output .= PHP_EOL;
|
||||
}
|
||||
|
||||
// process classes
|
||||
$classes = $this->getClasses();
|
||||
if (!empty($classes)) {
|
||||
foreach ($classes as $class) {
|
||||
$regex = str_replace('?', $class->getName(), self::$_markerClass);
|
||||
$regex = preg_quote($regex, '#');
|
||||
if (preg_match('#'.$regex.'#', $output)) {
|
||||
$output = preg_replace('#'.$regex.'#', $class->generate(), $output, 1);
|
||||
} else {
|
||||
$output .= $class->generate() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!empty($body)) {
|
||||
|
||||
// add an extra space betwee clsses and
|
||||
if (!empty($classes)) {
|
||||
$output .= PHP_EOL;
|
||||
}
|
||||
|
||||
$output .= $body;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function write()
|
||||
{
|
||||
if ($this->_filename == '' || !is_writable(dirname($this->_filename))) {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('This code generator object is not writable.');
|
||||
}
|
||||
file_put_contents($this->_filename, $this->generate());
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
184
libs/Zend/CodeGenerator/Php/Member/Abstract.php
Normal file
184
libs/Zend/CodeGenerator/Php/Member/Abstract.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_CodeGenerator_Php_Member_Abstract extends Zend_CodeGenerator_Php_Abstract
|
||||
{
|
||||
/**#@+
|
||||
* @param const string
|
||||
*/
|
||||
const VISIBILITY_PUBLIC = 'public';
|
||||
const VISIBILITY_PROTECTED = 'protected';
|
||||
const VISIBILITY_PRIVATE = 'private';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isAbstract = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isStatic = false;
|
||||
|
||||
/**
|
||||
* @var const
|
||||
*/
|
||||
protected $_visibility = self::VISIBILITY_PUBLIC;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = null;
|
||||
|
||||
/**
|
||||
* setDocblock() Set the docblock
|
||||
*
|
||||
* @param Zend_CodeGenerator_Php_Docblock|array|string $docblock
|
||||
* @return Zend_CodeGenerator_Php_File
|
||||
*/
|
||||
public function setDocblock($docblock)
|
||||
{
|
||||
if (is_string($docblock)) {
|
||||
$docblock = array('shortDescription' => $docblock);
|
||||
}
|
||||
|
||||
if (is_array($docblock)) {
|
||||
$docblock = new Zend_CodeGenerator_Php_Docblock($docblock);
|
||||
} elseif (!$docblock instanceof Zend_CodeGenerator_Php_Docblock) {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('setDocblock() is expecting either a string, array or an instance of Zend_CodeGenerator_Php_Docblock');
|
||||
}
|
||||
|
||||
$this->_docblock = $docblock;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDocblock()
|
||||
*
|
||||
* @return Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
public function getDocblock()
|
||||
{
|
||||
return $this->_docblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* setAbstract()
|
||||
*
|
||||
* @param bool $isAbstract
|
||||
* @return Zend_CodeGenerator_Php_Member_Abstract
|
||||
*/
|
||||
public function setAbstract($isAbstract)
|
||||
{
|
||||
$this->_isAbstract = ($isAbstract) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* isAbstract()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAbstract()
|
||||
{
|
||||
return $this->_isAbstract;
|
||||
}
|
||||
|
||||
/**
|
||||
* setStatic()
|
||||
*
|
||||
* @param bool $isStatic
|
||||
* @return Zend_CodeGenerator_Php_Member_Abstract
|
||||
*/
|
||||
public function setStatic($isStatic)
|
||||
{
|
||||
$this->_isStatic = ($isStatic) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* isStatic()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStatic()
|
||||
{
|
||||
return $this->_isStatic;
|
||||
}
|
||||
|
||||
/**
|
||||
* setVisitibility()
|
||||
*
|
||||
* @param const $visibility
|
||||
* @return Zend_CodeGenerator_Php_Member_Abstract
|
||||
*/
|
||||
public function setVisibility($visibility)
|
||||
{
|
||||
$this->_visibility = $visibility;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getVisibility()
|
||||
*
|
||||
* @return const
|
||||
*/
|
||||
public function getVisibility()
|
||||
{
|
||||
return $this->_visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* setName()
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_CodeGenerator_Php_Member_Abstract
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getName()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
}
|
55
libs/Zend/CodeGenerator/Php/Member/Container.php
Normal file
55
libs/Zend/CodeGenerator/Php/Member/Container.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Member_Container extends ArrayObject
|
||||
{
|
||||
|
||||
/**#@+
|
||||
* @param const string
|
||||
*/
|
||||
const TYPE_PROPERTY = 'property';
|
||||
const TYPE_METHOD = 'method';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* @var const|string
|
||||
*/
|
||||
protected $_type = self::TYPE_PROPERTY;
|
||||
|
||||
/**
|
||||
* __construct()
|
||||
*
|
||||
* @param const|string $type
|
||||
*/
|
||||
public function __construct($type = self::TYPE_PROPERTY)
|
||||
{
|
||||
$this->_type = $type;
|
||||
parent::__construct(array(), self::ARRAY_AS_PROPS);
|
||||
}
|
||||
|
||||
}
|
227
libs/Zend/CodeGenerator/Php/Method.php
Normal file
227
libs/Zend/CodeGenerator/Php/Method.php
Normal file
@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Member_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Member/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Docblock.php';
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Parameter
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Parameter.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Method extends Zend_CodeGenerator_Php_Member_Abstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_CodeGenerator_Php_Docblock
|
||||
*/
|
||||
protected $_docblock = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isFinal = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_parameters = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_body = null;
|
||||
|
||||
/**
|
||||
* fromReflection()
|
||||
*
|
||||
* @param Zend_Reflection_Method $reflectionMethod
|
||||
* @return Zend_CodeGenerator_Php_Method
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Method $reflectionMethod)
|
||||
{
|
||||
$method = new self();
|
||||
|
||||
$method->setSourceContent($reflectionMethod->getContents(false));
|
||||
$method->setSourceDirty(false);
|
||||
|
||||
if ($reflectionMethod->getDocComment() != '') {
|
||||
$method->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($reflectionMethod->getDocblock()));
|
||||
}
|
||||
|
||||
$method->setFinal($reflectionMethod->isFinal());
|
||||
|
||||
if ($reflectionMethod->isPrivate()) {
|
||||
$method->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
} elseif ($reflectionMethod->isProtected()) {
|
||||
$method->setVisibility(self::VISIBILITY_PROTECTED);
|
||||
} else {
|
||||
$method->setVisibility(self::VISIBILITY_PUBLIC);
|
||||
}
|
||||
|
||||
$method->setStatic($reflectionMethod->isStatic());
|
||||
|
||||
$method->setName($reflectionMethod->getName());
|
||||
|
||||
foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
|
||||
$method->setParameter(Zend_CodeGenerator_Php_Parameter::fromReflection($reflectionParameter));
|
||||
}
|
||||
|
||||
$method->setBody($reflectionMethod->getBody());
|
||||
|
||||
return $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* setFinal()
|
||||
*
|
||||
* @param bool $isFinal
|
||||
*/
|
||||
public function setFinal($isFinal)
|
||||
{
|
||||
$this->_isFinal = ($isFinal) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* setParameters()
|
||||
*
|
||||
* @param array $parameters
|
||||
* @return Zend_CodeGenerator_Php_Method
|
||||
*/
|
||||
public function setParameters(Array $parameters)
|
||||
{
|
||||
foreach ($parameters as $parameter) {
|
||||
$this->setParameter($parameter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setParameter()
|
||||
*
|
||||
* @param Zend_CodeGenerator_Php_Parameter|array $parameter
|
||||
* @return Zend_CodeGenerator_Php_Method
|
||||
*/
|
||||
public function setParameter($parameter)
|
||||
{
|
||||
if (is_array($parameter)) {
|
||||
$parameter = new Zend_CodeGenerator_Php_Parameter($parameter);
|
||||
$parameterName = $parameter->getName();
|
||||
} elseif ($parameter instanceof Zend_CodeGenerator_Php_Parameter) {
|
||||
$parameterName = $parameter->getName();
|
||||
} else {
|
||||
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
||||
throw new Zend_CodeGenerator_Php_Exception('setParameter() expects either an array of method options or an instance of Zend_CodeGenerator_Php_Parameter');
|
||||
}
|
||||
|
||||
$this->_parameters[$parameterName] = $parameter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getParameters()
|
||||
*
|
||||
* @return array Array of Zend_CodeGenerator_Php_Parameter
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->_parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* setBody()
|
||||
*
|
||||
* @param string $body
|
||||
* @return Zend_CodeGenerator_Php_Method
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->_body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getBody()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->_body;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$output = ' ';
|
||||
|
||||
if (null !== ($docblock = $this->getDocblock())) {
|
||||
$docblock->setIndentation(' ');
|
||||
$output .= $docblock->generate();
|
||||
$output .= ' ';
|
||||
}
|
||||
|
||||
if ($this->isAbstract()) {
|
||||
$output .= 'abstract ';
|
||||
}
|
||||
|
||||
$output .= $this->getVisibility() . ' function ' . $this->getName() . '(';
|
||||
|
||||
$parameters = $this->getParameters();
|
||||
if (!empty($parameters)) {
|
||||
foreach ($parameters as $parameter) {
|
||||
$parameterOuput[] = $parameter->generate();
|
||||
}
|
||||
|
||||
$output .= implode(', ', $parameterOuput);
|
||||
}
|
||||
|
||||
$output .= ')' . PHP_EOL . ' {' . PHP_EOL;
|
||||
|
||||
if ($this->_body) {
|
||||
$output .= ' '
|
||||
. str_replace(PHP_EOL, PHP_EOL . ' ', trim($this->_body))
|
||||
. PHP_EOL;
|
||||
}
|
||||
|
||||
$output .= ' }' . PHP_EOL;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
183
libs/Zend/CodeGenerator/Php/Parameter.php
Normal file
183
libs/Zend/CodeGenerator/Php/Parameter.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Parameter extends Zend_CodeGenerator_Php_Abstract
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_type = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultValue = null;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_position = null;
|
||||
|
||||
/**
|
||||
* fromReflection()
|
||||
*
|
||||
* @param Zend_Reflection_Parameter $reflectionParameter
|
||||
* @return Zend_CodeGenerator_Php_Parameter
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Parameter $reflectionParameter)
|
||||
{
|
||||
// @todo Research this
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* setType()
|
||||
*
|
||||
* @param string $type
|
||||
* @return Zend_CodeGenerator_Php_Parameter
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getType()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* setName()
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_CodeGenerator_Php_Parameter
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getName()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDefaultValue()
|
||||
*
|
||||
* @param string $defaultValue
|
||||
* @return Zend_CodeGenerator_Php_Parameter
|
||||
*/
|
||||
public function setDefaultValue($defaultValue)
|
||||
{
|
||||
$this->_defaultValue = $defaultValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDefaultValue()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultValue()
|
||||
{
|
||||
return $this->_defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* setPosition()
|
||||
*
|
||||
* @param int $position
|
||||
* @return Zend_CodeGenerator_Php_Parameter
|
||||
*/
|
||||
public function setPosition($position)
|
||||
{
|
||||
$this->_position = $position;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPosition()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
return $this->_position;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$output = '';
|
||||
|
||||
if ($this->_type) {
|
||||
$output .= $this->_type . ' ';
|
||||
}
|
||||
|
||||
$output .= '$' . $this->_name;
|
||||
|
||||
if ($this->_defaultValue) {
|
||||
$output .= ' = ';
|
||||
if (is_string($this->_defaultValue)) {
|
||||
$output .= '\'' . $this->_defaultValue . '\'';
|
||||
} else {
|
||||
$output .= $this->_defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
120
libs/Zend/CodeGenerator/Php/Property.php
Normal file
120
libs/Zend/CodeGenerator/Php/Property.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @subpackage PHP
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_CodeGenerator_Php_Member_Abstract
|
||||
*/
|
||||
require_once 'Zend/CodeGenerator/Php/Member/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_CodeGenerator
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_CodeGenerator_Php_Property extends Zend_CodeGenerator_Php_Member_Abstract
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isConst = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultValue = null;
|
||||
|
||||
/**
|
||||
* fromReflection()
|
||||
*
|
||||
* @param Zend_Reflection_Property $reflectionProperty
|
||||
* @return Zend_CodeGenerator_Php_Property
|
||||
*/
|
||||
public static function fromReflection(Zend_Reflection_Property $reflectionProperty) {
|
||||
$property = new self();
|
||||
$property->setSourceDirty(false);
|
||||
|
||||
return $property;
|
||||
}
|
||||
|
||||
/**
|
||||
* setConst()
|
||||
*
|
||||
* @param bool $const
|
||||
* @return Zend_CodeGenerator_Php_Property
|
||||
*/
|
||||
public function setConst($const)
|
||||
{
|
||||
$this->_isConst = $const;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* isConst()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConst()
|
||||
{
|
||||
return ($this->_isConst) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDefaultValue()
|
||||
*
|
||||
* @param string $defaultValue
|
||||
* @return Zend_CodeGenerator_Php_Property
|
||||
*/
|
||||
public function setDefaultValue($defaultValue)
|
||||
{
|
||||
$this->_defaultValue = $defaultValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDefaultValue()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultValue()
|
||||
{
|
||||
return $this->_defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$name = $this->getName();
|
||||
$defaultValue = $this->getDefaultValue();
|
||||
if ($this->isConst()) {
|
||||
$string = ' ' . 'const ' . $name . ' = \'' . $defaultValue . '\';';
|
||||
} else {
|
||||
$string = ' ' . $this->getVisibility() . ' $' . $name . ' = ' . ((null !== $defaultValue) ? '\'' . $defaultValue . '\'' : 'null') . ';';
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user