public function toNamespace($className = null, $separator = self::dot, $reduce = 1) { self::$separator = $separator; if (self::$mode == true) { $className = is_string($className) ? $className : self::$working; if (strstr($className, self::$separator)) { $arrClassName = array_reverse(explode(self::$separator, $className)); } else { $underscore = QTool::init()->toUnderscore($className); $array = QTool::init()->toArray($underscore, self::uscore); self::$mode = true; $arrClassName = array_reverse($array); } $arrNamespace = array(); foreach ($arrClassName as $key => $strName) { $arrNamespace[] = $key < count($arrClassName) - 1 ? QInflector::init()->pluralize($strName) : $strName; } self::set(implode(self::dot, $arrNamespace)); self::$separator = self::dot; return $this; } else { $arrClassName = strstr($className, self::$separator) ? array_reverse(explode(self::$separator, $className)) : array_reverse(QTool::init()->toArray(QTool::init()->toUnderscore($className)), self::$separator); $arrNamespace = array(); foreach ($arrClassName as $key => $strName) { $arrNamespace[] = $key < count($arrClassName) - $reduce ? QInflector::init()->pluralize($strName) : $strName; } return implode(self::dot, $arrNamespace); } }
/** * constructor: * - initializes xml objects * - adds package info * - binds methods to visualisation type * - sets default property values * @return void */ public function __construct() { // identifies context part of class name $this->context = QTool::make()->toUnderscore(get_class($this))->toArray()->get(); // package = context $this->package = $this->getContext(); // xml root node $xml = '<?xml version="1.0" encoding="UTF-8"?><' . $this->rootNode . '></' . $this->rootNode . '>'; // set api section $this->object["api"] = new SimpleXMLElement($xml); $api = $this->object["api"]; $apiscript = $api->addChild('script'); $apiscript->addAttribute("type", "text/javascript"); $apiscript->addAttribute("src", "http://www.google.com/jsapi"); // set base section $this->object["base"] = new SimpleXMLElement($xml); $object = $this->object["base"]; $script = $object->addChild("script"); $script->addAttribute("type", "text/javascript"); // do ignore if container must not be rendered if (empty($this->ignoreContainer)) { $this->object["div"] = new SimpleXMLElement($xml); $object = $this->object["div"]; $object->addChild("div"); // add attributes for local requirements switch ($this->getContext()) { case "map": case "annotatedtimeline": $object->div->addAttribute("style", 'width:' . $this->drawProperties["width"] . ";height:" . $this->drawProperties["height"] . ";"); break; } } $this->initDrawProperties(); }