MINOR Misc Convert documentation

MINOR Changed visibility of Convert::recursiveXMLToArray

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64409 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-10-16 11:49:51 +00:00
parent d6680e300d
commit b042141634
2 changed files with 18 additions and 7 deletions

View File

@ -22,7 +22,6 @@
* @subpackage misc * @subpackage misc
*/ */
class Convert extends Object { class Convert extends Object {
// Convert raw to other formats
static function raw2att($val) { static function raw2att($val) {
if(is_array($val)) { if(is_array($val)) {
@ -36,6 +35,7 @@ class Convert extends Object {
/** /**
* @see http://www.w3.org/TR/REC-html40/types.html#type-cdata * @see http://www.w3.org/TR/REC-html40/types.html#type-cdata
* @uses raw2att
*/ */
static function raw2htmlatt($val) { static function raw2htmlatt($val) {
if(is_array($val)) { if(is_array($val)) {
@ -73,6 +73,8 @@ class Convert extends Object {
* otherwise falls back to the Services_JSON class. * otherwise falls back to the Services_JSON class.
* *
* @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198 * @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198
* @uses Director::baseFolder()
* @uses Services_JSON
* *
* @param mixed $val * @param mixed $val
* @return string JSON safe string * @return string JSON safe string
@ -88,7 +90,6 @@ class Convert extends Object {
} }
// TODO Possible security risk: doesn't support arrays with more than one level - should be called recursively
static function raw2sql($val) { static function raw2sql($val) {
if(is_array($val)) { if(is_array($val)) {
foreach($val as $k => $v) $val[$k] = self::raw2sql($v); foreach($val as $k => $v) $val[$k] = self::raw2sql($v);
@ -101,6 +102,7 @@ class Convert extends Object {
/** /**
* Convert XML to raw text * Convert XML to raw text
* @uses html2raw()
* @todo Currently &#xxx; entries are stripped; they should be converted * @todo Currently &#xxx; entries are stripped; they should be converted
*/ */
static function xml2raw($val) { static function xml2raw($val) {
@ -131,7 +133,9 @@ class Convert extends Object {
return self::raw2sql(self::xml2raw($val)); return self::raw2sql(self::xml2raw($val));
} }
// Convert JS to other formats /**
* Convert JS to other formats
*/
static function js2raw($val) { static function js2raw($val) {
if(is_array($val)) { if(is_array($val)) {
foreach($val as $k => $v) $val[$k] = self::js2raw($v); foreach($val as $k => $v) $val[$k] = self::js2raw($v);
@ -147,6 +151,7 @@ class Convert extends Object {
static function js2att($val) { static function js2att($val) {
return self::raw2att(self::js2raw($val)); return self::raw2att(self::js2raw($val));
} }
static function js2sql($val) { static function js2sql($val) {
return self::raw2sql(self::js2raw($val)); return self::raw2sql(self::js2raw($val));
} }
@ -170,6 +175,9 @@ class Convert extends Object {
//} //}
} }
/**
* @uses json2obj
*/
static function json2array($val) { static function json2array($val) {
$json = self::json2obj($val); $json = self::json2obj($val);
$arr = array(); $arr = array();
@ -179,13 +187,15 @@ class Convert extends Object {
return $arr; return $arr;
} }
/**
* @uses recursiveXMLToArray()
*/
static function xml2array($val) { static function xml2array($val) {
$xml = new SimpleXMLElement($val); $xml = new SimpleXMLElement($val);
return self::recursiveXMLToArray($xml); return self::recursiveXMLToArray($xml);
} }
static function recursiveXMLToArray($xml) { protected static function recursiveXMLToArray($xml) {
if (get_class($xml) == 'SimpleXMLElement') { if (get_class($xml) == 'SimpleXMLElement') {
$attributes = $xml->attributes(); $attributes = $xml->attributes();
foreach($attributes as $k=>$v) { foreach($attributes as $k=>$v) {
@ -211,8 +221,6 @@ class Convert extends Object {
} }
$result = array(); $result = array();
// Debug::show($array);
foreach( $array as $key => $value ) foreach( $array as $key => $value )
if( is_array( $value ) ) if( is_array( $value ) )
$result[] = "'$key':" . Convert::array2json( $value ); $result[] = "'$key':" . Convert::array2json( $value );

View File

@ -166,6 +166,9 @@ class ContentController extends Controller {
return $this->getMenu($level); return $this->getMenu($level);
} }
/**
* @deprecated 2.3 Use $this->Level(2)->URLSegment
*/
public function Section2() { public function Section2() {
return $this->Level(2)->URLSegment; return $this->Level(2)->URLSegment;
} }