Example #1
0
	/**
	 * Show the file to the client
	 *
	 * @param string $prm File requested
	 */
	public static function get($prm) {
		self::init();
		$prm = self::$cfg->dir.
			str_replace(
				array(self::$cfg->webDir.'/', '/'),
				array('', DS)
				, $prm);
		if (self::$cfg->getInArray('forceDownload', file::getExt($prm)))
			response::getInstance()->sendFile($prm);
		else
			response::getInstance()->showFile($prm);
	}
Example #2
0
 /**
  * Get a db object
  *
  * @param string $type Element type (table, rowset or row)
  * @param db_table|string $table
  * @param array $prm Array parameter for the factory
  * @return db_table|db_rowset|db_row
  */
 public static function get($type, $table, array $prm = array())
 {
     if ($type == 'table' && array_key_exists($table, self::$tables)) {
         return self::$tables[$table];
     }
     self::init();
     if ($table instanceof db_table) {
         $tableName = $table->getName();
         if (!array_key_exists('table', $prm)) {
             $prm['table'] = $table;
         }
     } else {
         $tableName = $table;
         if ($type == 'table' && !array_key_exists('name', $prm)) {
             $prm['name'] = $table;
         } else {
             if ($type == 'row' && !array_key_exists('table', $prm)) {
                 $db = array_key_exists('db', $prm) ? $prm['db'] : self::getInstance();
                 $prm['table'] = self::get('table', $tableName, array('db' => $db));
             }
         }
     }
     if (!($className = self::$cfg->getInArray($type, $tableName)) && !factory::isCreable($className = 'db_' . $type . '_' . $tableName)) {
         $className = self::$cfg->get($type . 'Class');
     }
     if ($type == 'table') {
         self::$tables[$table] = factory::get($className, $prm);
         return self::$tables[$table];
     }
     return factory::get($className, $prm);
 }
Example #3
0
 public static function errorHandler($code, $message, $file, $line)
 {
     self::initCfg();
     $msg = self::$cfg->getInArray('errors', $code) . ': ' . $message . ' at ' . $file . ':' . $line;
     $stopCfg = self::$cfg->stop;
     $stop = is_array($stopCfg) ? in_array($code, $stopCfg) : $stopCfg;
     if ($stop) {
         $e = new nException($msg, $code);
         $e->line = $line;
         $e->file = $file;
         throw $e;
         return true;
     } else {
         // Maybe log something somewhere?
     }
 }
Example #4
0
	/**
	 * Get the translation for a keyword
	 *
	 * @param string $key The keyword
	 * @param bool $show Indicate if the word found should be directly shown
	 * @param bool $out Indicate if the word should be outted
	 * @return null|string
	 */
	public static function __($key, $show=false, $out=true) {
		self::initCfg();
		$ret = null;
		if (strpos($key, '_') !== false) {
			$keys = explode('_', $key);
			$ret = self::$cfg->getInArray($keys[0], $keys[1]);
		} else
			$ret = self::$cfg->get($key);
		
		if ($out)
			$ret = utils::htmlOut($ret);
		
		if (is_array($ret))
			$ret = array_map('nl2br', $ret);
		else
			$ret = nl2br($ret);
		
		if ($show)
			echo $ret;
		else
			return $ret;
	}
Example #5
0
 /**
  * Get a new object, with loading its definition and configuration
  *
  * @param string $className The classname to create
  * @param array $cfg The config
  * @return object The new object
  */
 public static function get($className, array $cfg = array())
 {
     if (self::$cfg && ($tmp = self::$cfg->getInArray('classAlias', $className))) {
         $className = $tmp;
     }
     self::load($className);
     $ref = new nReflection();
     if ($ref->rebuild($className)) {
         $prm = self::loadCfg($className);
         self::mergeCfg($prm, $cfg);
         $inst = $ref->newInstanceCfg(new config($prm));
         return $inst;
     } else {
         throw new nException('Factory - load: Unable to bluid ' . $className . '.');
     }
 }
Example #6
0
 /**
  * Get the Mime Type of a file
  *
  * @param string $file File path name
  * @return string
  */
 public static function getType($file)
 {
     self::initCfg();
     $ret = self::$cfg->getInArray('mimes', strtolower(self::getExt($file)));
     if (!$ret) {
         $ret = self::$cfg->getInArray('mimes', 'unknown');
     }
     return $ret;
     $ret = false;
     if (self::exists($file)) {
         $finfo = new finfo(FILEINFO_MIME);
         if ($finfo) {
             $ret = $finfo->file($filename);
             $finfo->close();
         } else {
             $ret = mime_content_type($file);
         }
     }
     return $ret;
 }
Example #7
0
	/**
	 * Get an attribute
	 *
	 * @param string $name Attribute name
	 * @return mixed|null The attribute or null if not set
	 */
	public function getAttr($name) {
		return $this->cfg->getInArray('attributes', $name);
	}