diff --git a/audit.php b/audit.php index 1338ca8c..6fa2e090 100644 --- a/audit.php +++ b/audit.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Data validator class Audit extends Prefab { diff --git a/auth.php b/auth.php index 5f7e0508..1c271ce5 100644 --- a/auth.php +++ b/auth.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Authorization/authentication plug-in class Auth { diff --git a/base.php b/base.php index fd0c97ba..5dc71627 100644 --- a/base.php +++ b/base.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Factory class for single-instance objects abstract class Prefab { @@ -29,7 +31,7 @@ abstract class Prefab { **/ static function instance() { if (!Registry::exists($class=get_called_class())) { - $ref=new Reflectionclass($class); + $ref=new \Reflectionclass($class); $args=func_get_args(); Registry::set($class, $args?$ref->newinstanceargs($args):new $class); @@ -40,7 +42,7 @@ static function instance() { } //! Base structure -final class Base extends Prefab implements ArrayAccess { +final class Base extends Prefab implements \ArrayAccess { //@{ Framework details const @@ -460,7 +462,7 @@ function checked($key) { **/ function visible($obj,$key) { if (property_exists($obj,$key)) { - $ref=new ReflectionProperty(get_class($obj),$key); + $ref=new \ReflectionProperty(get_class($obj),$key); $out=$ref->ispublic(); unset($ref); return $out; @@ -699,7 +701,7 @@ function extract($arr,$prefix) { * @param $prefix string **/ function constants($class,$prefix='') { - $ref=new ReflectionClass($class); + $ref=new \ReflectionClass($class); return $this->extract($ref->getconstants(),$prefix); } @@ -760,7 +762,7 @@ function recursive($arg,$func,$stack=NULL) { switch (gettype($arg)) { case 'object': if (method_exists('ReflectionClass','iscloneable')) { - $ref=new ReflectionClass($arg); + $ref=new \ReflectionClass($arg); if ($ref->iscloneable()) { $arg=clone($arg); $cast=is_a($arg,'IteratorAggregate')? @@ -1617,7 +1619,7 @@ function grab($func,$args=NULL) { if (is_subclass_of($parts[1],'Prefab')) $parts[1]=call_user_func($parts[1].'::instance'); else { - $ref=new ReflectionClass($parts[1]); + $ref=new \ReflectionClass($parts[1]); $parts[1]=method_exists($parts[1],'__construct')? $ref->newinstanceargs($args): $ref->newinstance(); @@ -1896,7 +1898,7 @@ protected function autoload($class) { is_file($file=$auto.$class.'.php') || is_file($file=$auto.strtolower($class).'.php') || is_file($file=strtolower($auto.$class).'.php')) - return require($file); + return require_once($file); } /** @@ -2394,7 +2396,7 @@ function load($dsn) { list($host,$port)=$parts; else $host=$parts[0]; - $this->ref=new Redis; + $this->ref=new \Redis; if(!$this->ref->connect($host,$port,2)) $this->ref=NULL; } @@ -2558,8 +2560,8 @@ class Preview extends View { $filter=array( 'esc'=>'$this->esc', 'raw'=>'$this->raw', - 'alias'=>'\Base::instance()->alias', - 'format'=>'\Base::instance()->format' + 'alias'=>'\F3\Base::instance()->alias', + 'format'=>'\F3\Base::instance()->format' ); /** @@ -2575,7 +2577,7 @@ function token($str) { $str=trim($parts[1]); foreach (Base::instance()->split($parts[2]) as $func) $str=is_string($cmd=$this->filter($func))?$cmd.'('.$str.')': - '\Base::instance()->call('. + '\F3\Base::instance()->call('. '$this->filter(\''.$func.'\'),array('.$str.'))'; } return $str; @@ -2631,7 +2633,7 @@ function($expr) use($self) { **/ function resolve($str,array $hive=NULL) { if (!$hive) - $hive=\Base::instance()->hive(); + $hive=Base::instance()->hive(); extract($hive); ob_start(); eval(' ?>'.$this->build($str).'constants($this,'LC_'); + return Base::instance()->constants($this,'LC_'); } /** @@ -3044,7 +3046,7 @@ function languages() { * @return array **/ function countries() { - return \Base::instance()->constants($this,'CC_'); + return Base::instance()->constants($this,'CC_'); } } diff --git a/basket.php b/basket.php index 94e03063..3e79f335 100644 --- a/basket.php +++ b/basket.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Session-based pseudo-mapper class Basket extends Magic { @@ -193,7 +195,7 @@ function drop() { **/ function copyfrom($var) { if (is_string($var)) - $var=\Base::instance()->get($var); + $var=Base::instance()->get($var); foreach ($var as $key=>$val) $this->set($key,$val); } @@ -204,7 +206,7 @@ function copyfrom($var) { * @param $key string **/ function copyto($key) { - $var=&\Base::instance()->ref($key); + $var=&Base::instance()->ref($key); foreach ($this->item as $key=>$field) $var[$key]=$field; } diff --git a/bcrypt.php b/bcrypt.php index 6ecd61e4..68f9ef22 100644 --- a/bcrypt.php +++ b/bcrypt.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Lightweight password hashing library class Bcrypt extends Prefab { diff --git a/db/cursor.php b/db/cursor.php index baef9531..e38a1943 100644 --- a/db/cursor.php +++ b/db/cursor.php @@ -20,10 +20,10 @@ */ -namespace DB; +namespace F3\DB; //! Simple cursor implementation -abstract class Cursor extends \Magic implements \IteratorAggregate { +abstract class Cursor extends \F3\Magic implements \IteratorAggregate { //@{ Error messages const diff --git a/db/jig.php b/db/jig.php index 736735c4..32af6220 100644 --- a/db/jig.php +++ b/db/jig.php @@ -20,7 +20,7 @@ */ -namespace DB; +namespace F3\DB; //! In-memory/flat-file DB wrapper class Jig { @@ -54,7 +54,7 @@ function &read($file) { $this->data[$file]=array(); return $this->data[$file]; } - $fw=\Base::instance(); + $fw=\F3\Base::instance(); $raw=$fw->read($dst); switch ($this->format) { case self::FORMAT_JSON: @@ -77,7 +77,7 @@ function &read($file) { function write($file,array $data=NULL) { if (!$this->dir) return count($this->data[$file]=$data); - $fw=\Base::instance(); + $fw=\F3\Base::instance(); switch ($this->format) { case self::FORMAT_JSON: $out=json_encode($data,@constant('JSON_PRETTY_PRINT')); @@ -142,8 +142,8 @@ function drop() { **/ function __construct($dir=NULL,$format=self::FORMAT_JSON) { if ($dir && !is_dir($dir)) - mkdir($dir,\Base::MODE,TRUE); - $this->uuid=\Base::instance()->hash($this->dir=$dir); + mkdir($dir,\F3\Base::MODE,TRUE); + $this->uuid=\F3\Base::instance()->hash($this->dir=$dir); $this->format=$format; } diff --git a/db/jig/mapper.php b/db/jig/mapper.php index f0f3953c..817bccac 100644 --- a/db/jig/mapper.php +++ b/db/jig/mapper.php @@ -20,10 +20,10 @@ */ -namespace DB\Jig; +namespace F3\DB\Jig; //! Flat-file DB mapper -class Mapper extends \DB\Cursor { +class Mapper extends \F3\DB\Cursor { protected //! Flat-file DB wrapper @@ -99,7 +99,7 @@ protected function factory($id,$row) { $mapper->document[$field]=$val; $mapper->query=array(clone($mapper)); if (isset($mapper->trigger['load'])) - \Base::instance()->call($mapper->trigger['load'],$mapper); + \F3\Base::instance()->call($mapper->trigger['load'],$mapper); return $mapper; } @@ -128,7 +128,7 @@ function($token) use($self) { return '$'.preg_replace_callback( '/(\.\w+)|\[((?:[^\[\]]*|(?R))*)\]/', function($expr) use($self) { - $fw=\Base::instance(); + $fw=\F3\Base::instance(); return '['. ($expr[1]? @@ -163,8 +163,8 @@ function find($filter=NULL,array $options=NULL,$ttl=0,$log=TRUE) { 'limit'=>0, 'offset'=>0 ); - $fw=\Base::instance(); - $cache=\Cache::instance(); + $fw=\F3\Base::instance(); + $cache=\F3\Cache::instance(); $db=$this->db; $now=microtime(TRUE); $data=array(); @@ -306,7 +306,7 @@ function skip($ofs=1) { $this->document=($out=parent::skip($ofs))?$out->document:array(); $this->id=$out?$out->id:NULL; if ($this->document && isset($this->trigger['load'])) - \Base::instance()->call($this->trigger['load'],$this); + \F3\Base::instance()->call($this->trigger['load'],$this); return $out; } @@ -326,7 +326,7 @@ function insert() { $this->id=$id; $pkey=array('_id'=>$this->id); if (isset($this->trigger['beforeinsert']) && - \Base::instance()->call($this->trigger['beforeinsert'], + \F3\Base::instance()->call($this->trigger['beforeinsert'], array($this,$pkey))===FALSE) return $this->document; $data[$id]=$this->document; @@ -334,7 +334,7 @@ function insert() { $db->jot('('.sprintf('%.1f',1e3*(microtime(TRUE)-$now)).'ms) '. $this->file.' [insert] '.json_encode($this->document)); if (isset($this->trigger['afterinsert'])) - \Base::instance()->call($this->trigger['afterinsert'], + \F3\Base::instance()->call($this->trigger['afterinsert'], array($this,$pkey)); $this->load(array('@_id=?',$this->id)); return $this->document; @@ -349,7 +349,7 @@ function update() { $now=microtime(TRUE); $data=&$db->read($this->file); if (isset($this->trigger['beforeupdate']) && - \Base::instance()->call($this->trigger['beforeupdate'], + \F3\Base::instance()->call($this->trigger['beforeupdate'], array($this,array('_id'=>$this->id)))===FALSE) return $this->document; $data[$this->id]=$this->document; @@ -357,7 +357,7 @@ function update() { $db->jot('('.sprintf('%.1f',1e3*(microtime(TRUE)-$now)).'ms) '. $this->file.' [update] '.json_encode($this->document)); if (isset($this->trigger['afterupdate'])) - \Base::instance()->call($this->trigger['afterupdate'], + \F3\Base::instance()->call($this->trigger['afterupdate'], array($this,array('_id'=>$this->id))); return $this->document; } @@ -385,7 +385,7 @@ function erase($filter=NULL) { else return FALSE; if (isset($this->trigger['beforeerase']) && - \Base::instance()->call($this->trigger['beforeerase'], + \F3\Base::instance()->call($this->trigger['beforeerase'], array($this,$pkey))===FALSE) return FALSE; $db->write($this->file,$data); @@ -395,7 +395,7 @@ function erase($filter=NULL) { array_slice($filter,1,NULL,TRUE); $args=is_array($args)?$args:array(1=>$args); foreach ($args as $key=>$val) { - $vals[]=\Base::instance()-> + $vals[]=\F3\Base::instance()-> stringify(is_array($val)?$val[0]:$val); $keys[]='/'.(is_numeric($key)?'\?':preg_quote($key)).'/'; } @@ -404,7 +404,7 @@ function erase($filter=NULL) { $this->file.' [erase] '. ($filter?preg_replace($keys,$vals,$filter[0],1):'')); if (isset($this->trigger['aftererase'])) - \Base::instance()->call($this->trigger['aftererase'], + \F3\Base::instance()->call($this->trigger['aftererase'], array($this,$pkey)); return TRUE; } @@ -427,7 +427,7 @@ function reset() { **/ function copyfrom($var,$func=NULL) { if (is_string($var)) - $var=\Base::instance()->get($var); + $var=\F3\Base::instance()->get($var); if ($func) $var=call_user_func($func,$var); foreach ($var as $key=>$val) @@ -440,7 +440,7 @@ function copyfrom($var,$func=NULL) { * @param $key string **/ function copyto($key) { - $var=&\Base::instance()->ref($key); + $var=&\F3\Base::instance()->ref($key); foreach ($this->document as $key=>$field) $var[$key]=$field; } @@ -467,7 +467,7 @@ function getiterator() { * @param $db object * @param $file string **/ - function __construct(\DB\Jig $db,$file) { + function __construct(\F3\DB\Jig $db,$file) { $this->db=$db; $this->file=$file; $this->reset(); diff --git a/db/jig/session.php b/db/jig/session.php index e4dca2fe..9a2c2326 100644 --- a/db/jig/session.php +++ b/db/jig/session.php @@ -20,7 +20,7 @@ */ -namespace DB\Jig; +namespace F3\DB\Jig; //! Jig-managed session handler class Session extends Mapper { @@ -67,7 +67,7 @@ function read($id) { if ($this->dry()) return FALSE; if ($this->get('ip')!=$this->_ip || $this->get('agent')!=$this->_agent) { - $fw=\Base::instance(); + $fw=\F3\Base::instance(); if (!isset($this->onsuspect) || FALSE===$fw->call($this->onsuspect,array($this,$id))) { //NB: `session_destroy` can't be called at that stage (`session_start` not completed) $this->destroy($id); @@ -159,12 +159,12 @@ function agent() { /** * Instantiate class - * @param $db \DB\Jig + * @param $db \F3\DB\Jig * @param $file string * @param $onsuspect callback * @param $key string **/ - function __construct(\DB\Jig $db,$file='sessions',$onsuspect=NULL,$key=NULL) { + function __construct(\F3\DB\Jig $db,$file='sessions',$onsuspect=NULL,$key=NULL) { parent::__construct($db,$file); $this->onsuspect=$onsuspect; session_set_save_handler( @@ -176,7 +176,7 @@ function __construct(\DB\Jig $db,$file='sessions',$onsuspect=NULL,$key=NULL) { array($this,'cleanup') ); register_shutdown_function('session_commit'); - $fw=\Base::instance(); + $fw=\F3\Base::instance(); $headers=$fw->get('HEADERS'); $this->_csrf=$fw->hash($fw->get('ROOT').$fw->get('BASE')).'.'. $fw->hash(mt_rand()); diff --git a/db/mongo.php b/db/mongo.php index ffe772e0..962d110d 100644 --- a/db/mongo.php +++ b/db/mongo.php @@ -20,7 +20,7 @@ */ -namespace DB; +namespace F3\DB; //! MongoDB wrapper class Mongo { @@ -102,7 +102,7 @@ function __call($func,array $args) { * @param $options array **/ function __construct($dsn,$dbname,array $options=NULL) { - $this->uuid=\Base::instance()->hash($this->dsn=$dsn); + $this->uuid=\F3\Base::instance()->hash($this->dsn=$dsn); $class=class_exists('\MongoClient')?'\MongoClient':'\Mongo'; $this->db=new \MongoDB(new $class($dsn,$options?:array()),$dbname); $this->setprofilinglevel(2); diff --git a/db/mongo/mapper.php b/db/mongo/mapper.php index e814b293..bd679521 100644 --- a/db/mongo/mapper.php +++ b/db/mongo/mapper.php @@ -20,10 +20,10 @@ */ -namespace DB\Mongo; +namespace F3\DB\Mongo; //! MongoDB mapper -class Mapper extends \DB\Cursor { +class Mapper extends \F3\DB\Cursor { protected //! MongoDB wrapper @@ -94,7 +94,7 @@ protected function factory($row) { $mapper->document[$key]=$val; $mapper->query=array(clone($mapper)); if (isset($mapper->trigger['load'])) - \Base::instance()->call($mapper->trigger['load'],$mapper); + \F3\Base::instance()->call($mapper->trigger['load'],$mapper); return $mapper; } @@ -126,8 +126,8 @@ function select($fields=NULL,$filter=NULL,array $options=NULL,$ttl=0) { 'limit'=>0, 'offset'=>0 ); - $fw=\Base::instance(); - $cache=\Cache::instance(); + $fw=\F3\Base::instance(); + $cache=\F3\Cache::instance(); if (!($cached=$cache->exists($hash=$fw->hash($this->db->dsn(). $fw->stringify(array($fields,$filter,$options))).'.mongo', $result)) || !$ttl || $cached[0]+$ttlexists($hash=$fw->hash($fw->stringify( array($filter))).'.mongo',$result)) || !$ttl || $cached[0]+$ttldocument=($out=parent::skip($ofs))?$out->document:array(); if ($this->document && isset($this->trigger['load'])) - \Base::instance()->call($this->trigger['load'],$this); + \F3\Base::instance()->call($this->trigger['load'],$this); return $out; } @@ -235,13 +235,13 @@ function insert() { if (isset($this->document['_id'])) return $this->update(); if (isset($this->trigger['beforeinsert']) && - \Base::instance()->call($this->trigger['beforeinsert'], + \F3\Base::instance()->call($this->trigger['beforeinsert'], array($this,array('_id'=>$this->document['_id'])))===FALSE) return $this->document; $this->collection->insert($this->document); $pkey=array('_id'=>$this->document['_id']); if (isset($this->trigger['afterinsert'])) - \Base::instance()->call($this->trigger['afterinsert'], + \F3\Base::instance()->call($this->trigger['afterinsert'], array($this,$pkey)); $this->load($pkey); return $this->document; @@ -254,13 +254,13 @@ function insert() { function update() { $pkey=array('_id'=>$this->document['_id']); if (isset($this->trigger['beforeupdate']) && - \Base::instance()->call($this->trigger['beforeupdate'], + \F3\Base::instance()->call($this->trigger['beforeupdate'], array($this,$pkey))===FALSE) return $this->document; $this->collection->update( $pkey,$this->document,array('upsert'=>TRUE)); if (isset($this->trigger['afterupdate'])) - \Base::instance()->call($this->trigger['afterupdate'], + \F3\Base::instance()->call($this->trigger['afterupdate'], array($this,$pkey)); return $this->document; } @@ -275,14 +275,14 @@ function erase($filter=NULL) { return $this->collection->remove($filter); $pkey=array('_id'=>$this->document['_id']); if (isset($this->trigger['beforeerase']) && - \Base::instance()->call($this->trigger['beforeerase'], + \F3\Base::instance()->call($this->trigger['beforeerase'], array($this,$pkey))===FALSE) return FALSE; $result=$this->collection-> remove(array('_id'=>$this->document['_id'])); parent::erase(); if (isset($this->trigger['aftererase'])) - \Base::instance()->call($this->trigger['aftererase'], + \F3\Base::instance()->call($this->trigger['aftererase'], array($this,$pkey)); return $result; } @@ -304,7 +304,7 @@ function reset() { **/ function copyfrom($var,$func=NULL) { if (is_string($var)) - $var=\Base::instance()->get($var); + $var=\F3\Base::instance()->get($var); if ($func) $var=call_user_func($func,$var); foreach ($var as $key=>$val) @@ -317,7 +317,7 @@ function copyfrom($var,$func=NULL) { * @param $key string **/ function copyto($key) { - $var=&\Base::instance()->ref($key); + $var=&\F3\Base::instance()->ref($key); foreach ($this->document as $key=>$field) $var[$key]=$field; } @@ -352,7 +352,7 @@ function getiterator() { * @param $db object * @param $collection string **/ - function __construct(\DB\Mongo $db,$collection) { + function __construct(\F3\DB\Mongo $db,$collection) { $this->db=$db; $this->collection=$db->selectcollection($collection); $this->reset(); diff --git a/db/mongo/session.php b/db/mongo/session.php index 0b510f13..46b58e69 100644 --- a/db/mongo/session.php +++ b/db/mongo/session.php @@ -20,7 +20,7 @@ */ -namespace DB\Mongo; +namespace F3\DB\Mongo; //! MongoDB-managed session handler class Session extends Mapper { @@ -67,7 +67,7 @@ function read($id) { if ($this->dry()) return FALSE; if ($this->get('ip')!=$this->_ip || $this->get('agent')!=$this->_agent) { - $fw=\Base::instance(); + $fw=\F3\Base::instance(); if (!isset($this->onsuspect) || FALSE===$fw->call($this->onsuspect,array($this,$id))) { //NB: `session_destroy` can't be called at that stage (`session_start` not completed) $this->destroy($id); @@ -159,12 +159,12 @@ function agent() { /** * Instantiate class - * @param $db \DB\Mongo + * @param $db \F3\DB\Mongo * @param $table string * @param $onsuspect callback * @param $key string **/ - function __construct(\DB\Mongo $db,$table='sessions',$onsuspect=NULL,$key=NULL) { + function __construct(\F3\DB\Mongo $db,$table='sessions',$onsuspect=NULL,$key=NULL) { parent::__construct($db,$table); $this->onsuspect=$onsuspect; session_set_save_handler( @@ -176,7 +176,7 @@ function __construct(\DB\Mongo $db,$table='sessions',$onsuspect=NULL,$key=NULL) array($this,'cleanup') ); register_shutdown_function('session_commit'); - $fw=\Base::instance(); + $fw=\F3\Base::instance(); $headers=$fw->get('HEADERS'); $this->_csrf=$fw->hash($fw->get('ROOT').$fw->get('BASE')).'.'. $fw->hash(mt_rand()); diff --git a/db/sql.php b/db/sql.php index 60089446..40282bfe 100644 --- a/db/sql.php +++ b/db/sql.php @@ -20,7 +20,7 @@ */ -namespace DB; +namespace F3\DB; //! PDO wrapper class SQL { @@ -147,8 +147,8 @@ function exec($cmds,$args=NULL,$ttl=0,$log=TRUE) { $cmds=array($cmds); $args=array($args); } - $fw=\Base::instance(); - $cache=\Cache::instance(); + $fw=\F3\Base::instance(); + $cache=\F3\Cache::instance(); $result=FALSE; for ($i=0;$i<$count;$i++) { $cmd=$cmds[$i]; @@ -329,7 +329,7 @@ function schema($table,$fields=NULL,$ttl=0) { 'FIELD','TYPE','DEFVAL','NULLABLE','Y','PKEY','P') ); if (is_string($fields)) - $fields=\Base::instance()->split($fields); + $fields=\F3\Base::instance()->split($fields); foreach ($cmd as $key=>$val) if (preg_match('/'.$key.'/',$this->engine)) { // Improve InnoDB performance on MySQL with @@ -371,7 +371,7 @@ function schema($table,$fields=NULL,$ttl=0) { function quote($val,$type=\PDO::PARAM_STR) { return $this->engine=='odbc'? (is_string($val)? - \Base::instance()->stringify(str_replace('\'','\'\'',$val)): + \F3\Base::instance()->stringify(str_replace('\'','\'\'',$val)): $val): $this->pdo->quote($val,$type); } @@ -454,7 +454,7 @@ function __call($func,array $args) { * @param $options array **/ function __construct($dsn,$user=NULL,$pw=NULL,array $options=NULL) { - $fw=\Base::instance(); + $fw=\F3\Base::instance(); $this->uuid=$fw->hash($this->dsn=$dsn); if (preg_match('/^.+?(?:dbname|database)=(.+?)(?=;|$)/is',$dsn,$parts)) $this->dbname=$parts[1]; diff --git a/db/sql/mapper.php b/db/sql/mapper.php index ca6f8493..ebae20aa 100644 --- a/db/sql/mapper.php +++ b/db/sql/mapper.php @@ -20,10 +20,10 @@ */ -namespace DB\SQL; +namespace F3\DB\SQL; //! SQL data mapper -class Mapper extends \DB\Cursor { +class Mapper extends \F3\DB\Cursor { protected //! PDO wrapper @@ -168,7 +168,7 @@ protected function factory($row) { } $mapper->query=array(clone($mapper)); if (isset($mapper->trigger['load'])) - \Base::instance()->call($mapper->trigger['load'],$mapper); + \F3\Base::instance()->call($mapper->trigger['load'],$mapper); return $mapper; } @@ -363,7 +363,7 @@ function skip($ofs=1) { unset($field); } if (!$dry && isset($this->trigger['load'])) - \Base::instance()->call($this->trigger['load'],$this); + \F3\Base::instance()->call($this->trigger['load'],$this); return $out; } @@ -386,7 +386,7 @@ function insert() { if ($field['pkey']) $pkeys[$key]=$field['previous']; if (isset($this->trigger['beforeinsert']) && - \Base::instance()->call($this->trigger['beforeinsert'], + \F3\Base::instance()->call($this->trigger['beforeinsert'], array($this,$pkeys))===FALSE) return $this; foreach ($this->fields as $key=>&$field) { @@ -430,7 +430,7 @@ function insert() { $this->fields[$inc]['pdo_type'],$this->_id)): array($filter,$nkeys)); if (isset($this->trigger['afterinsert'])) - \Base::instance()->call($this->trigger['afterinsert'], + \F3\Base::instance()->call($this->trigger['afterinsert'], array($this,$pkeys)); } return $this; @@ -450,7 +450,7 @@ function update() { if ($field['pkey']) $pkeys[$key]=$field['previous']; if (isset($this->trigger['beforeupdate']) && - \Base::instance()->call($this->trigger['beforeupdate'], + \F3\Base::instance()->call($this->trigger['beforeupdate'], array($this,$pkeys))===FALSE) return $this; foreach ($this->fields as $key=>$field) @@ -470,7 +470,7 @@ function update() { $sql='UPDATE '.$this->table.' SET '.$pairs.$filter; $this->db->exec($sql,$args); if (isset($this->trigger['afterupdate'])) - \Base::instance()->call($this->trigger['afterupdate'], + \F3\Base::instance()->call($this->trigger['afterupdate'], array($this,$pkeys)); } return $this; @@ -517,13 +517,13 @@ function erase($filter=NULL) { } parent::erase(); if (isset($this->trigger['beforeerase']) && - \Base::instance()->call($this->trigger['beforeerase'], + \F3\Base::instance()->call($this->trigger['beforeerase'], array($this,$pkeys))===FALSE) return 0; $out=$this->db-> exec('DELETE FROM '.$this->table.' WHERE '.$filter.';',$args); if (isset($this->trigger['aftererase'])) - \Base::instance()->call($this->trigger['aftererase'], + \F3\Base::instance()->call($this->trigger['aftererase'], array($this,$pkeys)); return $out; } @@ -555,7 +555,7 @@ function reset() { **/ function copyfrom($var,$func=NULL) { if (is_string($var)) - $var=\Base::instance()->get($var); + $var=\F3\Base::instance()->get($var); if ($func) $var=call_user_func($func,$var); foreach ($var as $key=>$val) @@ -569,7 +569,7 @@ function copyfrom($var,$func=NULL) { * @param $key string **/ function copyto($key) { - $var=&\Base::instance()->ref($key); + $var=&\F3\Base::instance()->ref($key); foreach ($this->fields+$this->adhoc as $key=>$field) $var[$key]=$field['value']; } @@ -619,7 +619,7 @@ function getiterator() { * @param $fields array|string * @param $ttl int **/ - function __construct(\DB\SQL $db,$table,$fields=NULL,$ttl=60) { + function __construct(\F3\DB\SQL $db,$table,$fields=NULL,$ttl=60) { $this->db=$db; $this->engine=$db->driver(); if ($this->engine=='oci') diff --git a/db/sql/session.php b/db/sql/session.php index 60702050..a908d077 100644 --- a/db/sql/session.php +++ b/db/sql/session.php @@ -20,7 +20,7 @@ */ -namespace DB\SQL; +namespace F3\DB\SQL; //! SQL-managed session handler class Session extends Mapper { @@ -67,7 +67,7 @@ function read($id) { if ($this->dry()) return FALSE; if ($this->get('ip')!=$this->_ip || $this->get('agent')!=$this->_agent) { - $fw=\Base::instance(); + $fw=\F3\Base::instance(); if (!isset($this->onsuspect) || FALSE===$fw->call($this->onsuspect,array($this,$id))) { //NB: `session_destroy` can't be called at that stage (`session_start` not completed) $this->destroy($id); @@ -159,13 +159,13 @@ function agent() { /** * Instantiate class - * @param $db \DB\SQL + * @param $db \F3\DB\SQL * @param $table string * @param $force bool * @param $onsuspect callback * @param $key string **/ - function __construct(\DB\SQL $db,$table='sessions',$force=TRUE,$onsuspect=NULL,$key=NULL) { + function __construct(\F3\DB\SQL $db,$table='sessions',$force=TRUE,$onsuspect=NULL,$key=NULL) { if ($force) { $eol="\n"; $tab="\t"; @@ -198,7 +198,7 @@ function __construct(\DB\SQL $db,$table='sessions',$force=TRUE,$onsuspect=NULL,$ array($this,'cleanup') ); register_shutdown_function('session_commit'); - $fw=\Base::instance(); + $fw=\F3\Base::instance(); $headers=$fw->get('HEADERS'); $this->_csrf=$fw->hash($fw->get('ROOT').$fw->get('BASE')).'.'. $fw->hash(mt_rand()); diff --git a/f3.php b/f3.php index 96c7845e..67fc34a4 100644 --- a/f3.php +++ b/f3.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Legacy mode enabler class F3 { diff --git a/image.php b/image.php index c400855d..cbf3e972 100644 --- a/image.php +++ b/image.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Image manipulation tools class Image { diff --git a/log.php b/log.php index 6583cedb..4bf758ad 100644 --- a/log.php +++ b/log.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Custom logger class Log { diff --git a/magic.php b/magic.php index 5669908a..cfad9275 100644 --- a/magic.php +++ b/magic.php @@ -20,8 +20,10 @@ */ +namespace F3; + //! PHP magic wrapper -abstract class Magic implements ArrayAccess { +abstract class Magic implements \ArrayAccess { /** * Return TRUE if key is not empty diff --git a/markdown.php b/markdown.php index 9863d911..cef069b0 100644 --- a/markdown.php +++ b/markdown.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Markdown-to-HTML converter class Markdown extends Prefab { diff --git a/matrix.php b/matrix.php index 7d8ceadb..235c92ea 100644 --- a/matrix.php +++ b/matrix.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Generic array utilities class Matrix extends Prefab { diff --git a/session.php b/session.php index 8b28c936..df7980bc 100644 --- a/session.php +++ b/session.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Cache-based session handler class Session { @@ -176,7 +178,7 @@ function __construct($onsuspect=NULL,$key=NULL) { array($this,'cleanup') ); register_shutdown_function('session_commit'); - $fw=\Base::instance(); + $fw=Base::instance(); $headers=$fw->get('HEADERS'); $this->_csrf=$fw->hash($fw->get('ROOT').$fw->get('BASE')).'.'. $fw->hash(mt_rand()); diff --git a/smtp.php b/smtp.php index 8c2fcf60..cf32c183 100644 --- a/smtp.php +++ b/smtp.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! SMTP plug-in class SMTP extends Magic { diff --git a/template.php b/template.php index 8b985cde..66170bed 100644 --- a/template.php +++ b/template.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! XML-style template engine class Template extends Preview { @@ -66,7 +68,7 @@ protected function _include(array $node) { (preg_match('/^\'.*\'$/',$pair[2]) || preg_match('/\$/',$pair[2])? $pair[2]: - \Base::instance()->stringify($pair[2])); + Base::instance()->stringify($pair[2])); },$pairs)).')+get_defined_vars()': 'get_defined_vars()'; $ttl=isset($attrib['ttl'])?(int)$attrib['ttl']:0; @@ -339,7 +341,7 @@ function parse($text) { * return object **/ function __construct() { - $ref=new ReflectionClass(__CLASS__); + $ref=new \ReflectionClass(__CLASS__); $this->tags=''; foreach ($ref->getmethods() as $method) if (preg_match('/^_(?=[[:alpha:]])/',$method->name)) diff --git a/test.php b/test.php index 05e6e6c5..29096148 100644 --- a/test.php +++ b/test.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Unit test kit class Test { diff --git a/utf.php b/utf.php index fbfe0005..3e39a727 100644 --- a/utf.php +++ b/utf.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Unicode string manager class UTF extends Prefab { diff --git a/web.php b/web.php index 57fbf937..5ae6f413 100644 --- a/web.php +++ b/web.php @@ -20,6 +20,8 @@ */ +namespace F3; + //! Wrapper for various HTTP utilities class Web extends Prefab { diff --git a/web/geo.php b/web/geo.php index 498f857d..b82eb738 100644 --- a/web/geo.php +++ b/web/geo.php @@ -20,10 +20,10 @@ */ -namespace Web; +namespace F3\Web; //! Geo plug-in -class Geo extends \Prefab { +class Geo extends \F3\Prefab { /** * Return information about specified Unix time zone @@ -52,8 +52,8 @@ function tzinfo($zone) { * @param $ip string **/ function location($ip=NULL) { - $fw=\Base::instance(); - $web=\Web::instance(); + $fw=\F3\Base::instance(); + $web=\F3\Web::instance(); if (!$ip) $ip=$fw->get('IP'); $public=filter_var($ip,FILTER_VALIDATE_IP, @@ -89,8 +89,8 @@ function location($ip=NULL) { * @param $longitude float **/ function weather($latitude,$longitude) { - $fw=\Base::instance(); - $web=\Web::instance(); + $fw=\F3\Base::instance(); + $web=\F3\Web::instance(); $query=array( 'lat'=>$latitude, 'lon'=>$longitude diff --git a/web/google/staticmap.php b/web/google/staticmap.php index 71acc550..bc0130be 100644 --- a/web/google/staticmap.php +++ b/web/google/staticmap.php @@ -20,7 +20,7 @@ */ -namespace Web\Google; +namespace F3\Web\Google; //! Google Static Maps API v2 plug-in class StaticMap { @@ -49,8 +49,8 @@ function __call($func,array $args) { * @return string **/ function dump() { - $fw=\Base::instance(); - $web=\Web::instance(); + $fw=\F3\Base::instance(); + $web=\F3\Web::instance(); $out=''; return ($req=$web->request( self::URL_Static.'?'.array_reduce( diff --git a/web/openid.php b/web/openid.php index 89173d0b..7242f29c 100644 --- a/web/openid.php +++ b/web/openid.php @@ -20,10 +20,10 @@ */ -namespace Web; +namespace F3\Web; //! OpenID consumer -class OpenID extends \Magic { +class OpenID extends \F3\Magic { protected //! OpenID provider endpoint URL @@ -49,7 +49,7 @@ protected function discover($proxy) { strtolower($url['host']).(isset($url['path'])?$url['path']:'/'). (isset($url['query'])?('?'.$url['query']):''); // HTML-based discovery of OpenID provider - $req=\Web::instance()-> + $req=\F3\Web::instance()-> request($this->args['identity'],array('proxy'=>$proxy)); if (!$req) return FALSE; @@ -141,7 +141,7 @@ protected function discover($proxy) { * @param $reqd string|array **/ function auth($proxy=NULL,$attr=array(),array $reqd=NULL) { - $fw=\Base::instance(); + $fw=\F3\Base::instance(); $root=$fw->get('SCHEME').'://'.$fw->get('HOST'); if (empty($this->args['trust_root'])) $this->args['trust_root']=$root.$fw->get('BASE').'/'; @@ -182,7 +182,7 @@ function verified($proxy=NULL) { $var=array(); foreach ($this->args as $key=>$val) $var['openid.'.$key]=$val; - $req=\Web::instance()->request( + $req=\F3\Web::instance()->request( $this->url, array( 'method'=>'POST', diff --git a/web/pingback.php b/web/pingback.php index 9dd750a3..aaa10cb0 100644 --- a/web/pingback.php +++ b/web/pingback.php @@ -20,10 +20,10 @@ */ -namespace Web; +namespace F3\Web; //! Pingback 1.0 protocol (client and server) implementation -class Pingback extends \Prefab { +class Pingback extends \F3\Prefab { protected //! Transaction history @@ -35,7 +35,7 @@ class Pingback extends \Prefab { * @param $url **/ protected function enabled($url) { - $web=\Web::instance(); + $web=\F3\Web::instance(); $req=$web->request($url); $found=FALSE; if ($req && $req['body']) { @@ -62,8 +62,8 @@ protected function enabled($url) { * @param $source string **/ function inspect($source) { - $fw=\Base::instance(); - $web=\Web::instance(); + $fw=\F3\Base::instance(); + $web=\F3\Web::instance(); $parts=parse_url($source); if (empty($parts['scheme']) || empty($parts['host']) || $parts['host']==$fw->get('HOST')) { @@ -108,7 +108,7 @@ function inspect($source) { * @param $path string **/ function listen($func,$path=NULL) { - $fw=\Base::instance(); + $fw=\F3\Base::instance(); if (PHP_SAPI!='cli') { header('X-Powered-By: '.$fw->get('PACKAGE')); header('Content-Type: application/xml; '. @@ -116,7 +116,7 @@ function listen($func,$path=NULL) { } if (!$path) $path=$fw->get('BASE'); - $web=\Web::instance(); + $web=\F3\Web::instance(); $args=xmlrpc_decode_request($fw->get('BODY'),$method,$charset); $options=array('encoding'=>$charset); if ($method=='pingback.ping' && isset($args[0],$args[1])) {