import v1.1.0_RC2 | 2009-09-20

This commit is contained in:
2019-07-17 22:19:00 +02:00
parent 3b7ba80568
commit 38c146901c
2504 changed files with 101817 additions and 62316 deletions

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Abstract.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -33,7 +33,13 @@ require_once 'Zend/CodeGenerator/Abstract.php';
*/
abstract class Zend_CodeGenerator_Php_Abstract extends Zend_CodeGenerator_Abstract
{
/**
* Line feed to use in place of EOL
*
*/
const LINE_FEED = "\n";
/**
* @var bool
*/

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Body.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Class.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -326,6 +326,17 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
return false;
}
/**
* hasProperty()
*
* @param string $propertyName
* @return bool
*/
public function hasProperty($propertyName)
{
return isset($this->_properties[$propertyName]);
}
/**
* setMethods()
*
@ -463,23 +474,23 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
$output .= ' implements ' . implode(', ', $implemented);
}
$output .= PHP_EOL . '{' . PHP_EOL . PHP_EOL;
$output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED;
$properties = $this->getProperties();
if (!empty($properties)) {
foreach ($properties as $property) {
$output .= $property->generate() . PHP_EOL . PHP_EOL;
$output .= $property->generate() . self::LINE_FEED . self::LINE_FEED;
}
}
$methods = $this->getMethods();
if (!empty($methods)) {
foreach ($methods as $method) {
$output .= $method->generate() . PHP_EOL;
$output .= $method->generate() . self::LINE_FEED;
}
}
$output .= PHP_EOL . '}' . PHP_EOL;
$output .= self::LINE_FEED . '}' . self::LINE_FEED;
return $output;
}

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Docblock.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -185,14 +185,14 @@ class Zend_CodeGenerator_Php_Docblock extends Zend_CodeGenerator_Php_Abstract
$output = '';
if (null !== ($sd = $this->getShortDescription())) {
$output .= $sd . PHP_EOL . PHP_EOL;
$output .= $sd . self::LINE_FEED . self::LINE_FEED;
}
if (null !== ($ld = $this->getLongDescription())) {
$output .= $ld . PHP_EOL . PHP_EOL;
$output .= $ld . self::LINE_FEED . self::LINE_FEED;
}
foreach ($this->getTags() as $tag) {
$output .= $tag->generate();
$output .= $tag->generate() . self::LINE_FEED;
}
return $this->_docCommentize(trim($output));
@ -207,13 +207,13 @@ class Zend_CodeGenerator_Php_Docblock extends Zend_CodeGenerator_Php_Abstract
protected function _docCommentize($content)
{
$indent = $this->getIndentation();
$output = '/**' . PHP_EOL;
$content = wordwrap($content, 80, "\n");
$lines = explode("\n", $content);
$output = $indent . '/**' . self::LINE_FEED;
$content = wordwrap($content, 80, self::LINE_FEED);
$lines = explode(self::LINE_FEED, $content);
foreach ($lines as $line) {
$output .= $indent . ' * ' . $line . PHP_EOL;
$output .= $indent . ' * ' . $line . self::LINE_FEED;
}
$output .= $indent . ' */' . PHP_EOL;
$output .= $indent . ' */' . self::LINE_FEED;
return $output;
}

View File

@ -17,13 +17,13 @@
* @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$
* @version $Id: Tag.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
* @see Zend_CodeGenerator_Abstract
*/
require_once 'Zend/CodeGenerator/Abstract.php';
require_once 'Zend/CodeGenerator/Php/Abstract.php';
/**
* @see Zend_CodeGenerator_Php_Docblock_Tag_Param
@ -41,7 +41,7 @@ require_once 'Zend/CodeGenerator/Php/Docblock/Tag/Return.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
*/
class Zend_CodeGenerator_Php_Docblock_Tag extends Zend_CodeGenerator_Abstract
class Zend_CodeGenerator_Php_Docblock_Tag extends Zend_CodeGenerator_Php_Abstract
{
/**
@ -178,7 +178,7 @@ class Zend_CodeGenerator_Php_Docblock_Tag extends Zend_CodeGenerator_Abstract
*/
public function generate()
{
return '@' . $this->_name . ' ' . $this->_description . PHP_EOL;
return '@' . $this->_name . ' ' . $this->_description;
}
}

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: License.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -91,7 +91,7 @@ class Zend_CodeGenerator_Php_Docblock_Tag_License extends Zend_CodeGenerator_Php
*/
public function generate()
{
$output = '@license ' . $this->_url . ' ' . $this->_description . PHP_EOL;
$output = '@license ' . $this->_url . ' ' . $this->_description . self::LINE_FEED;
return $output;
}

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Param.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -118,7 +118,10 @@ class Zend_CodeGenerator_Php_Docblock_Tag_Param extends Zend_CodeGenerator_Php_D
*/
public function generate()
{
$output = '@param ' . $this->_datatype . ' ' . $this->_paramName . ' ' . $this->_description . PHP_EOL;
$output = '@param '
. (($this->_datatype != null) ? $this->_datatype : 'unknown')
. (($this->_paramName != null) ? ' $' . $this->_paramName : '')
. (($this->_description != null) ? ' ' . $this->_description : '');
return $output;
}

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Return.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -91,7 +91,7 @@ class Zend_CodeGenerator_Php_Docblock_Tag_Return extends Zend_CodeGenerator_Php_
*/
public function generate()
{
$output = '@return ' . $this->_datatype . ' ' . $this->_description . PHP_EOL;
$output = '@return ' . $this->_datatype . ' ' . $this->_description;
return $output;
}

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Exception.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: File.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -389,7 +389,7 @@ class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
// start with the body (if there), or open tag
if (preg_match('#(?:\s*)<\?php#', $this->getBody()) == false) {
$output = '<?php' . PHP_EOL;
$output = '<?php' . self::LINE_FEED;
}
// if there are markers, put the body into the output
@ -406,22 +406,22 @@ class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
if (preg_match('#'.$regex.'#', $output)) {
$output = preg_replace('#'.$regex.'#', $docblock->generate(), $output, 1);
} else {
$output .= $docblock->generate() . PHP_EOL;
$output .= $docblock->generate() . self::LINE_FEED;
}
}
// newline
$output .= PHP_EOL;
$output .= self::LINE_FEED;
// 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 .= 'require_once \'' . $requiredFile . '\';' . self::LINE_FEED;
}
$output .= PHP_EOL;
$output .= self::LINE_FEED;
}
// process classes
@ -433,7 +433,7 @@ class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
if (preg_match('#'.$regex.'#', $output)) {
$output = preg_replace('#'.$regex.'#', $class->generate(), $output, 1);
} else {
$output .= $class->generate() . PHP_EOL;
$output .= $class->generate() . self::LINE_FEED;
}
}
@ -443,7 +443,7 @@ class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
// add an extra space betwee clsses and
if (!empty($classes)) {
$output .= PHP_EOL;
$output .= self::LINE_FEED;
}
$output .= $body;

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Abstract.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -25,6 +25,11 @@
*/
require_once 'Zend/CodeGenerator/Php/Abstract.php';
/**
* @see Zend_CodeGenerator_Php_Abstract
*/
require_once 'Zend/CodeGenerator/Php/Docblock.php';
/**
* @category Zend
* @package Zend_CodeGenerator
@ -33,6 +38,7 @@ require_once 'Zend/CodeGenerator/Php/Abstract.php';
*/
abstract class Zend_CodeGenerator_Php_Member_Abstract extends Zend_CodeGenerator_Php_Abstract
{
/**#@+
* @param const string
*/
@ -41,11 +47,21 @@ abstract class Zend_CodeGenerator_Php_Member_Abstract extends Zend_CodeGenerator
const VISIBILITY_PRIVATE = 'private';
/**#@-*/
/**
* @var Zend_CodeGenerator_Php_Docblock
*/
protected $_docblock = null;
/**
* @var bool
*/
protected $_isAbstract = false;
/**
* @var bool
*/
protected $_isFinal = false;
/**
* @var bool
*/
@ -116,6 +132,28 @@ abstract class Zend_CodeGenerator_Php_Member_Abstract extends Zend_CodeGenerator
return $this->_isAbstract;
}
/**
* setFinal()
*
* @param bool $isFinal
* @return Zend_CodeGenerator_Php_Member_Abstract
*/
public function setFinal($isFinal)
{
$this->_isFinal = ($isFinal) ? true : false;
return $this;
}
/**
* isFinal()
*
* @return bool
*/
public function isFinal()
{
return $this->_isFinal;
}
/**
* setStatic()
*
@ -136,7 +174,7 @@ abstract class Zend_CodeGenerator_Php_Member_Abstract extends Zend_CodeGenerator
public function isStatic()
{
return $this->_isStatic;
}
}
/**
* setVisitibility()

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Container.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Method.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -188,19 +188,26 @@ class Zend_CodeGenerator_Php_Method extends Zend_CodeGenerator_Php_Member_Abstra
*/
public function generate()
{
$output = ' ';
$output = '';
if (null !== ($docblock = $this->getDocblock())) {
$docblock->setIndentation(' ');
$indent = $this->getIndentation();
if (($docblock = $this->getDocblock()) !== null) {
$docblock->setIndentation($indent);
$output .= $docblock->generate();
$output .= ' ';
}
$output .= $indent;
if ($this->isAbstract()) {
$output .= 'abstract ';
} else {
$output .= (($this->isFinal()) ? 'final ' : '');
}
$output .= $this->getVisibility() . ' function ' . $this->getName() . '(';
$output .= $this->getVisibility()
. (($this->isStatic()) ? ' static' : '')
. ' function ' . $this->getName() . '(';
$parameters = $this->getParameters();
if (!empty($parameters)) {
@ -211,15 +218,15 @@ class Zend_CodeGenerator_Php_Method extends Zend_CodeGenerator_Php_Member_Abstra
$output .= implode(', ', $parameterOuput);
}
$output .= ')' . PHP_EOL . ' {' . PHP_EOL;
$output .= ')' . self::LINE_FEED . $indent . '{' . self::LINE_FEED;
if ($this->_body) {
$output .= ' '
. str_replace(PHP_EOL, PHP_EOL . ' ', trim($this->_body))
. PHP_EOL;
. str_replace(self::LINE_FEED, self::LINE_FEED . $indent . $indent, trim($this->_body))
. self::LINE_FEED;
}
$output .= ' }' . PHP_EOL;
$output .= $indent . '}' . self::LINE_FEED;
return $output;
}

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Parameter.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**

View File

@ -17,7 +17,7 @@
* @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$
* @version $Id: Property.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
@ -25,6 +25,11 @@
*/
require_once 'Zend/CodeGenerator/Php/Member/Abstract.php';
/**
* @see Zend_CodeGenerator_Php_Property_DefaultValue
*/
require_once 'Zend/CodeGenerator/Php/Property/DefaultValue.php';
/**
* @category Zend
* @package Zend_CodeGenerator
@ -33,6 +38,7 @@ require_once 'Zend/CodeGenerator/Php/Member/Abstract.php';
*/
class Zend_CodeGenerator_Php_Property extends Zend_CodeGenerator_Php_Member_Abstract
{
/**
* @var bool
*/
@ -49,8 +55,32 @@ class Zend_CodeGenerator_Php_Property extends Zend_CodeGenerator_Php_Member_Abst
* @param Zend_Reflection_Property $reflectionProperty
* @return Zend_CodeGenerator_Php_Property
*/
public static function fromReflection(Zend_Reflection_Property $reflectionProperty) {
public static function fromReflection(Zend_Reflection_Property $reflectionProperty)
{
$property = new self();
$property->setName($reflectionProperty->getName());
$allDefaultProperties = $reflectionProperty->getDeclaringClass()->getDefaultProperties();
$property->setDefaultValue($allDefaultProperties[$reflectionProperty->getName()]);
if ($reflectionProperty->getDocComment() != '') {
$property->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($reflectionProperty->getDocComment()));
}
if ($reflectionProperty->isStatic()) {
$property->setStatic(true);
}
if ($reflectionProperty->isPrivate()) {
$property->setVisibility(self::VISIBILITY_PRIVATE);
} elseif ($reflectionProperty->isProtected()) {
$property->setVisibility(self::VISIBILITY_PROTECTED);
} else {
$property->setVisibility(self::VISIBILITY_PUBLIC);
}
$property->setSourceDirty(false);
return $property;
@ -77,23 +107,34 @@ class Zend_CodeGenerator_Php_Property extends Zend_CodeGenerator_Php_Member_Abst
{
return ($this->_isConst) ? true : false;
}
/**
* setDefaultValue()
*
* @param string $defaultValue
* @param Zend_CodeGenerator_Php_Property_DefaultValue|string|array $defaultValue
* @return Zend_CodeGenerator_Php_Property
*/
public function setDefaultValue($defaultValue)
{
// if it looks like
if (is_array($defaultValue)
&& array_key_exists('value', $defaultValue)
&& array_key_exists('type', $defaultValue)) {
$defaultValue = new Zend_CodeGenerator_Php_Property_DefaultValue($defaultValue);
}
if (!($defaultValue instanceof Zend_CodeGenerator_Php_Property_DefaultValue)) {
$defaultValue = new Zend_CodeGenerator_Php_Property_DefaultValue(array('value' => $defaultValue));
}
$this->_defaultValue = $defaultValue;
return $this;
}
/**
* getDefaultValue()
*
* @return string
* @return Zend_CodeGenerator_Php_Property_DefaultValue
*/
public function getDefaultValue()
{
@ -109,12 +150,30 @@ class Zend_CodeGenerator_Php_Property extends Zend_CodeGenerator_Php_Member_Abst
{
$name = $this->getName();
$defaultValue = $this->getDefaultValue();
if ($this->isConst()) {
$string = ' ' . 'const ' . $name . ' = \'' . $defaultValue . '\';';
} else {
$string = ' ' . $this->getVisibility() . ' $' . $name . ' = ' . ((null !== $defaultValue) ? '\'' . $defaultValue . '\'' : 'null') . ';';
$output = '';
if (($docblock = $this->getDocblock()) !== null) {
$docblock->setIndentation(' ');
$output .= $docblock->generate();
}
return $string;
if ($this->isConst()) {
if ($defaultValue != null && !$defaultValue->isValidConstantType()) {
require_once 'Zend/CodeGenerator/Php/Exception.php';
throw new Zend_CodeGenerator_Php_Exception('The property ' . $this->_name . ' is said to be '
. 'constant but does not have a valid constant value.');
}
$output .= $this->_indentation . 'const ' . $name . ' = '
. (($defaultValue !== null) ? $defaultValue->generate() : 'null;');
} else {
$output .= $this->_indentation
. $this->getVisibility()
. (($this->isStatic()) ? ' static' : '')
. ' $' . $name . ' = '
. (($defaultValue !== null) ? $defaultValue->generate() : 'null;');
}
return $output;
}
}

View File

@ -0,0 +1,314 @@
<?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: DefaultValue.php 16971 2009-07-22 18:05:45Z mikaelkael $
*/
/**
* @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_Property_DefaultValue extends Zend_CodeGenerator_Php_Abstract
{
/**#@+
* Constant values
*/
const TYPE_AUTO = 'auto';
const TYPE_BOOLEAN = 'boolean';
const TYPE_BOOL = 'bool';
const TYPE_NUMBER = 'number';
const TYPE_INTEGER = 'integer';
const TYPE_INT = 'int';
const TYPE_FLOAT = 'float';
const TYPE_DOUBLE = 'double';
const TYPE_STRING = 'string';
const TYPE_ARRAY = 'array';
const TYPE_CONSTANT = 'constant';
const TYPE_NULL = 'null';
const TYPE_OTHER = 'other';
/**#@-*/
/**
* @var array of reflected constants
*/
protected static $_constants = array();
/**
* @var mixed
*/
protected $_value = null;
/**
* @var string
*/
protected $_type = self::TYPE_AUTO;
/**
* @var int
*/
protected $_arrayDepth = 1;
/**
* _init()
*
* This method will prepare the constant array for this class
*/
protected function _init()
{
$reflect = new ReflectionClass(get_class($this));
self::$_constants = $reflect->getConstants();
unset($reflect);
}
/**
* isValidConstantType()
*
* @return bool
*/
public function isValidConstantType()
{
if ($this->_type == self::TYPE_AUTO) {
$type = $this->_getAutoDeterminedType($this->_value);
}
// valid types for constants
$scalarTypes = array(
self::TYPE_BOOLEAN,
self::TYPE_BOOL,
self::TYPE_NUMBER,
self::TYPE_INTEGER,
self::TYPE_INT,
self::TYPE_FLOAT,
self::TYPE_DOUBLE,
self::TYPE_STRING,
self::TYPE_CONSTANT,
self::TYPE_NULL
);
return in_array($type, $scalarTypes);
}
/**
* setValue()
*
* @param mixed $value
* @return Zend_CodeGenerator_Php_Property_DefaultValue
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* getValue()
*
* @return mixed
*/
public function getValue()
{
return $this->_value;
}
/**
* setType()
*
* @param string $type
* @return Zend_CodeGenerator_Php_Property_DefaultValue
*/
public function setType($type)
{
$this->_type = $type;
return $this;
}
/**
* getType()
*
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* setArrayDepth()
*
* @param int $arrayDepth
* @return Zend_CodeGenerator_Php_Property_DefaultValue
*/
public function setArrayDepth($arrayDepth)
{
$this->_arrayDepth = $arrayDepth;
return $this;
}
/**
* getArrayDepth()
*
* @return int
*/
public function getArrayDepth()
{
return $this->_arrayDepth;
}
/**
* _getValidatedType()
*
* @param string $type
* @return string
*/
protected function _getValidatedType($type)
{
if (($constName = array_search($type, self::$_constants)) !== false) {
return $type;
}
return self::TYPE_AUTO;
}
/**
* _getAutoDeterminedType()
*
* @param mixed $value
* @return string
*/
public function _getAutoDeterminedType($value)
{
switch (gettype($value)) {
case 'boolean':
return self::TYPE_BOOLEAN;
case 'integer':
return self::TYPE_INT;
case 'string':
return self::TYPE_STRING;
case 'double':
case 'float':
case 'integer':
return self::TYPE_NUMBER;
case 'array':
return self::TYPE_ARRAY;
case 'NULL':
return self::TYPE_NULL;
case 'object':
case 'resource':
case 'unknown type':
default:
return self::TYPE_OTHER;
}
return self::TYPE_OTHER;
}
/**
* generate()
*
* @return string
*/
public function generate()
{
$type = $this->_type;
if ($type != self::TYPE_AUTO) {
$type = $this->_getValidatedType($type);
}
$value = $this->_value;
if ($type == self::TYPE_AUTO) {
$type = $this->_getAutoDeterminedType($value);
if ($type == self::TYPE_ARRAY) {
$rii = new RecursiveIteratorIterator(
$it = new RecursiveArrayIterator($value),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($rii as $curKey => $curValue) {
if (!$curValue instanceof Zend_CodeGenerator_Php_Property_DefaultValue) {
$curValue = new self(array('value' => $curValue));
$rii->getSubIterator()->offsetSet($curKey, $curValue);
}
$curValue->setArrayDepth($rii->getDepth());
}
$value = $rii->getSubIterator()->getArrayCopy();
}
}
$output = '';
switch ($type) {
case self::TYPE_STRING:
$output .= "'" . $value . "'";
break;
case self::TYPE_NUMBER:
case self::TYPE_INTEGER:
case self::TYPE_INT:
case self::TYPE_FLOAT:
case self::TYPE_DOUBLE:
case self::TYPE_NULL:
case self::TYPE_CONSTANT:
$output .= $value;
break;
case self::TYPE_ARRAY:
$output .= 'array(';
$curArrayMultiblock = false;
if (count($value) > 1) {
$curArrayMultiblock = true;
$output .= PHP_EOL . str_repeat($this->_indentation, $this->_arrayDepth+1);
}
$outputParts = array();
$noKeyIndex = 0;
foreach ($value as $n => $v) {
$v->setArrayDepth($this->_arrayDepth + 1);
$partV = $v->generate();
$partV = substr($partV, 0, strlen($partV)-1);
if ($n === $noKeyIndex) {
$outputParts[] = $partV;
$noKeyIndex++;
} else {
$outputParts[] = (is_int($n) ? $n : "'" . $n . "'") . ' => ' . $partV;
}
}
$output .= implode(',' . PHP_EOL . str_repeat($this->_indentation, $this->_arrayDepth+1), $outputParts);
if ($curArrayMultiblock == true) {
$output .= PHP_EOL . str_repeat($this->_indentation, $this->_arrayDepth+1);
}
$output .= ')';
break;
case self::TYPE_OTHER:
default:
throw new Exception('I dont know this type');
}
$output .= ';';
return $output;
}
}