First release of domframework
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1207 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
86
renderer.php
Normal file
86
renderer.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
class renderer
|
||||
{
|
||||
public $result = NULL;
|
||||
public $output = NULL;
|
||||
public $title = " "; // Title by default : space to be compatible with HTML5
|
||||
/** Filename of class containing the presentation layer */
|
||||
public $viewClass = FALSE;
|
||||
/** Method apply to class object to display the $result */
|
||||
public $viewMethod = FALSE;
|
||||
/** Filename in views containing the HTML layout. Without .html at the end */
|
||||
public $layout = FALSE;
|
||||
|
||||
/** Display the $this->result result in the output model defined by
|
||||
$this->output */
|
||||
public function run ()
|
||||
{
|
||||
if (!@require_once ("output$this->output.php"))
|
||||
throw new Exception ("Renderer '$this->output' not found", 500);
|
||||
$class = "output$this->output";
|
||||
$reflection = new ReflectionMethod ($class, "out");
|
||||
$res = $reflection->invokeArgs (new $class,
|
||||
array ($this->result, $this->title,
|
||||
$this->viewClass, $this->viewMethod, $this->layout));
|
||||
echo $res;
|
||||
}
|
||||
|
||||
/** Add a flash message to the user, on the next HTML page.
|
||||
In CLI, display the message immediately.
|
||||
Message must be translated before sending to the function
|
||||
Priority is 1:success, 2:info, 3:warning, 4:error
|
||||
or textual : SUCCESS, INFO, WARNING, ERROR */
|
||||
static public function flash ($priority, $message)
|
||||
{
|
||||
if (php_sapi_name () === "cli")
|
||||
{
|
||||
switch ($priority)
|
||||
{
|
||||
case 1:
|
||||
case "SUCCESS":
|
||||
echo "SUCCESS: $message\n";
|
||||
break;
|
||||
case 2:
|
||||
case "INFO":
|
||||
echo "INFO: $message\n";
|
||||
break;
|
||||
case 3:
|
||||
case "WARNING":
|
||||
echo "WARNING: $message\n";
|
||||
break;
|
||||
case 4:
|
||||
case "ERROR":
|
||||
echo "ERROR: $message\n";
|
||||
break;
|
||||
default:
|
||||
throw new Exception ("Unknown flash priority '$priority'", 500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! isset ($_SESSION))
|
||||
throw new Exception ("No session available to store flash", 500);
|
||||
switch ($priority)
|
||||
{
|
||||
case 1:
|
||||
case "SUCCESS":
|
||||
$_SESSION["renderer"]["flash"][] = array (1, $message);
|
||||
break;
|
||||
case 2:
|
||||
case "INFO":
|
||||
$_SESSION["renderer"]["flash"][] = array (2, $message);
|
||||
break;
|
||||
case 3:
|
||||
case "WARNING":
|
||||
$_SESSION["renderer"]["flash"][] = array (3, $message);
|
||||
break;
|
||||
case 4:
|
||||
case "ERROR":
|
||||
$_SESSION["renderer"]["flash"][] = array (4, $message);
|
||||
break;
|
||||
default:
|
||||
throw new Exception ("Unknown flash priority '$priority'", 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user