Pretty errors, fixed controllers, and more.

This commit is contained in:
Buster Silver 2015-01-02 02:59:57 -06:00
parent 7220df0e85
commit c09f1bbbf9
11 changed files with 161 additions and 231 deletions

View File

@ -7,7 +7,8 @@
"phpoffice/phpexcel": "1.8.0",
"james-heinrich/getid3": "v1.9.8",
"electrolinux/phpquery": "0.9.6",
"phalcon/devtools": "dev-master"
"phalcon/devtools": "dev-master",
"filp/whoops": "1.*"
},
"authors": [
{

122
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "a2dcaba671944856f06618be1a717f2d",
"hash": "7f51d53eec75b9dacad7675b59414c2d",
"packages": [
{
"name": "doctrine/annotations",
@ -12,12 +12,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/annotations.git",
"reference": "3b6668f54ad3f95d68b64a742f6b0de55d6caeb1"
"reference": "b5202eb9e83f8db52e0e58867e0a46e63be8332e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/annotations/zipball/3b6668f54ad3f95d68b64a742f6b0de55d6caeb1",
"reference": "3b6668f54ad3f95d68b64a742f6b0de55d6caeb1",
"url": "https://api.github.com/repos/doctrine/annotations/zipball/b5202eb9e83f8db52e0e58867e0a46e63be8332e",
"reference": "b5202eb9e83f8db52e0e58867e0a46e63be8332e",
"shasum": ""
},
"require": {
@ -72,7 +72,7 @@
"docblock",
"parser"
],
"time": "2014-11-04 15:34:10"
"time": "2014-12-23 22:40:37"
},
{
"name": "doctrine/cache",
@ -80,12 +80,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
"reference": "85ff6118558d7b2501cd85b31bdc1ffc0cab731a"
"reference": "803a41469d948bc120a6c913399e8bfc8b5d9650"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/cache/zipball/85ff6118558d7b2501cd85b31bdc1ffc0cab731a",
"reference": "85ff6118558d7b2501cd85b31bdc1ffc0cab731a",
"url": "https://api.github.com/repos/doctrine/cache/zipball/803a41469d948bc120a6c913399e8bfc8b5d9650",
"reference": "803a41469d948bc120a6c913399e8bfc8b5d9650",
"shasum": ""
},
"require": {
@ -142,7 +142,7 @@
"cache",
"caching"
],
"time": "2014-11-27 00:22:12"
"time": "2014-12-08 23:13:26"
},
{
"name": "doctrine/collections",
@ -216,12 +216,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/common.git",
"reference": "559a805125524b0bb6742638784c2979a5c5e607"
"reference": "c819359fc0babd36620e4b48d2eb0c6dacbc48a2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/common/zipball/559a805125524b0bb6742638784c2979a5c5e607",
"reference": "559a805125524b0bb6742638784c2979a5c5e607",
"url": "https://api.github.com/repos/doctrine/common/zipball/c819359fc0babd36620e4b48d2eb0c6dacbc48a2",
"reference": "c819359fc0babd36620e4b48d2eb0c6dacbc48a2",
"shasum": ""
},
"require": {
@ -281,7 +281,7 @@
"persistence",
"spl"
],
"time": "2014-07-27 17:39:50"
"time": "2015-01-01 17:37:36"
},
{
"name": "doctrine/dbal",
@ -289,12 +289,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "40fd004725b4aa902aea170cd15152b06a6faba0"
"reference": "608d2a281b58209b8e2f69e5286c0108e254350e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/40fd004725b4aa902aea170cd15152b06a6faba0",
"reference": "40fd004725b4aa902aea170cd15152b06a6faba0",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/608d2a281b58209b8e2f69e5286c0108e254350e",
"reference": "608d2a281b58209b8e2f69e5286c0108e254350e",
"shasum": ""
},
"require": {
@ -314,7 +314,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5.x-dev"
"dev-master": "2.6.x-dev"
}
},
"autoload": {
@ -352,7 +352,7 @@
"persistence",
"queryobject"
],
"time": "2014-11-24 15:49:52"
"time": "2015-01-01 16:43:32"
},
{
"name": "doctrine/inflector",
@ -360,12 +360,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/inflector.git",
"reference": "8a0b96e65d2399d6f95b75de11134843a2c61feb"
"reference": "e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/inflector/zipball/8a0b96e65d2399d6f95b75de11134843a2c61feb",
"reference": "8a0b96e65d2399d6f95b75de11134843a2c61feb",
"url": "https://api.github.com/repos/doctrine/inflector/zipball/e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d",
"reference": "e5eaf8c7ded0877195b5d2848491e17b1c0a6c4d",
"shasum": ""
},
"require": {
@ -419,7 +419,7 @@
"singularize",
"string"
],
"time": "2014-10-05 18:49:49"
"time": "2015-01-01 18:34:57"
},
{
"name": "doctrine/lexer",
@ -591,6 +591,64 @@
"homepage": "http://code.google.com/p/phpquery/",
"time": "2013-03-21 12:39:33"
},
{
"name": "filp/whoops",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
"reference": "542400d23369c3c9f1ff221858ba4b220bcc4245"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filp/whoops/zipball/542400d23369c3c9f1ff221858ba4b220bcc4245",
"reference": "542400d23369c3c9f1ff221858ba4b220bcc4245",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"mockery/mockery": "0.9.*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
}
},
"autoload": {
"psr-0": {
"Whoops": "src/"
},
"classmap": [
"src/deprecated"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Filipe Dobreira",
"homepage": "https://github.com/filp",
"role": "Developer"
}
],
"description": "php error handling for cool kids",
"homepage": "https://github.com/filp/whoops",
"keywords": [
"error",
"exception",
"handling",
"library",
"silex-provider",
"whoops",
"zf2"
],
"time": "2014-11-29 09:19:11"
},
{
"name": "james-heinrich/getid3",
"version": "v1.9.8",
@ -628,12 +686,12 @@
"source": {
"type": "git",
"url": "https://github.com/phalcon/phalcon-devtools.git",
"reference": "169058d5b12782a771f198f638429975460ec136"
"reference": "070c3c3a51c81944ae241267e271ee9ce8ebf066"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phalcon/phalcon-devtools/zipball/169058d5b12782a771f198f638429975460ec136",
"reference": "169058d5b12782a771f198f638429975460ec136",
"url": "https://api.github.com/repos/phalcon/phalcon-devtools/zipball/070c3c3a51c81944ae241267e271ee9ce8ebf066",
"reference": "070c3c3a51c81944ae241267e271ee9ce8ebf066",
"shasum": ""
},
"require": {
@ -664,7 +722,7 @@
"framework",
"phalcon"
],
"time": "2014-10-14 02:42:17"
"time": "2014-12-11 14:36:33"
},
{
"name": "phpoffice/phpexcel",
@ -730,12 +788,12 @@
"source": {
"type": "git",
"url": "https://github.com/symfony/Console.git",
"reference": "c5e1a11682f97c1330223268b2a8105f3fc3630d"
"reference": "1576b36b25204ae72d4c4577b985181cf3cd0a98"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Console/zipball/c5e1a11682f97c1330223268b2a8105f3fc3630d",
"reference": "c5e1a11682f97c1330223268b2a8105f3fc3630d",
"url": "https://api.github.com/repos/symfony/Console/zipball/1576b36b25204ae72d4c4577b985181cf3cd0a98",
"reference": "1576b36b25204ae72d4c4577b985181cf3cd0a98",
"shasum": ""
},
"require": {
@ -743,8 +801,8 @@
},
"require-dev": {
"psr/log": "~1.0",
"symfony/event-dispatcher": "~2.1",
"symfony/process": "~2.1"
"symfony/event-dispatcher": "~2.1|~3.0.0",
"symfony/process": "~2.1|~3.0.0"
},
"suggest": {
"psr/log": "For using the console logger",
@ -778,7 +836,7 @@
],
"description": "Symfony Console Component",
"homepage": "http://symfony.com",
"time": "2014-11-30 15:28:47"
"time": "2014-12-30 13:34:24"
},
{
"name": "zendframework/zendframework1",

View File

@ -54,6 +54,9 @@ $config->preload(array('application','general'));
// Loop through modules to find configuration files or libraries.
$module_config_dirs = array();
$modules = scandir(DF_INCLUDE_MODULES);
$phalcon_modules = array();
foreach($modules as $module)
{
if ($module == '.' || $module == '..')
@ -62,6 +65,11 @@ foreach($modules as $module)
$config_directory = DF_INCLUDE_MODULES.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'config';
if (file_exists($config_directory))
$module_config[$module] = new \DF\Config($config_directory);
$phalcon_modules[$module] = array(
'className' => 'Modules\\'.ucfirst($module).'\Module',
'path' => DF_INCLUDE_MODULES.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'/Module.php',
);
}
$autoload_classes = $config->application->autoload->toArray();
@ -81,9 +89,16 @@ foreach($autoload_classes['psr4'] as $class_key => $class_dir)
// $em = \Zend_Registry::get('em');
// \DF\Doctrine\Session\SaveHandler::register($em);
// PVL-specific customization.
$system_tz = \PVL\Customization::get('timezone');
@date_default_timezone_set($system_tz);
// Register error-handler.
$run = new \Whoops\Run;
$handler = new \Whoops\Handler\PrettyPageHandler;
$handler->setPageTitle("Whoops! There was a problem.");
$run->pushHandler($handler);
// $run->pushHandler(new \Whoops\Handler\JsonResponseHandler);
$run->register();
$di = new \Phalcon\DI\FactoryDefault();
@ -96,6 +111,9 @@ $di['router'] = function() {
$di['config'] = $config;
$di['module_config'] = $module_config;
// Database
$di->setShared('em', '\DF\Doctrine\Service');
// Auth and ACL
$di->setShared('auth', '\DF\Auth\Model');
$di->setShared('acl', '\DF\Acl\Instance');
@ -114,4 +132,6 @@ $di->set('session', function() {
return $session;
});
return $di;
// PVL-specific customization.
$system_tz = \PVL\Customization::get('timezone');
@date_default_timezone_set($system_tz);

View File

@ -1,6 +1,8 @@
<?php
$router = new \Phalcon\Mvc\Router(true);
$router->add('/admin', array(
'module' => 'backend',
'controller' => 'index',
@ -11,6 +13,7 @@ $router->add('/index', array(
'controller' => 'index',
'action' => 'index'
));
$router->add('/', array(
'module' => 'frontend',
'controller' => 'index',

View File

@ -146,8 +146,8 @@ class Instance implements \Phalcon\DI\InjectionAwareInterface
*/
public function checkPermission($action)
{
$auth = \Zend_Registry::get('auth');
$auth = $this->_di->get('auth');
if (!$this->isAllowed($action))
{
if (!$auth->isLoggedIn())

View File

@ -1,10 +1,10 @@
<?php
namespace DF\Service;
namespace DF\Doctrine;
use \Doctrine\Common\ClassLoader;
use \Doctrine\DBAL\Types\Type;
class Doctrine
class Service
{
public static function init($options)
{
@ -127,21 +127,7 @@ class Doctrine
}
// Try the connection before rendering the page.
try
{
$em->getConnection()->connect();
}
catch(\Exception $e)
{
$db_config_location = str_replace(DF_INCLUDE_ROOT, '', DF_INCLUDE_APP).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'application.conf.php';
\DF\Application\Maintenance::display('
<h2>Database Error</h2>
<p>The system could not connect to the database. Verify that the information listed in "<i>'.$db_config_location.'</i>" is correct.</p>
<blockquote>'.$e->getMessage().'</blockquote>
');
exit;
}
$em->getConnection()->connect();
return $em;
}

View File

@ -32,7 +32,7 @@ class Customization
public static function getCustom($key)
{
// Check for permanent variable if logged in.
$auth = \Zend_Registry::get('auth');
$auth = \Phalcon\DI::getDefault()->get('auth');
if ($auth->isLoggedIn())
{
$user = $auth->getLoggedInUser();
@ -94,7 +94,7 @@ class Customization
static $defaults;
if (!$defaults)
{
$config = \Zend_Registry::get('config');
$config = \Phalcon\DI::getDefault()->get('config');
$defaults = $config->pvl->customization_defaults->toArray();
}
return $defaults;

View File

@ -1,86 +1,43 @@
<?php
namespace Baseapp\Frontend;
namespace Modules\Frontend;
/**
* Frontend Module
*
* @package base-app
* @category Module
* @version 2.0
*/
class Module implements \Phalcon\Mvc\ModuleDefinitionInterface
class Module
{
/**
* Register a specific autoloader for the module
*
* @package base-app
* @version 2.0
*
* @param mixed $di dependency Injector
*
* @return void
*/
public function registerAutoloaders($di = null)
public function registerAutoloaders()
{
$loader = new \Phalcon\Loader();
$loader->registerNamespaces(array(
'Baseapp\Frontend\Controllers' => __DIR__ . '/controllers/',
'Modules\Frontend\Controllers' => __DIR__ . '/controllers/',
));
$loader->register();
}
/**
* Register specific services for the module
*
* @package base-app
* @version 2.0
*
* @param object $di dependency Injector
*
* @return void
*/
public function registerServices($di)
{
//Registering a dispatcher
$di->set('dispatcher', function() {
//Create/Get an EventManager
$eventsManager = new \Phalcon\Events\Manager();
//Attach a listener
$eventsManager->attach("dispatch", function($event, $dispatcher, $exception) {
//controller or action doesn't exist
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'controller' => 'index',
'action' => 'notFound'
));
return false;
}
}
});
$di['dispatcher'] = function() {
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Set default namespace to frontend module
$dispatcher->setDefaultNamespace("Baseapp\Frontend\Controllers");
//Bind the EventsManager to the dispatcher
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setDefaultNamespace("Modules\Frontend\Controllers");
return $dispatcher;
});
};
//Registering the view component
$di->set('view', function() use($di) {
/**
* Setting up the view component
*/
$di['view'] = function() {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir(__DIR__ . '/views/');
$view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di));
$view->setLayoutsDir('../../../templates');
$view->setTemplateAfter('main');
return $view;
});
};
}
}
}

View File

@ -1,113 +1,13 @@
<?php
namespace Baseapp\Frontend\Controllers;
namespace Modules\Frontend\Controllers;
/**
* Frontend Index Controller
*
* @package base-app
* @category Controller
* @version 2.0
*/
class IndexController extends \Phalcon\Mvc\Controller
{
public $siteDesc;
public $scripts = array();
/**
* Before Action
*
* @package base-app
* @version 2.0
*/
public function beforeExecuteRoute($dispatcher)
{
// Set default title and description
$this->tag->setTitle('Default');
$this->siteDesc = 'Default';
// Add css and js to assets collection
$this->assets->addCss('css/fonts.css');
$this->assets->addCss('css/app.css');
$this->assets->addJs('js/plugins.js');
}
/**
* Initialize
*
* @package base-app
* @version 2.0
*/
public function initialize()
{
// Check the session lifetime
if ($this->session->has('last_active') && time() - $this->session->get('last_active') > $this->config->session->options->lifetime) {
$this->session->destroy();
}
$this->session->set('last_active', time());
// Set the language from session
if ($this->session->has('lang')) {
$this->i18n->lang($this->session->get('lang'));
// Set the language from cookie
} elseif ($this->cookies->has('lang')) {
$this->i18n->lang($this->cookies->get('lang')->getValue());
}
// Send langs to the view
$this->view->setVars(array(
// Translate langs before
'siteLangs' => array_map('__', $this->config->i18n->langs->toArray())
));
}
/**
* Index Action
*
* @package base-app
* @version 2.0
*/
public function indexAction()
{
$this->tag->setTitle(__('Home'));
$this->siteDesc = __('Home');
}
/**
* After Action
*
* @package base-app
* @version 2.0
*/
public function afterExecuteRoute($dispatcher)
{
// Set final title and description
$this->tag->setTitleSeparator(' | ');
$this->tag->appendTitle($this->config->app->name);
$this->view->setVar('siteDesc', mb_substr($this->filter->sanitize($this->siteDesc, 'string'), 0, 200, 'utf-8'));
// Set scripts
$this->view->setVar('scripts', $this->scripts);
// Minify css and js collection
\Baseapp\Library\Tool::assetsMinification();
}
/**
* Not found Action
*
* @package base-app
* @version 2.0
*/
public function notFoundAction()
{
// Send a HTTP 404 response header
$this->response->setStatusCode(404, "Not Found");
$this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
$this->view->setMainView('404');
$this->assets->addCss('css/fonts.css');
}
}

View File

@ -4,15 +4,9 @@ use Phalcon\Mvc\Application;
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
require(__DIR__ . '/../app/bootstrap.php');
$di = require(__DIR__ . '/../app/bootstrap.php');
$application = new Application($di);
$application = new Application($di);
$application->registerModules($phalcon_modules);
echo $application->handle()->getContent();
} catch (Exception $e) {
echo $e->getMessage();
}
echo $application->handle()->getContent();

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Common Layout</title>
</head>
<body>
<div style="background: coral">
<?php echo $this->getContent(); ?>
</div>
</body>
</html>