Permalink
Browse files

[UPDATE] new feature (audit) and enhancements

[UPDATE] new feature (audit) and enhancements

Audit is a new feature which allows to determine what takes most of the
generation time during the whole generation process. It stores
informations (calls number, time spent and last call time) so that each
call can be audited. Audit is filled calling
WsdlTophpgenerator::auditInit() at function start then
WsdlTophpgenerator::audit() to calculate time spent and calls number.
Audit informations are stored using the WsdlToPhpGenerator global
storage data. Audit can be accessed using the
WsdlToPhpGenerator::getAudit() method which returns an associative array
of all audited calls.

Improve inheritance determination, operation return and parameter types
determination by browsing schemas sequentially in order to retrieve
several particular tags (header, list, union, attribute, input, output).
See WsdlToPhpGenerator::wsdlsLoaded(). The generated php doc is then
more precise and informations are retrieved when the SoapClient object
doesn't retrieve hem.

Improve location management system in order to allow local schemas file
loading.

Minor review of attributes declaration for WsdlToPhpModel type classes.

Minor review of documentation management for php doc.
  • Loading branch information...
1 parent 32fba77 commit 20faab57249a93afd9ef1ce1bffc774cc82ec845 @mikaelcom committed Feb 4, 2013
@@ -15,12 +15,12 @@ class WsdlToPhpFunction extends WsdlToPhpModel
* Type of the parameter for the operation
* @var string
*/
- private $parameterType;
+ private $parameterType = '';
/**
* Type of the return value for the operation
* @var string
*/
- private $returnType;
+ private $returnType = '';
/**
* Main constructor
* @see WsdlToPhpModel::__construct()
View
Oops, something went wrong.
View
@@ -20,22 +20,22 @@ class WsdlToPhpModel
* Original name od the element
* @var string
*/
- private $name;
+ private $name = '';
/**
* Values associated to the operation
* @var array
*/
- private $meta;
+ private $meta = array();
/**
* Define the inheritance of a struct by the name of the parent struct or type
* @var string
*/
- private $inheritance;
+ private $inheritance = '';
/**
* Store the object which owns the current model
* @var WsdlToPhpModel
*/
- private $owner;
+ private $owner = null;
/**
* Store all the models generated
* @var array
@@ -68,8 +68,6 @@ class WsdlToPhpModel
*/
public function __construct($_name)
{
- $this->setInheritance();
- $this->setMeta();
$this->setName($_name);
self::updateModels($this);
}
@@ -79,6 +77,7 @@ public function __construct($_name)
* @uses WsdlToPhpModel::getDocumentation()
* @uses WsdlToPhpModel::addMetaComment()
* @uses WsdlToPhpModel::getDocSubPackages()
+ * @uses WsdlToPhpStruct::getIsStruct()
* @uses WsdlToPhpGenerator::getPackageName()
* @param int $_part comment part
* @return array
@@ -100,6 +99,16 @@ public function getComment($_part = '')
if($this->getDocumentation() != '')
array_push($comments,'Documentation : ' . $this->getDocumentation());
$this->addMetaComment($comments,false,true);
+ if($this->getInheritance() != '')
+ {
+ $inheritedModel = self::getModelByName($this->getInheritance());
+ /**
+ * A virtual struct exists only to store meta informations about itself
+ * So don't add meta informations about a valid struct
+ */
+ if($inheritedModel && !$inheritedModel->getIsStruct())
+ $inheritedModel->addMetaComment($comments,false,false);
+ }
array_push($comments,'@package ' . WsdlToPhpGenerator::getPackageName());
if(count($this->getDocSubPackages()))
array_push($comments,'@subpackage ' . implode(',',$this->getDocSubPackages()));
@@ -197,11 +206,14 @@ public function getInheritance()
}
/**
* Set the name of the class the current class inherits from
+ * @uses WsdlToPhpModel::updateModels()
* @param string
*/
public function setInheritance($_inheritance = '')
{
- return ($this->inheritance = $_inheritance);
+ $this->inheritance = $_inheritance;
+ self::updateModels($this);
+ return $_inheritance;
}
/**
* Add meta informations to comment array
@@ -280,15 +292,17 @@ public function addMeta($_metaName,$_metaValue)
return $metaValue;
}
/**
- * Set the documentation meta value
+ * Set the documentation meta value.
+ * Documentation is set as an array so if multiple documentation nodes are set for an unique element, it will gather them.
* @uses WsdlToPhpModel::META_DOCUMENTATION
* @uses WsdlToPhpModel::addMeta()
* @param string $_documentation the documentation from the WSDL
* @return string the documentation from the WSDL
*/
public function setDocumentation($_documentation)
{
- return $this->addMeta(self::META_DOCUMENTATION,$_documentation);
+ return $this->addMeta(self::META_DOCUMENTATION,is_array($_documentation)?$_documentation:array(
+ $_documentation));
}
/**
* Get the documentation meta value
@@ -299,7 +313,7 @@ public function setDocumentation($_documentation)
*/
public function getDocumentation()
{
- return self::cleanComment($this->getMetaValue(self::META_DOCUMENTATION,''));
+ return self::cleanComment($this->getMetaValue(self::META_DOCUMENTATION,''),' ');
}
/**
* Return a meta value according to its name
@@ -363,11 +377,14 @@ public function getOwner()
}
/**
* @param WsdlToPhpModel $_owner object the owner of the current model
+ * @uses WsdlToPhpModel::updateModels()
* @return WsdlToPhpModel
*/
public function setOwner(WsdlToPhpModel $_owner)
{
- return ($this->owner = $_owner);
+ $this->owner = $_owner;
+ self::updateModels($this);
+ return $_owner;
}
/**
* Returns true if the original name is safe to use as a PHP property, variable name or class name
@@ -454,9 +471,9 @@ private static function setModels(array $_models = array())
* @param WsdlToPhpModel $_model a WsdlToPhpModel object
* @return WsdlToPhpStruct|bool
*/
- private static function updateModels(WsdlToPhpModel $_model)
+ protected static function updateModels(WsdlToPhpModel $_model)
{
- if($_model->__toString() != 'WsdlToPhpStruct')
+ if($_model->__toString() != 'WsdlToPhpStruct' || !$_model->getName())
return false;
return (self::$models['_' . $_model->getName() . '_'] = $_model);
}
@@ -531,13 +548,14 @@ public static function getValueWithinItsType($_value)
/**
* Clean comment
* @param string $_comment the comment to clean
+ * @param string $_glueSeparator ths string to use when gathering values
* @return string
*/
- public static function cleanComment($_comment)
+ public static function cleanComment($_comment,$_glueSeparator = ',')
{
if(!is_scalar($_comment) && !is_array($_comment))
return '';
- return trim(str_replace('*/','*[:slash:]',is_scalar($_comment)?$_comment:implode(',',array_unique($_comment))));
+ return trim(str_replace('*/','*[:slash:]',is_scalar($_comment)?$_comment:implode($_glueSeparator,array_unique($_comment))));
}
/**
* Returns the generic name of the WsdlClass
@@ -15,7 +15,7 @@ class WsdlToPhpService extends WsdlToPhpModel
* Store the functions of the service
* @var array
*/
- private $functions;
+ private $functions = array();
/**
* Main constructor
* @see WsdlToPhpModel::__construct()
@@ -26,7 +26,6 @@ class WsdlToPhpService extends WsdlToPhpModel
public function __construct($_name)
{
parent::__construct($_name);
- $this->setFunctions();
}
/**
* Allows to define the contextual part of the class name for the package
View
@@ -15,22 +15,22 @@ class WsdlToPhpStruct extends WsdlToPhpModel
* Attributes of the struct
* @var array
*/
- private $attributes;
+ private $attributes = array();
/**
* Is the struct a restriction with defined values ?
* @var bool
*/
- private $isRestriction;
+ private $isRestriction = false;
/**
* If the struct is a restriction with values, then store values
* @var array
*/
- private $values;
+ private $values = array();
/**
* Define if the urrent struct is a concrete struct or just a virtual struct to store meta informations
* @var bool
*/
- private $isStruct;
+ private $isStruct = false;
/**
* Main constructor
* @see WsdlToPhpModel::__construct()
@@ -45,8 +45,6 @@ public function __construct($_name,$_isStruct = true)
{
parent::__construct($_name);
$this->setIsStruct($_isStruct);
- $this->setValues();
- $this->setAttributes();
}
/**
* Returns the constructor method
@@ -399,13 +397,16 @@ public function setAttributes(array $_attributes = array())
}
/**
* Add attribute based on its original name
+ * @uses WsdlToPhpModel::updateModels()
* @param string $_attributeName the attribute name
* @param string $_attributeType the attribute type
* @return WsdlToPhpStructAttribute
*/
public function addAttribute($_attributeName,$_attributeType)
{
- return ($this->attributes[$_attributeName] = new WsdlToPhpStructAttribute($_attributeName,$_attributeType,$this));
+ $this->attributes[$_attributeName] = new WsdlToPhpStructAttribute($_attributeName,$_attributeType,$this);
+ self::updateModels($this);
+ return $this->attributes[$_attributeName];
}
/**
* Return the attribute by its name, otherwise null
@@ -427,12 +428,15 @@ public function getIsRestriction()
}
/**
* Set the isRestriction value
+ * @uses WsdlToPhpModel::updateModels()
* @param bool $_isRestriction
* @return bool
*/
public function setIsRestriction($_isRestriction = true)
{
- return ($this->isRestriction = $_isRestriction);
+ $this->isRestriction = $_isRestriction;
+ self::updateModels($this);
+ return $_isRestriction;
}
/**
* Returns the isStruct value
@@ -444,12 +448,15 @@ public function getIsStruct()
}
/**
* Set the isStruct value
+ * @uses WsdlToPhpModel::updateModels()
* @param bool $_isStruct
* @return bool
*/
public function setIsStruct($_isStruct = true)
{
- return ($this->isStruct = $_isStruct);
+ $this->isStruct = $_isStruct;
+ self::updateModels($this);
+ return $_isStruct;
}
/**
* Returns the values for an enumeration
@@ -461,15 +468,19 @@ public function getValues()
}
/**
* Set the values for an enumeration
+ * @uses WsdlToPhpModel::updateModels()
* @param array $_values
* @return array
*/
private function setValues(array $_values = array())
{
- return ($this->values = $_values);
+ $this->values = $_values;
+ self::updateModels($this);
+ return $_values;
}
/**
* Add value to values array
+ * @uses WsdlToPhpModel::updateModels()
* @uses WsdlToPhpStruct::getValue()
* @uses WsdlToPhpStruct::getValues()
* @param mixed $_value the original value
@@ -478,6 +489,7 @@ public function addValue($_value)
{
if(!$this->getValue($_value))
array_push($this->values,new WsdlToPhpStructValue($_value,count($this->getValues()),$this));
+ self::updateModels($this);
}
/**
* Get the value object for the given value
@@ -15,7 +15,7 @@ class WsdlToPhpStructAttribute extends WsdlToPhpModel
* Type of the struct attribute
* @var string
*/
- private $type;
+ private $type = '';
/**
* Main constructor
* @see WsdlToPhpModel::__construct()
@@ -20,7 +20,7 @@ class WsdlToPhpStructValue extends WsdlToPhpModel
* The index of the value in the enumeration struct
* @var int
*/
- private $index;
+ private $index = 0;
/**
* Main constructor
* @see WsdlToPhpModel::__construct()
@@ -1,6 +1,6 @@
<?php
/**
- * Sample to show how to use WsdlToPhp class
+ * Sample to show how to use WsdlToPhpGenerator class
* @package WsdlToPhpGenerator
* @date 01/07/2012
*/
@@ -139,5 +139,6 @@ function lcfirst($_s)
exec('rm -rf ' . __DIR__ . '/docs/' . $name . '/* && clear && phpdoc --sourcecode on -d ' . __DIR__ . '/samples/' . $name . ' -t ' . __DIR__ . '/docs/' . $name . ' -pp -ti "' . ucfirst($name) . ' package documentation" -o HTML:frames:DOM/earthli;',$ouputs);
print_r($ouputs);
echo "\r\nGenerate doc end " . date('H:i:s');
+ print_r($w->getAudit());
}
?>

0 comments on commit 20faab5

Please sign in to comment.