Esempio n. 1
0
 public function __construct()
 {
     // 创建swoole_http_server对象
     $http = new swoole_http_server("0.0.0.0", 9501);
     // 设置参数
     $http->set(array('worker_num' => 16, 'daemonize' => false, 'max_request' => 10000, 'dispatch_mode' => 1));
     $http->setGlobal(HTTP_GLOBAL_ALL);
     // 绑定WorkerStart
     $http->on('WorkerStart', array($this, 'onWorkerStart'));
     // 绑定request
     $http->on('request', function ($request, $response) {
         ob_start();
         try {
             //注入uri
             $_GET['_url'] = $request->server['request_uri'];
             $application = new \Phalcon\Mvc\Application($this->di);
             echo $application->handle()->getContent();
         } catch (Exception $e) {
             echo $e->getMessage();
         }
         $result = ob_get_contents();
         ob_end_clean();
         $response->end($result);
     });
     $http->start();
 }
Esempio n. 2
0
 public function run()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     // Config
     require_once APPLICATION_PATH . '/modules/Cms/Config.php';
     $config = \Cms\Config::get();
     $di->set('config', $config);
     // Registry
     $registry = new \Phalcon\Registry();
     $di->set('registry', $registry);
     // Loader
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->registerDirs([APPLICATION_PATH . "/plugins/"]);
     $loader->register();
     require_once APPLICATION_PATH . '/../vendor/autoload.php';
     // Database
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(["host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset]);
     $di->set('db', $db);
     // View
     $this->initView($di);
     // URL
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath($config->base_path);
     $url->setBaseUri($config->base_path);
     $di->set('url', $url);
     // Cache
     $this->initCache($di);
     // CMS
     $cmsModel = new \Cms\Model\Configuration();
     $registry->cms = $cmsModel->getConfig();
     // Отправляем в Registry
     // Application
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     // Events Manager, Dispatcher
     $this->initEventManager($di);
     // Session
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $di->set('acl', $acl);
     // JS Assets
     $this->initAssetsManager($di);
     // Flash helper
     $flash = new \Phalcon\Flash\Session(['error' => 'ui red inverted segment', 'success' => 'ui green inverted segment', 'notice' => 'ui blue inverted segment', 'warning' => 'ui orange inverted segment']);
     $di->set('flash', $flash);
     $di->set('helper', new \Application\Mvc\Helper());
     // Routing
     $this->initRouting($application, $di);
     $application->setDI($di);
     // Main dispatching process
     $this->dispatch($di);
 }
Esempio n. 3
0
 public static function run()
 {
     global $di;
     $di = new \Phalcon\DI\FactoryDefault();
     self::initSystemConst();
     self::initSystemService();
     self::initAutoloaders();
     $application = new \Phalcon\Mvc\Application($di);
     //Register the installed modules
     $application->registerModules(array('home' => array('className' => 'Application\\Home\\Module', 'path' => '../application/modules/home/module.php'), 'admin' => array('className' => 'Application\\Admin\\Module', 'path' => '../application/modules/admin/module.php'), 'api' => array('className' => 'Application\\Api\\Module', 'path' => '../application/modules/Api/module.php')));
     echo $application->handle()->getContent();
 }
Esempio n. 4
0
 public function handle($uri = null)
 {
     /** @var Response $response */
     $response = parent::handle($uri);
     if ($response->getContent()) {
         return $response;
     }
     switch ($response->getStatusCode()) {
         case Response::HTTP_NOT_FOUND:
         case Response::HTTP_METHOD_NOT_ALLOWED:
         case Response::HTTP_UNAUTHORIZED:
         case Response::HTTP_FORBIDDEN:
         case Response::HTTP_INTERNAL_SERVER_ERROR:
             if ($this->request->isAjax() || $response instanceof JsonResponse) {
                 $response->setContent(array('error' => $response->getStatusMessage()));
             } else {
                 $template = new Template($this->view, 'error');
                 $template->set('code', $response->getStatusCode());
                 $template->set('message', $response->getStatusMessage());
                 $response->setContent($template->render());
             }
             break;
         default:
             break;
     }
     return $response;
 }
Esempio n. 5
0
 public function testApplicationModulesDefinitionClosure()
 {
     // Creates the autoloader
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Frontend\\Controllers' => __DIR__ . '/modules/frontend/controllers/', 'Backend\\Controllers' => __DIR__ . '/modules/backend/controllers/'));
     $loader->register();
     $_GET['_url'] = '/login';
     Phalcon\DI::reset();
     $di = new Phalcon\DI\FactoryDefault();
     $di->set('router', function () {
         $router = new Phalcon\Mvc\Router(false);
         $router->add('/index', array('controller' => 'index', 'module' => 'frontend', 'namespace' => 'Frontend\\Controllers\\'));
         $router->add('/login', array('controller' => 'login', 'module' => 'backend', 'namespace' => 'Backend\\Controllers\\'));
         return $router;
     });
     $application = new Phalcon\Mvc\Application();
     $view = new \Phalcon\Mvc\View();
     $application->registerModules(array('frontend' => function ($di) use($view) {
         $di->set('view', function () use($view) {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir(__DIR__ . '/modules/frontend/views/');
             return $view;
         });
     }, 'backend' => function ($di) use($view) {
         $di->set('view', function () use($view) {
             $view->setViewsDir(__DIR__ . '/modules/backend/views/');
             return $view;
         });
     }));
     $application->setDi($di);
     $this->assertEquals($application->handle()->getContent(), '<html>here</html>' . PHP_EOL);
     $loader->unregister();
 }
Esempio n. 6
0
function run_cgi_application()
{
    $di = get_app_di();
    $application = new \Phalcon\Mvc\Application($di);
    echo $application->handle()->getContent();
}
<?php

try {
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    define('PUBLIC_PATH', realpath(dirname(__FILE__)));
    /**
     * Read the configuration
     */
    $config = (include __DIR__ . "/../app/config/config.php");
    /**
     * Read auto-loader
     */
    include __DIR__ . "/../app/config/loader.php";
    //include __DIR__ . "/../vendor/autoload.php";
    require_once __DIR__ . "/../app/config/define.php";
    /**
     * Read services
     */
    include __DIR__ . "/../app/config/services.php";
    include __DIR__ . "/../app/config/debug.php";
    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application($di);
    $application->registerModules(array('frontend' => array('className' => 'Multiple\\Frontend\\Module', 'path' => '../app/frontend/Module.php'), 'methodist' => array('className' => 'Multiple\\Methodist\\Module', 'path' => '../app/methodist/Module.php'), 'student' => array('className' => 'Multiple\\Student\\Module', 'path' => '../app/student/Module.php'), 'crud' => array('className' => 'Multiple\\Crud\\Module', 'path' => '../app/crud/Module.php'), 'rest' => array('className' => 'Multiple\\Rest\\Module', 'path' => '../app/rest/Module.php')));
    echo $application->handle()->getContent();
} catch (\Exception $e) {
    echo $e->getMessage();
}
Esempio n. 8
0
 /**
  * Execute Phalcon Developer Tools
  *
  * @param  string             $path The path to the Phalcon Developer Tools
  * @param  string             $ip   Optional IP address for securing Developer Tools
  * @return void
  * @throws \Exception         if Phalcon extension is not installed
  * @throws \Exception         if Phalcon version is not compatible Developer Tools
  * @throws \Phalcon\Exception if Application config could not be loaded
  */
 public static function main($path, $ip = null)
 {
     if (!extension_loaded('phalcon')) {
         throw new \Exception('Phalcon extension is not installed, follow these instructions to install it: http://phalconphp.com/documentation/install');
     }
     if ($ip !== null) {
         self::$ip = $ip;
     }
     if (!defined('TEMPLATE_PATH')) {
         define('TEMPLATE_PATH', $path . '/templates');
     }
     chdir('..');
     // Read configuration
     $configPaths = array('config', 'app/config', 'apps/frontend/config');
     $readed = false;
     foreach ($configPaths as $configPath) {
         $cpath = $configPath . '/config.ini';
         if (file_exists($cpath)) {
             $config = new \Phalcon\Config\Adapter\Ini($cpath);
             $readed = true;
             break;
         } else {
             $cpath = $configPath . '/config.php';
             if (file_exists($cpath)) {
                 $config = (require $cpath);
                 $readed = true;
                 break;
             }
         }
     }
     if ($readed === false) {
         throw new \Phalcon\Exception('Configuration file could not be loaded!');
     }
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array($path . '/scripts/', $path . '/scripts/Phalcon/Web/Tools/controllers/'));
     $loader->registerNamespaces(array('Phalcon' => $path . '/scripts/'));
     $loader->register();
     if (Version::getId() < Script::COMPATIBLE_VERSION) {
         throw new \Exception('Your Phalcon version is not compatible with Developer Tools, download the latest at: http://phalconphp.com/download');
     }
     try {
         $di = new FactoryDefault();
         $di->set('view', function () use($path) {
             $view = new View();
             $view->setViewsDir($path . '/scripts/Phalcon/Web/Tools/views/');
             return $view;
         });
         $di->set('config', $config);
         $di->set('url', function () use($config) {
             $url = new \Phalcon\Mvc\Url();
             $url->setBaseUri($config->application->baseUri);
             return $url;
         });
         $di->set('flash', function () {
             return new \Phalcon\Flash\Direct(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
         });
         $di->set('db', function () use($config) {
             if (isset($config->database->adapter)) {
                 $adapter = $config->database->adapter;
             } else {
                 $adapter = 'Mysql';
             }
             if (is_object($config->database)) {
                 $configArray = $config->database->toArray();
             } else {
                 $configArray = $config->database;
             }
             $className = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
             unset($configArray['adapter']);
             return new $className($configArray);
         });
         self::$di = $di;
         $app = new \Phalcon\Mvc\Application();
         $app->setDi($di);
         echo $app->handle()->getContent();
     } catch (\Phalcon\Exception $e) {
         echo get_class($e), ': ', $e->getMessage(), "<br>";
         echo nl2br($e->getTraceAsString());
     } catch (\PDOException $e) {
         echo get_class($e), ': ', $e->getMessage(), "<br>";
         echo nl2br($e->getTraceAsString());
     }
 }
Esempio n. 9
0
    /**
     * The URL component is used to generate all kind of urls in the application
     */
    $di->set('url', function () {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/mvc/multiple-shared-layouts/');
        return $url;
    });
    /**
     * Start the session the first time some component request the session service
     */
    $di->set('session', function () {
        $session = new \Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });
    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application();
    $application->setDI($di);
    /**
     * Register application modules
     */
    $application->registerModules(array('frontend' => array('className' => 'Modules\\Frontend\\Module', 'path' => '../apps/frontend/Module.php'), 'backend' => array('className' => 'Modules\\Backend\\Module', 'path' => '../apps/backend/Module.php')));
    echo $application->handle()->getContent();
} catch (Phalcon\Exception $e) {
    echo $e->getMessage();
} catch (PDOException $e) {
    echo $e->getMessage();
}
Esempio n. 10
0
<?php

error_reporting(E_ALL);
define('APP_PATH', dirname(__DIR__));
$loader = (require APP_PATH . '/vendor/autoload.php');
$config = (require APP_PATH . "/config/config.php");
$di = (require APP_PATH . "/config/services.php");
try {
    $app = new \Phalcon\Mvc\Application($di);
    $app->setEventsManager($di['eventsManager']);
    $app->useImplicitView(false);
    echo $app->handle()->getContent();
} catch (\Exception $e) {
    $di['logger']->error($e->getMessage() . "\n" . $e->getTraceAsString());
    $di['response']->setStatusCode(500)->setContent("Internal error")->send();
}
Esempio n. 11
0
        foreach ($routers as $name => $rule) {
            $pattern = $rule->pattern;
            unset($rule->pattern);
            $router->add($pattern, $rule->toArray())->setName($name);
        }
    }
    return $router;
});
$di->setShared('db', function () use($config) {
    $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, "charset" => $config->database->charset, "collation" => $config->database->collation));
    return $connection;
});
$di->set('modelsManager', new \Phalcon\Mvc\Model\Manager());
$di->setShared('url', function () use($config) {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($config->app->base);
    return $url;
});
try {
    $application = new Phalcon\Mvc\Application();
    $application->setDI($di);
    if (!empty($config->apps)) {
        foreach ($config->apps as $name => $app) {
            $apps[$name] = array('className' => $app . '\\Module', 'path' => '../' . $config->app->apps . $name . DIRECTORY_SEPARATOR . 'Module.php');
        }
    }
    $application->registerModules($apps);
    echo $application->handle()->getContent();
} catch (Exception $e) {
    echo $e->getMessage();
}
Esempio n. 12
0
<?php

$loader = (require __DIR__ . '/../app/autoload.php');
$kernel = new AppKernel('dev');
$kernel->boot();
$kernel->registerRoutes();
$app = new \Phalcon\Mvc\Application($kernel->getDI());
/**
 * Handle the request
 */
$response = $app->handle();
$response->send();
Esempio n. 13
0
 /**
  * Read the configuration
  */
 $config = (include __DIR__ . "/../app/config/config.php");
 /**
  * Read auto-loader
  */
 include $config->application->appDir . "config/loader.php";
 /**
  * Read services
  */
 include $config->application->appDir . "config/services.php";
 /**
  * Handle the request
  */
 $application = new \Phalcon\Mvc\Application($di);
 // print_r($config->modules->toArray());exit();
 $application->registerModules($config->modules->toArray());
 if (substr($di['request']->getUserAgent(), 0, 11) === 'PHP Yar Rpc') {
     $service = new Yar_Server(new \App\Bootstrap\Service($application));
     $service->handle();
 } else {
     if ($di['request']->getQuery('_method') == 'yar') {
         list($tmp, $module, $controller, $action) = explode('/', $di['request']->getURI());
         $className = "App\\Modules\\" . ucfirst($module) . "\\Controllers\\" . ucfirst($controller) . "Controller";
         include "../app/modules/user/controllers/IndexController.php";
         // $obj = "App\Modules\User\Controllers\IndexController()";
         $service = new Yar_Server();
         $service->handle();
     } else {
         $application->getDI()->set('params', function () use($di) {
Esempio n. 14
0
            $compiler->addFilter('truncate', function ($resolvedArgs, $exprArgs) {
                $string = $exprArgs[0]['expr']['value'];
                $length = (int) $exprArgs[1]['expr']['value'];
                $end = isset($exprArgs[2]) ? $exprArgs[2]['expr']['value'] : '...';
                return "mb_strimwidth({$string}, 0, {$length}, '{$end}', 'UTF-8')";
            });
            $compiler->addFilter('shift', function ($resolvedArgs, $exprArgs) {
                return "array_shift({$resolvedArgs})";
            });
            $compiler->addFilter('number_format', function ($resolvedArgs, $exprArgs) {
                return "number_format({$resolvedArgs})";
            });
            return $volt;
        }));
        // $view->setVar('FACEBOOK_ADMIN_ID', $config->facebook[ENVIRONMENT]->admin);
        // $view->setVar('GOOGLE_ANALYTICS_KEY', $config->ga[ENVIRONMENT]->key);
        return $view;
    }, true);
    $eventsManager = new \Phalcon\Events\Manager();
    $eventsManager->attach("application:afterHandleRequest", function ($event, $application) {
        $datetime = gmdate("D, d M Y H:i:s") . ' GMT';
        $application->response->setHeader('Last-Modified', $datetime);
        return true;
    });
    $application = new \Phalcon\Mvc\Application($di);
    $application->setEventsManager($eventsManager);
    $application->registerModules(array(SITENAME => array('className' => 'Lininliao\\' . SITENAME . '\\Module', 'path' => ROOT . DS . 'apps' . DS . SITENAME . DS . 'Module.php')));
    echo $application->handle()->getContent();
} catch (\Exception $e) {
    echo $e->getMessage();
}
Esempio n. 15
0
 public static function run()
 {
     if (in_array(APPLICATION_ENV, array('development'))) {
         $debug = new \Phalcon\Debug();
         $debug->listen();
     }
     $di = new \Phalcon\DI\FactoryDefault();
     $config = (include APPLICATION_PATH . '/config/application.php');
     $di->set('config', $config);
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->register();
     $loader->registerDirs(array(APPLICATION_PATH . "/plugins/"));
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset));
     $di->set('db', $db);
     $view = new View();
     /* $view->disableLevel(array(
        View::LEVEL_BEFORE_TEMPLATE => true,
        View::LEVEL_LAYOUT          => true,
        View::LEVEL_AFTER_TEMPLATE  => true
        )); */
     define('MAIN_VIEW_PATH', '../../../views/');
     $view->setMainView(MAIN_VIEW_PATH . 'main');
     $view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
     $view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
     $volt = new \Application\Mvc\View\Engine\Volt($view, $di);
     $volt->setOptions(array('compiledPath' => APPLICATION_PATH . '/cache/volt/'));
     $volt->initCompiler();
     $viewEngines = array(".volt" => $volt);
     $view->registerEngines($viewEngines);
     $di->set('view', $view);
     $viewSimple = new \Phalcon\Mvc\View\Simple();
     $viewSimple->registerEngines($viewEngines);
     $di->set('viewSimple', $viewSimple);
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath('/');
     $url->setBaseUri('/');
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     $router = new \Application\Mvc\Router\DefaultRouter();
     foreach ($application->getModules() as $module) {
         $className = str_replace('Module', 'Routes', $module['className']);
         if (class_exists($className)) {
             $class = new $className();
             $router = $class->init($router);
         }
     }
     $di->set('router', $router);
     $eventsManager = new \Phalcon\Events\Manager();
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
         new ExceptionPlugin($dispatcher, $exception);
     });
     $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) {
         new LocalizationPlugin($dispatcher);
     });
     $eventsManager->attach("acl", function ($event, $acl) {
         if ($event->getType() == 'beforeCheckAccess') {
             echo $acl->getActiveRole(), $acl->getActiveResource(), $acl->getActiveAccess();
         }
     });
     $dispatcher->setEventsManager($eventsManager);
     $di->set('dispatcher', $dispatcher);
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $acl->setEventsManager($eventsManager);
     $di->set('acl', $acl);
     $assets = new \Phalcon\Assets\Manager();
     $di->set('assets', $assets);
     $flash = new \Phalcon\Flash\Session(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
     $di->set('flash', $flash);
     $di->set('helper', new \Application\Mvc\Helper());
     $application->setDI($di);
     echo $application->handle()->getContent();
 }
Esempio n. 16
0
<?php

iconv_set_encoding('internal_encoding', 'UTF-8');
setlocale(LC_ALL, 'ru_RU.UTF-8');
define('PUBLICROOT', __DIR__);
define('COREROOT', dirname(__DIR__));
(new \Phalcon\Debug())->listen(true, true);
/**
 * Read the configuration
 */
$config = (include __DIR__ . "/../app/config/config.php");
/**
 * Read auto-loader
 */
include __DIR__ . "/../app/config/loader.php";
/**
 * Read services
 */
include __DIR__ . "/../app/config/services.php";
/**
 * Handle the request
 */
$application = new \Phalcon\Mvc\Application($di);
$application->registerModules(require __DIR__ . '/../app/config/modules.php');
echo $application->handle()->getContent();
Esempio n. 17
0
<?php

$di = new \Phalcon\DI\FactoryDefault();
$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router();
    $router->setDefaultModule('shop');
    $router->add('/:module/:controller/:action/:params', array('module' => 1, 'controller' => 2, 'action' => 3, 'params' => 4));
    return $router;
});
try {
    $application = new \Phalcon\Mvc\Application($di);
    $application->registerModules(array('shop' => array('className' => 'Bishop\\Shop\\Module', 'path' => ROOT_DIR . '/app/shop/Module.php'), 'backend' => array('className' => 'Bishop\\Admin\\Module', 'path' => ROOT_DIR . '/app/admin/Module.php')));
    echo $application->handle()->getContent();
} catch (\Exception $e) {
    echo $e->getMessage();
}
Esempio n. 18
0
    session_set_cookie_params(0, '/', Config::instance()->cookie_domain);
    /** @var Phalcon\Session\AdapterInterface $session */
    $session = new $class(['path' => Config::instance()->session->save_path, 'lifetime' => Config::instance()->session->lifetime]);
    $session->start();
    return $session;
}, true);
$di->set('view', function () {
    return new TestView();
}, true);
$di->set('dispatcher', function () use($di) {
    return new Phalcon\Mvc\Dispatcher();
}, true);
$di->set('url', function () use($di) {
    $url = new Phalcon\Mvc\Url();
    //$url->setBaseUri($di['config']->base_uri);
    return $url;
}, true);
$di->set('response', new Phalcon\Http\Response());
$requestUri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
if (false !== ($pos = strpos($requestUri, '?'))) {
    $requestUri = substr($requestUri, 0, $pos);
}
$requestUri = rtrim($requestUri, '/');
if (strlen($requestUri) == 0 || $requestUri[0] != '/') {
    $requestUri = '/';
}
$app = new Phalcon\Mvc\Application($di);
$di->set('request_uri', function () use($requestUri) {
    return urldecode($requestUri);
});
echo $app->handle($di['request_uri'])->getContent();
Esempio n. 19
0
error_reporting(E_ALL);
$debug = new \Phalcon\Debug();
$debug->listen();
try {
    /**
     * Read the configuration
     */
    $config = (include __DIR__ . "/../app/config/config.php");
    /**
     * Read auto-loader
     */
    include __DIR__ . "/../app/config/loader.php";
    /**
     * Read services
     */
    include __DIR__ . "/../app/config/services.php";
    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application($di);
    $application->useImplicitView(false);
    echo $application->handle()->getContent();
} catch (Exception $e) {
    $debug = new \Phalcon\Debug();
    $debug->listen();
    echo "PhalconException:" . $e->getMessage() . '<br/>';
    echo "File: " . $e->getFile() . '<br/>';
    echo "Line: " . $e->getLine() . '<br/>';
    print_r(get_class_methods($e));
    print_r($config);
}
Esempio n. 20
0
<?php

/**
 * Handle the request
 */
$application = new \Phalcon\Mvc\Application();
$application->setDI($di);
Esempio n. 21
0
        $url->setBaseUri('/');
        return $url;
    });
    /** Start the session the first time some component request the session service */
    $di->set('session', function () {
        $session = new \Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });
    $di->set('cookies', function () {
        $cookies = new \Phalcon\Http\Response\Cookies();
        $cookies->useEncryption(false);
        return $cookies;
    });
    /** Handle the request */
    $application = new \Phalcon\Mvc\Application();
    $application->setDI($di);
    /** Register application modules */
    $application->registerModules(array('users' => array('className' => 'Modules\\Users\\Module', 'path' => '../apps/users/Module.php'), 'admin' => array('className' => 'Modules\\Admin\\Module', 'path' => '../apps/admin/Module.php')));
    function sanitize_output($buffer)
    {
        $search = array('/\\>[^\\S ]+/s', '/[^\\S ]+\\</s', '/(\\s)+/s');
        $replace = array('>', '<', '\\1');
        $buffer = preg_replace($search, $replace, $buffer);
        return $buffer;
    }
    ob_start("sanitize_output");
    echo $application->handle()->getContent();
} catch (Phalcon\Exception $e) {
    echo $e->getMessage();
} catch (PDOException $e) {
Esempio n. 22
0
        $router->add('/{controller:((?!admin).*)}', array('module' => 'backend', 'controller' => 'index', 'action' => 'index'));
        $router->add("/{controller:((?!admin).*)}/:action", array('module' => 'frontend', 'controller' => 1, 'action' => 2));
        $router->add("/{controller:((?!admin).*)}/:action/:int", array('module' => 'frontend', "controller" => 1, "action" => 2, "id" => 3));
        //       $router->notFound(array(
        //     "controller" => "index",
        //     "action" => "route404"
        // ));
        return $router;
    });
    // set the dispatcher for security reasons
    // $di->set('dispatcher', function() use ($di) {
    // $eventsManager = $di->getShared('eventsManager');
    // $security = new Security($di);
    // $eventsManager->attach('dispatch', $security);
    // $dispatcher = new Phalcon\Mvc\Dispatcher();
    // $dispatcher->setEventsManager($eventsManager);
    // return $dispatcher;
    // });
    //Register an user component
    // $di->set('elements', function(){
    // 	return new Elements();
    // });
    //Handle the request
    $application = new \Phalcon\Mvc\Application($di);
    // Register the installed modules
    $application->registerModules(array('frontend' => array('className' => 'Bbc\\Frontend\\Module', 'path' => '../apps/frontend/Module.php'), 'backend' => array('className' => 'Bbc\\Backend\\Module', 'path' => '../apps/backend/Module.php'), 'shared' => array('className' => 'Bbc\\Shared\\Module', 'path' => '../apps/shared/Module.php')));
    \Phalcon\Mvc\Model::setup(array('notNullValidations' => false));
    echo $application->handle()->getContent();
} catch (\Phalcon\Exception $e) {
    echo "<pre>PhalconException: ", $e->getMessage(), '</pre>';
}
Esempio n. 23
0
        $cookies->useEncryption(false);
        return $cookies;
    });
    /**
     * If the configuration specify the use of metadata adapter use it or use memory otherwise
     */
    $di->set('modelsMetadata', function () use($config) {
        if (isset($config->models->metadata)) {
            $metadataAdapter = 'Phalcon\\Mvc\\Model\\Metadata\\' . $config->models->metadata->adapter;
            return new $metadataAdapter();
        } else {
            return new \Phalcon\Mvc\Model\Metadata\Memory();
        }
    });
    /**
     * setting model caching service
     */
    $di->set('modelsCache', function () use($config) {
        //frontend   a day
        $frontCache = new \Phalcon\Cache\Frontend\Data(array('lifetime' => 86400));
        $cache = new \Phalcon\Cache\Backend\Memcache($frontCache, array("host" => "localhost", "port" => "11211"));
        return $cache;
    });
    //Handle the request
    $app = new \Phalcon\Mvc\Application($di);
    echo $app->handle()->getContent();
} catch (\Phalcon\Exception $e) {
    echo "PhalconException: ", $e->getMessage();
} catch (PDOException $e) {
    die('数据库连接失败-' . $e->getMessage());
}
Esempio n. 24
0
 /**
  * @param \Phalcon\DiInterface $di
  *
  * @return \Phalcon\Mvc\Application
  */
 protected function getDefaultApplication(\Phalcon\DiInterface $di)
 {
     $application = new \Phalcon\Mvc\Application($di);
     $application->useImplicitView(false);
     return $application;
 }
Esempio n. 25
0
<?php

use DebugBar\StandardDebugBar;
defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'stage');
try {
    $configuration_path = dirname(dirname(__FILE__)) . '/application/config/';
    include $configuration_path . "namespaces.php";
    $di = (include $configuration_path . 'services.php');
    $modules = (include $configuration_path . 'modules.php');
    $di['router'] = (include $configuration_path . 'routers.php');
    $application = new \Phalcon\Mvc\Application($di);
    $di['app'] = $application;
    $application->registerModules($modules);
    (new Snowair\Debugbar\ServiceProvider())->start();
    echo $application->handle()->getContent();
} catch (\Exception $e) {
    echo get_class($e), ": ", $e->getMessage(), "\n";
    echo " File=", $e->getFile(), "\n";
    echo " Line=", $e->getLine(), "\n";
    echo $e->getTraceAsString();
}
echo "<!-- " . getenv('APPLICATION_ENV') . " -->";
Esempio n. 26
0
            default:
                if (Config::instance()->mail_exceptions && $mail) {
                    MailQueue::push2admin('Exception', $message);
                }
                break;
        }
    } else {
        throw $e;
    }
}
set_exception_handler(function (Exception $e) {
    logException($e);
    if (!Config::instance()->production || PHP_SAPI == 'cli') {
        throw $e;
    } else {
        $app = new Phalcon\Mvc\Application(Phalcon\DI::getDefault());
        switch (true) {
            case $e instanceof PageNotFound:
            case $e instanceof Phalcon\Mvc\Dispatcher\Exception:
                header('HTTP/1.1 404 Not Found');
                header('Status: 404 Not Found');
                $app->di->set('last_exception', $e);
                exit($app->handle('/error/show404')->getContent());
            default:
                header('HTTP/1.1 503 Service Temporarily Unavailable');
                header('Status: 503 Service Temporarily Unavailable');
                header('Retry-After: 3600');
                exit($app->handle('/error/show503')->getContent());
        }
    }
});
Esempio n. 27
0
<?php

error_reporting(E_ALL);
try {
    /**
     * Read the configuration
     */
    $config = (include __DIR__ . "/../app/config/config.php");
    /**
     * Read auto-loader
     */
    include __DIR__ . "/../app/config/loader.php";
    /**
     * Read services
     */
    include __DIR__ . "/../app/config/services.php";
    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application();
    $application->setDI($di);
    echo $application->handle()->getContent();
} catch (Phalcon\Exception $e) {
    echo $e->getMessage();
} catch (PDOException $e) {
    echo $e->getMessage();
}
Esempio n. 28
0
 function phalcon()
 {
     static $application = null;
     if (is_null($application)) {
         $loader = new \Phalcon\Loader();
         $loader->registerDirs(array(APPLICATION_PATH . DS . 'phalcon/controllers/', APPLICATION_PATH . DS . 'phalcon/models/'));
         $loader->register();
         $di = new \Phalcon\DI();
         //Registering a router
         $di->set('router', 'Phalcon\\Mvc\\Router');
         //Registering a dispatcher
         $di->set('dispatcher', 'Phalcon\\Mvc\\Dispatcher');
         //Registering a Http\Response
         $di->set('response', 'Phalcon\\Http\\Response');
         //Registering a Http\Request
         $di->set('request', 'Phalcon\\Http\\Request');
         //Registering the view component
         $di->set('view', function () {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir(APPLICATION_PATH . DS . 'phalcon/views/');
             return $view;
         });
         $params = \Thin\Bootstrap::$bag['config']->getDatabase();
         $di->set('db', function () use($params) {
             return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $params->getHost(), "username" => $params->getUsername(), "password" => $params->getPassword(), "dbname" => $params->getDbname()));
         });
         //Registering the Models-Metadata
         $di->set('modelsMetadata', 'Phalcon\\Mvc\\Model\\Metadata\\Memory');
         //Registering the Models Manager
         $di->set('modelsManager', 'Phalcon\\Mvc\\Model\\Manager');
         $application = new \Phalcon\Mvc\Application();
         $application->setDI($di);
     }
     return $application;
 }
Esempio n. 29
0
<?php

error_reporting(E_ALL);
define('APP_PATH', realpath('..'));
try {
    /**
     * Read the configuration
     */
    $config = (include APP_PATH . "/app/config/config.php");
    /**
     * Read auto-loader
     */
    include APP_PATH . "/app/config/loader.php";
    /**
     * Read services
     */
    include APP_PATH . "/app/config/services.php";
    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application($di);
    echo $application->handle()->getContent();
} catch (\Exception $e) {
    echo $e->getMessage();
}
Esempio n. 30
0
        echo '<script type="text/javascript">' . $console . '</script>';
    }
    require_once __DIR__ . '/../app/library/PhpConsole/__autoload.php';
    $handler = PhpConsole\Handler::getInstance();
    $handler->start();
    define('INDEX_PATH', __DIR__);
    /**
     * Read the configuration
     */
    $config = (include __DIR__ . "/../app/config/config.php");
    /**
     * Read auto-loader
     */
    include __DIR__ . "/../app/config/loader.php";
    /**
     * Read services
     */
    include __DIR__ . "/../app/config/services.php";
    /**
     * Read Common Method
     */
    include $config->application->controllersDir . 'CommonController.php';
    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application($di);
    $application->registerModules($di->getRegisterModules());
    echo $application->handle()->getContent();
} catch (\Exception $e) {
    echo $e->getMessage();
}