Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fatfree-core to use the top level vendor namespace F3. Refs #110 #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

*/

namespace F3;

//! Data validator
class Audit extends Prefab {

Expand Down
2 changes: 2 additions & 0 deletions auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

*/

namespace F3;


//! Authorization/authentication plug-in
class Auth {
Expand Down
30 changes: 16 additions & 14 deletions base.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

*/

namespace F3;

//! Factory class for single-instance objects
abstract class Prefab {

Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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')?
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'
);

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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).'<?php ');
Expand Down Expand Up @@ -3036,15 +3038,15 @@ class ISO extends Prefab {
* @return array
**/
function languages() {
return \Base::instance()->constants($this,'LC_');
return Base::instance()->constants($this,'LC_');
}

/**
* Return list of countries indexed by ISO 3166-1 country code
* @return array
**/
function countries() {
return \Base::instance()->constants($this,'CC_');
return Base::instance()->constants($this,'CC_');
}

}
Expand Down
6 changes: 4 additions & 2 deletions basket.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

*/

namespace F3;

//! Session-based pseudo-mapper
class Basket extends Magic {

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions bcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

*/

namespace F3;

//! Lightweight password hashing library
class Bcrypt extends Prefab {

Expand Down
4 changes: 2 additions & 2 deletions db/cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions db/jig.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

*/

namespace DB;
namespace F3\DB;

//! In-memory/flat-file DB wrapper
class Jig {
Expand Down Expand Up @@ -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:
Expand All @@ -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'));
Expand Down Expand Up @@ -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;
}

Expand Down
34 changes: 17 additions & 17 deletions db/jig/mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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]?
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand All @@ -326,15 +326,15 @@ 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;
$db->write($this->file,$data);
$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;
Expand All @@ -349,15 +349,15 @@ 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;
$db->write($this->file,$data);
$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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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)).'/';
}
Expand All @@ -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;
}
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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();
Expand Down
Loading