Esempio n. 1
0
 /**
  * Tests {@link Breeze\Application::register()} to register a plugin which registers a helper.
  *
  */
 public function testRegisterPluginWithHelper()
 {
     $closure = function () {
     };
     $this->_mocks['helpers_object']->expects($this->once())->method('add')->with($this->equalTo('name'), $this->equalTo($closure), 'label');
     Application::register('test_plugin', function ($app) use($closure) {
         $app->helper('name', $closure);
     });
     $this->_mockApplication();
     Application::unregister('test_plugin');
 }
Esempio n. 2
0
 /**
  * Sets up the {@link Breeze\Errors\Errors::$_default_error} instance variable
  * for handling errors with no defined handler.
  *
  * @access public
  * @param  Breeze\Application $application  an instance of the base Breeze Framework class for passing into closures.
  * @return void
  */
 public function __construct(Application $application)
 {
     $this->_application = $application;
     $this->_default_error = function (Application $application, \Exception $exception) use($application) {
         $body = sprintf("<h1>%s</h1>", $exception->getMessage());
         if ($application->config('errors_backtrace')) {
             $body .= sprintf('<pre><code>%s</code></pre>', $exception->getTraceAsString());
         }
         if ($application->layoutExists()) {
             echo $application->fetchLayout($body);
         } else {
             echo "<!DOCTYPE html><html><head><title>An error occurred</title></head><body>{$body}</body></html>";
         }
     };
 }
Esempio n. 3
0
 /**
  * Using the current application configurations, retrieves an instance of the specified
  * template engine.
  *
  * @access public
  * @return Breeze\View\Driver\DriverInterface  The template engine.
  * @throws UnexpectedValueException
  */
 public function getEngine()
 {
     $engine_class = __NAMESPACE__ . '\\Driver\\' . $this->_application->config('template_engine');
     if (strtolower(get_class((object) $this->_engine)) != strtolower($engine_class)) {
         if (class_exists($engine_class) && in_array(__NAMESPACE__ . '\\Driver\\DriverInterface', class_implements($engine_class))) {
             $this->_engine = new $engine_class($this->_application, $this->_application->config('template_directory'), $this->_application->config('template_options'));
         } else {
             throw new \UnexpectedValueException(sprintf(self::INVALID_TEMPLATE_ENGINE_ERROR, $engine_class));
         }
     } else {
         $this->_engine->config();
     }
     return $this->_engine;
 }
Esempio n. 4
0
    /**
     * Sets up the internal template engine structures.  This is intended
     * to be where engine specific options are set up.
     *
     * @access protected
     * @return void
     */
    protected function _config()
    {
        $path = $this->getPath();
        $this->_dwoo->setCompileDir($path . '/' . $this->getOption('compile_dir', self::DEFAULT_COMPILE_DIR));
        $this->_dwoo->setCacheDir($path . '/' . $this->getOption('cache_dir', self::DEFAULT_CACHE_DIR));
    }
    /**
     * Renders a template using the $variables parameter and returns
     * the contents.
     *
     * @access protected
     * @param  string $template  The path to the template, excluding the base templates directory.
     * @param  array $variables  An associative array of variables to use in the template.
     * @return string  The rendered template.
     */
    protected function _fetch($template, array $variables = null)
    {
        return $this->_dwoo->get($this->getTemplatePath($template), $variables);
    }
}
Application::register('Dwoo', function ($app) {
    // Sets up some default Dwoo configurations
    $app->config(array('template_engine' => 'Dwoo', 'template_extension' => '.tpl', 'template_options' => array('compile_dir' => Dwoo::DEFAULT_COMPILE_DIR, 'cache_dir' => Dwoo::DEFAULT_CACHE_DIR)));
});
Esempio n. 5
0
 * @see Breeze\Application
 */
use Breeze\Application;
define('BREEZE_APPLICATION', realpath(dirname(__FILE__)));
// The admin form messages
const POST_ERROR_MESSAGE = 'Oh no, something went wrong:';
const POST_CREATED_MESSAGE = 'Your post was successfully created.';
const POST_UPDATED_MESSAGE = 'Your post was successfully updated.';
const POST_DELETED_MESSAGE = 'Your post was successfully deleted.';
// Uncomment to use an alternate template engine
// require_once 'Breeze/plugins/breeze.dwoo.php';
// require_once 'Breeze/plugins/breeze.smarty.php';
// Setup the breeze framework components
require_once 'Breeze/plugins/breeze.flashhash.php';
require_once 'Breeze/Application.php';
$breeze = new Application();
require_once 'helpers.php';
// Configure the breeze framework
$breeze->config('template_directory', BREEZE_APPLICATION . '/views/' . strtolower($breeze->config('template_engine')));
$breeze->config('errors_backtrace', false);
$breeze->error('404', function ($breeze) {
    $breeze->display('errors/404');
});
$breeze->error(function ($breeze) {
    $breeze->display('errors/500');
});
// Setup the Doctrine model components
require_once 'Doctrine/lib/Doctrine.php';
\spl_autoload_register(array('Doctrine', 'autoload'));
\spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
$manager = \Doctrine_Manager::getInstance();
Esempio n. 6
0
Application::register('flashhash', function ($app) {
    // Make the flashhash available to templates
    $app->flash = new Base();
    /**
     *  <code>
     *      get('/', function(){
     *          flash('name', 'This is a value');
     *          redirect('/getflash');
     *      });
     *
     *      get('/getflash', function(){
     *          echo flash('name'); // This is a value
     *          display('getflash');
     *      });
     *
     *      // getflash.php
     *      <p id="flash"><?php echo $flash['name']; ?></p>
     *  </code>
     */
    $app->helper('flash', function ($name, $value = null) use($app) {
        $num_args = func_num_args();
        if ($num_args == 1) {
            return $app->flash[$name];
        } else {
            $_SESSION['flashhash'][$name] = $value;
        }
    });
    /**
     *  <code>
     *      get('/', function(){
     *          flashnow('name', 'This is a value');
     *          echo flash('name'); // This is a value
     *          display('getflash');
     *      });
     *
     *      // getflash.php
     *      <p id="flash"><?php echo $flash['name']; ?></p>
     *  </code>
     */
    $app->helper('flashnow', function ($name, $value = null) use($app) {
        $app->flash[$name] = $value;
    });
});