ef.php File Reference

Go to the source code of this file.

Enumerations

enum  EF_ACTION
enum  EF_BLOCK
enum  EF_HOOKS
enum  EF_LANG
enum  REGEXP_LANG
enum  EF_CONT
 carry on More...
enum  EF_ABRT
 dont output anything More...
enum  EF_STOP
 stop here More...

Functions

 ef_log ($level, $msg)
 Logs $msg with given log $level The lower is $level,.
 ef_die ($msg="(no message)", $http="HTTP/1.0 400 Bad Request")
 Prints backtrace, logs, and dies.
 ef_include_lang ($format, $lang=FALSE)
 Include a language file.
 t ($what)
 Translate sentence using files loaded by ef_include_lang().
 ef_save_lang ($lang)
 Saves user language in a cookie.
 ef_read_hooks_file ($path)
 Reads hooks file and merges it's contents with global $ef_hooks array.
 ef_read_hooks ($dir)
 Recursively reads hooks from $dir File names should be ended with ".php" extension.
 ef_state_new ($path, $appname, &$curpath, &$vars, &$retcode)
 Switch to new ef state.
 ef_state_restore ($state)
 Switch to previous ef state.
 ef_rootname ($path)
 Returns element at path beginning - like basename(), but inverse.
 ef_htmlbase ()
 Generates the BASE HTML element.
 ef_realpath ($path, $root=FALSE, $cwd=FALSE)
 realpath() with variable root dir
 ef_chdir ($path)
 A chdir which won't cause symbolic links to be resolved in getcwd().
 ef_getcwd ()
 A getcwd() replacement which doesn't resolve symbolic links.
 ef_getreq ($name, $default=NULL)
 Retrieves value from $req with optional default value.
 ef_getget ($name, $default=NULL)
 Retrieves value from $_GET with optional default value.
 ef_path_shortcut ($path)
 Make a CSS-suitable shortcut of given path.
 ef_block_exists ($name)
 Returns true if given block is bound.
 ef_block_islink ($name)
 Returns true if given block is bound as a link.
 ef_block_clean ($name=false)
 Flushes block bindings - all or single, if block $name is given.
 ef_block_include ($name, $path)
 Register a block->file binding.
 ef_block_write ($name, $html)
 Register a block->HTML binding.
 ef_block_mv ($name, $newname)
 Register a block->link binding.
 ef_block ($name, $args=array())
 Draw given block from current ef state.
 ef_obstart ()
 ef_obstop ()
 ef_obabort ()
 ef_include_extract ($_file, &$_vars, $_override=array())
 include() which supports separate variable scope
 _ef_export ($where, &$what)
 Mark variables to be exported either as globals or template variables.
 ef_globals ()
 ef_outputs ()
 ef_run ($path, $req=array())
 The ef.
 ef_tpl ($state, $css=true)
 Generate HTML output out of passed data.
 ef_req ($path, $req=array(), $css=1)
 Convenient wrapper around ef_run and ef_tpl.
 ef_reqmap ($path, $reqmap, $css=false, $funcname="ef_req")
 A Django-like URL -> ef translator.
 ef_init ()
 Inits ef Have to be used before any other f-n from this file.

Variables

 $ef_dir = "/usr/share/php/ef"
 path to ef applications
 $ef_ctl = getcwd() . "/.."
 main application root dir
 $ef_logs = array()
 log messages go here
 $ef_log_level = 1
 maximum log level to log a message
 $ef_log_to_stdout = FALSE
 to log using "echo" or not
 $ef_log_indent_width = 1
 log indentation width
 $ef_hooks = array()
 hooks are registered here
 $ef_trans = array()
 contains translations
 $ef_default_lang = "en"
 default user language
 $ef_lang = NULL
 current language
 $ef_default_action = "/index"
 default action to run
 $ef_cli_mode = (php_sapi_name() == "cli")
 are we running in CLI environment?
 $ef_span = "span"
 HTML tag to use for CSS integration.
 $ef_reqdefs = array()
 default efreq values #5
 $ef_state
 Global current request state.
 $ef_export_helper = array()
 Helper for exports in ef_include_extract() #4.


Enumeration Type Documentation

enum EF_ABRT

dont output anything

Definition at line 36 of file ef.php.

enum EF_ACTION

Definition at line 23 of file ef.php.

enum EF_BLOCK

Definition at line 24 of file ef.php.

enum EF_CONT

carry on

Definition at line 33 of file ef.php.

enum EF_HOOKS

Definition at line 25 of file ef.php.

enum EF_LANG

Definition at line 26 of file ef.php.

enum EF_STOP

stop here

Definition at line 39 of file ef.php.

Definition at line 27 of file ef.php.


Function Documentation

_ef_export ( where,
&$  what 
)

Mark variables to be exported either as globals or template variables.

Parameters:
$where either "globals" or "outputs"
$what array with variable names

Definition at line 732 of file ef.php.

Referenced by ef_globals(), and ef_outputs().

ef_block ( name,
args = array() 
)

Draw given block from current ef state.

Parameters:
$name name of block
$args additional data to $out
Note:
if CSS support is on, a generated code will be wrapped in a HTML span tag with class name derived from efpath (see #2)

Definition at line 624 of file ef.php.

References $ef_span, $ef_state, ef_block_exists(), ef_chdir(), ef_include_extract(), ef_log(), and ef_path_shortcut().

Referenced by ef_tpl().

ef_block_clean ( name = false  ) 

Flushes block bindings - all or single, if block $name is given.

Definition at line 551 of file ef.php.

ef_block_exists ( name  ) 

Returns true if given block is bound.

Definition at line 534 of file ef.php.

Referenced by ef_block(), and ef_block_islink().

ef_block_include ( name,
path 
)

Register a block->file binding.

Parameters:
$name block name
$path file path (relative)

Definition at line 564 of file ef.php.

References $ef_state, ef_block_islink(), ef_getcwd(), and ef_realpath().

Referenced by ef_run().

ef_block_islink ( name  ) 

Returns true if given block is bound as a link.

Definition at line 542 of file ef.php.

References ef_block_exists().

Referenced by ef_block_include(), and ef_block_write().

ef_block_mv ( name,
newname 
)

Register a block->link binding.

All further file and HTML bindings for this block will be ignored. On drawing, block $newname will be taken instead of $name.

Parameters:
$name name of block to be masked
$newname name of block replacing it

Definition at line 606 of file ef.php.

References $ef_state.

ef_block_write ( name,
html 
)

Register a block->HTML binding.

Parameters:
$name block name
$html HTML code

Definition at line 584 of file ef.php.

References $ef_state, and ef_block_islink().

ef_chdir ( path  ) 

A chdir which won't cause symbolic links to be resolved in getcwd().

Returns:
old value of ef_getcwd()

Definition at line 473 of file ef.php.

References $ef_state.

Referenced by ef_block(), ef_run(), and ef_state_new().

ef_die ( msg = "(no message)",
http = "HTTP/1.0 400 Bad Request" 
)

Prints backtrace, logs, and dies.

Definition at line 119 of file ef.php.

References ef_obabort().

ef_getcwd (  ) 

A getcwd() replacement which doesn't resolve symbolic links.

Definition at line 488 of file ef.php.

Referenced by ef_block_include(), ef_realpath(), and ef_run().

ef_getget ( name,
default = NULL 
)

Retrieves value from $_GET with optional default value.

Definition at line 505 of file ef.php.

ef_getreq ( name,
default = NULL 
)

Retrieves value from $req with optional default value.

Definition at line 494 of file ef.php.

References $ef_state.

ef_globals (  ) 

Definition at line 738 of file ef.php.

References _ef_export().

ef_htmlbase (  ) 

Generates the BASE HTML element.

Note:
in HTML, put the returned string <head><base href=" HERE "></head>

Definition at line 373 of file ef.php.

ef_include_extract ( _file,
&$  _vars,
_override = array() 
)

include() which supports separate variable scope

Parameters:
$_file file to include
$_vars variable scope, passed by reference
$_override variables to override in $vars (for convenience)
Returns:
return code passed from included file

Definition at line 694 of file ef.php.

Referenced by ef_block(), and ef_run().

ef_include_lang ( format,
lang = FALSE 
)

Include a language file.

The $format should look like: 'lang.*.php', where '*' sign will be replaced with $lang. If including of such file fails, we fallback on English ("en" language).

Parameters:
$format include file format
$lang preferred language
Return values:
true preferred or default language was loaded
false nothing was loaded
Note:
watch for get_defined_vars() at the end

Definition at line 175 of file ef.php.

References $ef_lang, and ef_log().

Referenced by ef_run().

ef_init (  ) 

Inits ef Have to be used before any other f-n from this file.

Definition at line 988 of file ef.php.

References $ef_default_lang, $ef_lang, ef_log(), ef_read_hooks(), and ef_save_lang().

ef_log ( level,
msg 
)

Logs $msg with given log $level The lower is $level,.

Definition at line 96 of file ef.php.

References $ef_log_level, $ef_log_to_stdout, $ef_logs, and $ef_state.

Referenced by ef_block(), ef_include_lang(), ef_init(), ef_read_hooks_file(), ef_realpath(), ef_reqmap(), ef_run(), ef_save_lang(), and ef_tpl().

ef_obabort (  ) 

Definition at line 682 of file ef.php.

Referenced by ef_die().

ef_obstart (  ) 

Definition at line 680 of file ef.php.

Referenced by ef_run(), and ef_tpl().

ef_obstop (  ) 

Definition at line 681 of file ef.php.

Referenced by ef_run(), and ef_tpl().

ef_outputs (  ) 

Definition at line 739 of file ef.php.

References _ef_export().

ef_path_shortcut ( path  ) 

Make a CSS-suitable shortcut of given path.

E.g. /jinks/content/view/single/post -> jcvs-post

Parameters:
$path path to shorten
Returns:
string: shortcut

Definition at line 517 of file ef.php.

Referenced by ef_block().

ef_read_hooks ( dir  ) 

Recursively reads hooks from $dir File names should be ended with ".php" extension.

Definition at line 290 of file ef.php.

References ef_read_hooks_file().

Referenced by ef_init().

ef_read_hooks_file ( path  ) 

Reads hooks file and merges it's contents with global $ef_hooks array.

Parameters:
$path path to file

Definition at line 265 of file ef.php.

References ef_log().

Referenced by ef_read_hooks().

ef_realpath ( path,
root = FALSE,
cwd = FALSE 
)

realpath() with variable root dir

In other words, it translates all "./", "../", etc. in given $path and returns the result relative to given $root directory.

We don't use realpath() here, because it checks whether checked path is valid (exists) - we just want pure relative->absolute translation.

Examples:

  • Absolute $path:
    • ef_realpath("/foo/bar", "/home/root") -> "/foo/bar"
    • ef_realpath("/", "/home/root") -> "/"
  • Current working dir "/blah/blablah/dir1/dir2":
    • ef_realpath(".", "/blah/blablah") -> "/dir1/dir2"
    • ef_realpath("/", "/blah/blablah") -> "/"
    • ef_realpath("../", "/blah/blablah") -> "/dir1"
    • ef_realpath("./dir3/../../dir1", "/blah/blablah") -> "/dir1"

As you see, it's mainly useful when $path is relative.

Parameters:
$path path to translate
$root virtual root directory; if FALSE, then $ef_dir used (default)
$cwd optionally override output of ef_getcwd() function

Definition at line 412 of file ef.php.

References ef_getcwd(), and ef_log().

Referenced by ef_block_include(), and ef_run().

ef_req ( path,
req = array(),
css = 1 
)

Convenient wrapper around ef_run and ef_tpl.

  1. Handle the request
    • ef_run() is called which executes whole application logic and returns pure data
  2. Draw it
    • ef_tpl() is called which pours the data into templates and returns HTML

Parameters:
$path efpath
$req request parameters
$css passed to ef_tpl()
See also:
ef_run()

ef_tpl()

Definition at line 904 of file ef.php.

References ef_run(), and ef_tpl().

ef_reqmap ( path,
reqmap,
css = false,
funcname = "ef_req" 
)

A Django-like URL -> ef translator.

Purpose of this function is to run series of regular expressions against browser-supplied URL address and to translate it into an ef request on a match. In order to make it convenient arguments to ef request may also be specified - statically and/or derived from users URL.

Parameters:
$path path to match against
$reqmap an array of $regexp => $reqdescr entries:
  • if $reqdescr is a string, PHP function with such name is called (see #1)
  • otherwise, it must be an array:
    • $reqdescr[0] has /efpath to request
      • if path starts with a colon (:) PCRE back references may be used, e.g. if $regexp is /index/(.*) and you pass "/myapp/\1", then for URL of /index/cart/show an efpath of /myapp/cart/show will be requested
    • $reqdescr[1] holds array of URL -> $req translations, e.g.:
      • if $regexp is /index/([0-9]+)/([a-z]+) and you pass array("id", "type"), then for URL of /index/179/foobar a $req array("id" => "179", "type" => "foobar") will be generated
    • $reqdescr[2] has additional $req parts; remember that URL-derived $req is more important
    • $reqdescr[3] decides if JSON output is requested (true), otherwise (false) HTML is returned
$css to pass to ef_req()
$funcname function to call to handle the result of this URL->ef mapping

Definition at line 931 of file ef.php.

References ef_log(), and ef_run().

ef_rootname ( path  ) 

Returns element at path beginning - like basename(), but inverse.

Note:
example: assert(ef_rootname("/foo/bar/dirboo/x.php" == "foo"));
Parameters:
$path path to operate on
Return values:
false,: if it couldn't find the rootname
string,: in case it was possible

Definition at line 359 of file ef.php.

Referenced by ef_run().

ef_run ( path,
req = array() 
)

The ef.

Parameters:
$path efpath
$req request parameters
Returns:
bool: true on success, false on failure

Definition at line 751 of file ef.php.

References ef_block_include(), ef_chdir(), ef_getcwd(), ef_include_extract(), ef_include_lang(), ef_log(), ef_obstart(), ef_obstop(), ef_realpath(), ef_rootname(), ef_state_new(), and ef_state_restore().

Referenced by ef_req(), and ef_reqmap().

ef_save_lang ( lang  ) 

Saves user language in a cookie.

Parameters:
$lang the language to save as the preferred one
Returns:
bool
Return values:
true language saved sucessfully
false there was an error

Definition at line 231 of file ef.php.

References $ef_lang, and ef_log().

Referenced by ef_init().

ef_state_new ( path,
appname,
&$  curpath,
&$  vars,
&$  retcode 
)

Switch to new ef state.

See also:
$ef_state
Returns:
old state (suitable for ef_state_restore())

Definition at line 313 of file ef.php.

References $ef_state, and ef_chdir().

Referenced by ef_run().

ef_state_restore ( state  ) 

Switch to previous ef state.

Parameters:
$state new state
Returns:
previous state (suitable for ef_state_restore())

Definition at line 340 of file ef.php.

References $ef_state.

Referenced by ef_run(), and ef_tpl().

ef_tpl ( state,
css = true 
)

Generate HTML output out of passed data.

Parameters:
$state data generated by ef_run()
$css if not empty, turn on CSS support:
  1. wrap generated HTML in span tag with class="ef-$appname"
  2. if $css[class] is set, add this CSS class to 1. and set $out[efcssclass]
  3. if $css[id] is set, add an id= to this span tag and set $out[efcssid] $css may be just a boolean "true" (default)
Returns:
HTML output as string

Definition at line 841 of file ef.php.

References $ef_span, $ef_state, ef_block(), ef_log(), ef_obstart(), ef_obstop(), and ef_state_restore().

Referenced by ef_req().

t ( what  ) 

Translate sentence using files loaded by ef_include_lang().

Parameters:
$what sentence to translate
Returns:
string: translation of $what
Note:
name of the function is short to make it handy

Definition at line 216 of file ef.php.


Variable Documentation

$ef_cli_mode = (php_sapi_name() == "cli")

are we running in CLI environment?

Definition at line 55 of file ef.php.

$ef_ctl = getcwd() . "/.."

main application root dir

Definition at line 45 of file ef.php.

$ef_default_action = "/index"

default action to run

Definition at line 54 of file ef.php.

$ef_default_lang = "en"

default user language

Definition at line 52 of file ef.php.

Referenced by ef_init().

$ef_dir = "/usr/share/php/ef"

path to ef applications

Definition at line 44 of file ef.php.

$ef_export_helper = array()

Helper for exports in ef_include_extract() #4.

Definition at line 86 of file ef.php.

$ef_hooks = array()

hooks are registered here

Definition at line 50 of file ef.php.

$ef_lang = NULL

current language

Definition at line 53 of file ef.php.

Referenced by ef_include_lang(), ef_init(), and ef_save_lang().

$ef_log_indent_width = 1

log indentation width

Definition at line 49 of file ef.php.

$ef_log_level = 1

maximum log level to log a message

Definition at line 47 of file ef.php.

Referenced by ef_log().

$ef_log_to_stdout = FALSE

to log using "echo" or not

Definition at line 48 of file ef.php.

Referenced by ef_log().

$ef_logs = array()

log messages go here

Definition at line 46 of file ef.php.

Referenced by ef_log().

$ef_reqdefs = array()

default efreq values #5

Definition at line 57 of file ef.php.

$ef_span = "span"

HTML tag to use for CSS integration.

Definition at line 56 of file ef.php.

Referenced by ef_block(), and ef_tpl().

$ef_state

Initial value:

 array(
        "path"     => FALSE,
        "appname"  => "none",
        "curpath"  => "",
        "vars"     => array(),
        "blocks"   => array(),
        "retcode"  => EF_ABRT,
        "cwd"      => getcwd()
)
Global current request state.

Used:

  • for simpler ef_*() in action.php
  • as ef_run() output data format
  • as ef_tpl() input data format

Members:

  • path - path being handled
  • appname - application name (ef_rootname() on path above)
  • curpath - current position in path
  • vars - variable scope
  • blocks - template blocks
  • retcode - last action.php return code
  • cwd - for better cwd (Current Working Dir) tracking

Definition at line 75 of file ef.php.

Referenced by ef_block(), ef_block_include(), ef_block_mv(), ef_block_write(), ef_chdir(), ef_getreq(), ef_log(), ef_state_new(), ef_state_restore(), and ef_tpl().

$ef_trans = array()

contains translations

Definition at line 51 of file ef.php.


Generated on Tue Dec 12 06:53:28 2017 for ef by  doxygen 1.5.5