/**
	 * Construct the XML
	 *
	 * @access public
	 * @since 1.0.8
	 */
	public function constructXML()
	{
		$this->_xmlToolBox->startTag("Cookie");
		
		$cookies = $_COOKIE;		
		foreach($cookies as $name => $content)
		{			
			$cookie = new SLS_Cookie($name);
			$cookieParams = $cookie->getParams();
			if (!empty($cookieParams))
			{
				$this->_xmlToolBox->startTag("item",array("name" => $name));
					$this->_xmlToolBox->startTag("params");
					foreach($cookieParams as $key => $value)
					{
						if (empty($value))
							$value = "null";
						if (is_object($value))
							$value = SLS_String::printArray(SLS_String::objectToArray($value));
						else if (is_array($value))
							$value = SLS_String::printArray($value);
						
						$this->_xmlToolBox->startTag("param");
							$this->_xmlToolBox->addFullTag("name", $key, true);
							$this->_xmlToolBox->addFullTag("value", $value, true);
						$this->_xmlToolBox->endTag("param");
					}
					$this->_xmlToolBox->endTag("params");
				$this->_xmlToolBox->endTag("item");
			}
		}
		
		$this->_xmlToolBox->endTag("Cookie");
	}	
	/**
	 * Construct the XML
	 *
	 * @access public
	 * @since 1.0
	 */
	public function constructXML()
	{
		$this->_xmlToolBox->startTag("Session");
		
		$params = $this->_session->getParams();		
		uksort($params,"strnatcasecmp");
		$this->_xmlToolBox->startTag("params");
		foreach($params as $key => $value)
		{
			$type = "string";

			if (empty($value))
				$value = "null";
			if (is_object($value))
			{
				$value = str_replace("\t","    ", SLS_String::printObject(json_encode($value)));
				$type = "object";
			}
			else if (is_array($value))
			{
				$value = str_replace("\t","    ", SLS_String::printArray($value));
				$type = "array";
			}
			$this->_xmlToolBox->startTag("param", array("type" => $type));
			$this->_xmlToolBox->addFullTag("name",$key,true);
			$this->_xmlToolBox->addFullTag("value",$value,true);
			$this->_xmlToolBox->endTag("param");
		}
		$this->_xmlToolBox->endTag("params");
		
		$this->_xmlToolBox->endTag("Session");
	}	
예제 #3
0
	/**
	 * Construct the XML
	 *
	 * @access public
	 * @since 1.0
	 */
	public function constructXML()
	{
		$this->_xmlToolBox->startTag("Http");
		
		$methods = array("GET","POST","FILES");		
		$this->_xmlToolBox->startTag("params");
			$params = $this->_http->getParams();
			uksort($params,"strnatcasecmp");
			foreach($params as $key => $value)
			{
				$this->_xmlToolBox->startTag("param",array("method"=>"NATIVE","type" => ((is_array($value)) ? "array" : "string")));
					$this->_xmlToolBox->addFullTag("name",$key,true);
					$this->_xmlToolBox->addFullTag("value",(is_array($value)) ? str_replace("\t","    ",  SLS_String::printArray($value)) : $value,true);
				$this->_xmlToolBox->endTag("param");
			}
			$this->_xmlToolBox->startTag("param",array("method"=>"SLS","type"=>"string"));
				$this->_xmlToolBox->addFullTag("name","genericmode",true);
				$this->_xmlToolBox->addFullTag("value",$this->_generic->getGenericControllerName(),true);
			$this->_xmlToolBox->endTag("param");
			$this->_xmlToolBox->startTag("param",array("method"=>"SLS","type"=>"string"));
				$this->_xmlToolBox->addFullTag("name","genericsmode",true);
				$this->_xmlToolBox->addFullTag("value",$this->_generic->getGenericScontrollerName(),true);
			$this->_xmlToolBox->endTag("param");
			$controllerBo = array_shift($this->_generic->getControllersXML()->getTags("//controllers/controller[@isBo='true']/@name"));
			$this->_xmlToolBox->startTag("param",array("method"=>"SLS","type"=>"string"));
				$this->_xmlToolBox->addFullTag("name","genericmodebo",true);
				$this->_xmlToolBox->addFullTag("value",$controllerBo,true);
			$this->_xmlToolBox->endTag("param");
			$this->_xmlToolBox->startTag("param",array("method"=>"SLS","type"=>"string"));
				$this->_xmlToolBox->addFullTag("name","request_uri",true);
				$this->_xmlToolBox->addFullTag("value",str_replace("/","|",substr($_SERVER["REQUEST_URI"],1)),true);
			$this->_xmlToolBox->endTag("param");
		$this->_xmlToolBox->endTag("params");
		
		$this->_xmlToolBox->endTag("Http");
	}
예제 #4
0
	/**
	 * Magic method to print current object
	 * 
	 * @access public
	 * @return string $this->getParams formated current object property
	 * @since 1.0.9
	 */
	public function __toString()
	{
		return SLS_String::printArray($this->getParams(true));
	}
예제 #5
0
	/**
	 * Get trace infos	 
	 *
	 * @access public static
	 * @param array $traceElt associative array contained trace informations recovered by the raise of the exception
	 * @param bool $html if we want a HTML render (version dev)
	 * @return string $trace trace infos shaped (html ou plain)
	 * @since 1.0
	 */
	public static function getTraceInfo($traceElt,$html=false) 
	{
		$info = $traceElt['class'] . $traceElt['type'] . $traceElt['function'];
		$info .= '(';
		if ($traceElt['args']) 
		{			
			for ($i = 0; $i < count($traceElt['args']); $i++) 
			{
				$arg = $traceElt['args'][$i];				
				if ($html)
				{
					if (is_array($arg))
						$info .= '<a href="#" onclick="return false;" class="tooltip" title="'.gettype($arg).'" rel="<pre name=\'highlight_'.uniqid().'\' class=\'brush:php\'>'.SLS_String::printArray($arg).'</pre>">'.gettype($arg).'</a>';
					else if (is_object($arg))
						$info .= '<a href="#" onclick="return false;" class="tooltip" title="'.get_class($arg).'" rel="<pre name=\'highlight_'.uniqid().'\' class=\'brush:js\'>'.SLS_String::printObject(str_replace(array('"',':'),array("'",': '),json_encode($arg))).'</pre>">'.gettype($arg).'</a>';
					else 
					{
						if (is_string($arg) && (SLS_String::startsWith(trim(strtolower($arg)),"select") || SLS_String::startsWith(trim(strtolower($arg)),"update") || SLS_String::startsWith(trim(strtolower($arg)),"insert") || SLS_String::startsWith(trim(strtolower(arg)),"delete")))
							$info .= '<a href="#" onclick="return false;" class="tooltip" title="'.gettype($arg).'" rel="<pre name=\'highlight_'.uniqid().'\' class=\'brush:sql\'>'.(is_string($arg) ? trim($arg) : $arg).'</pre>">'.gettype($arg).'</a>';
						else	
							$info .= '<a href="#" onclick="return false;" class="tooltip" title="'.gettype($arg).'" rel="<pre name=\'highlight_'.uniqid().'\' class=\'brush:php\'>&#34;'.(is_string($arg) ? trim($arg) : $arg).'&#34;</pre>">'.gettype($arg).'</a>';
					}					
				}
				else
					$info .= is_object($arg) ? get_class($arg) : ''.gettype($arg).'';
				if ($i < count($traceElt['args']) - 1)
					$info .= ', ';				
			}
		}
		$info .= ')';
		return $info;
	}
예제 #6
0
	/**
	 * Log execution time
	 * 
	 * @access public
	 * @param float $time execution time
	 * @param string $message message to log
	 * @param string $detail detail
	 * @param string $type type of process
	 * @since 1.0.5
	 */
	public function logTime($time,$message,$detail="",$type="unknown")
	{
		#echo "[".$type."] || ".date("Y-m-d H:i:s")." || ".$time." || ".$message." || "."Detail: ".$detail."<br />";
		
		// Developer monitoring
		if ($this->getSide() == "user" && $this->getBo() != $this->getGenericControllerName())
		{
			$types = array("statics" 		=> array("time" => "0", "logs" => array()),
						   "components" 	=> array("time" => "0", "logs" => array()),
						   "routing" 		=> array("time" => "0", "msg"  => ""),
						   "init" 			=> array("time" => "0", "msg"  => ""),
						   "action" 		=> array("time" => "0", "msg"  => ""),
						   "sql" 			=> array("time" => "0", "logs" => array()),
						   "parsing_html" 	=> array("time" => "0", "msg"  => ""),
						   "parsing_xsl" 	=> array("time" => "0", "msg"  => ""),
						   "flush_cache" 	=> array("time" => "0", "logs" => array()));
			$logSession = $this->_session->getParam("sls_dev_logs");
			$devLogs = (empty($logSession)) ? $types : $logSession;
			switch($type)
	    	{
	    		case "Controller Static":
	    			$devLogs["statics"]["time"] += $time;
	    			$devLogs["statics"]["logs"][] = array("time" => $time, "msg" => trim(SLS_String::substrAfterFirstDelimiter($detail,"Controller:")));
	    			break;
	    		case "Controller Component":
	    			$devLogs["components"]["time"] += $time;
	    			$devLogs["components"]["logs"][] = array("time" => $time, "msg" => trim(SLS_String::substrAfterFirstDelimiter($detail,"Controller:")));
	    			break;
	    		case "Controller Front":
	    			$mapping = trim(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($message,"Resolve Mapping ("),")"));
	    			$mappingController = SLS_String::substrBeforeFirstDelimiter($mapping,"/");
	    			$mappingAction = SLS_String::substrAfterFirstDelimiter($mapping,"/");
	    			$devLogs["routing"]["time"] += $time;
	    			$devLogs["routing"]["msg"] = SLS_String::printArray(array("mode" => $mappingController, "smode" => $mappingAction));
	    			break;
	    		case "Controller Init":
	    			$devLogs["init"]["time"] += $time;
	    			break;
	    		case "Controller Action":
	    			$devLogs["action"]["time"] += $time;
	    			break;
	    		case "MySQL Query":
					$message = trim((!SLS_String::startsWith($detail,"Query:")) ? $message : SLS_String::substrAfterFirstDelimiter($detail,"Query:"));
					if ($message == "MySQL Connecting")
						$message = "Connection"." |n|".$detail;
					$message = str_replace(array("|n|"),array("\n"),$message);
	    			$devLogs["sql"]["time"] += $time;
	    			$devLogs["sql"]["logs"][] = array("time" => $time, "msg" => $message);
	    			break;
	    		case "HTML Parsing":
	    			$devLogs["parsing_html"]["time"] += $time;
	    			break;
	    		case "XML/XSL Parsing":
	    			$devLogs["parsing_xsl"]["time"] += $time;
	    			break;
	    		case "Flush Cache":
	    			$devLogs["flush_cache"]["time"] += $time;
	    			$devLogs["flush_cache"]["logs"][] = array("time" => $time, "msg" => $detail);
	    			break;
	    	}
	    	$this->_session->setParam("sls_dev_logs",$devLogs);
		}
		
		if (!$this->isMonitoring())
			return;
		
		// Objects
		$nbOccurencesFiles = 0;
		$nbMaxLines = 5000;
		$directory = "monitoring/".date("Y-m");
		$fileName = date("Y-m-d");
		$filePath = "";
		
		// Check if monitoring directory exists
		if (!file_exists($this->getPathConfig("logs")."monitoring"))
			mkdir($this->getPathConfig("logs")."monitoring",0777);	
		
		// If month directory doesn't exists, create it			
		if (!file_exists($this->getPathConfig("logs").$directory))			
			mkdir($this->getPathConfig("logs").$directory,0777);
			
		// Count the number of hits of log file			
		$handle = opendir($this->getPathConfig("logs").$directory);
		while (false !== ($file = readdir($handle)))
			if (SLS_String::startsWith($file,$fileName))
				$nbOccurencesFiles++;
    	closedir($handle);
    	
    	// If the current file log doesn't exists, create it		    
	    if ($nbOccurencesFiles == 0)
	    {
	    	touch($this->getPathConfig("logs").$directory."/".$fileName."_0.log");
	    	$filePath = $this->getPathConfig("logs").$directory."/".$fileName."_0.log";
	    }
	    // Else, locate it
	    else	    
	    	$filePath = $this->getPathConfig("logs").$directory."/".$fileName."_".($nbOccurencesFiles-1).".log";
	    
	    // Then, if and only if the file log has been located, increased or created : write into the logs		    
	    if (is_file($filePath) && $this->getSide() == "user")
	    {
	    	$oldContentLog = file_get_contents($filePath);
	    	$newContentLog = "".$type." || ".date("Y-m-d H:i:s")." || ".$time." || ".$message." || ".$detail;
	    	if (SLS_String::endsWith($newContentLog,"\n"))
	    		$newContentLog = SLS_String::substrBeforeLastDelimiter($newContentLog,"\n");
	    	$newContentLog = str_replace("\n","|n|",$newContentLog);
	    	    	
	    	file_put_contents($filePath,$newContentLog."\n".$oldContentLog,LOCK_EX);
	    		    	
	    	if ($type == "Render")
	    	{
	    		$oldContentLog = file_get_contents($filePath);
	    		$newContentLog = "#|end|#";
	    		file_put_contents($filePath,$newContentLog."\n".$oldContentLog,LOCK_EX);
	    		
		    	// If the max number of lines has been reach, increase the file log version		    
			    if (SLS_String::countLines(file_get_contents($filePath)) >= $nbMaxLines)
			    {
			    	touch($this->getPathConfig("logs").$directory."/".$fileName."_".$nbOccurencesFiles.".log");
			    	$filePath = $this->getPathConfig("logs").$directory."/".$fileName."_".$nbOccurencesFiles.".log";
			    }
	    	}
	    }
	}