#2 | Phalcon\Mvc\Application->handle
/home/sahara/apps/inmlhiiiinjl/public/index.php (539) <?php
//echo phpinfo(); exit;
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
use Phalcon\Mvc\Router,
Phalcon\Mvc\Application,
Phalcon\DI\FactoryDefault,
Phalcon\Security,
Phalcon\Loader;
use Phalcon\Logger;
use Phalcon\Logger\Adapter\File as FileAdapter;
use Phalcon\Http\Cookie;
use Phalcon\Http\Response\Cookies;
use Phalcon\Logger\Adapter\Stream;
use Phalcon\Html\Helper\Doctype;
use Phalcon\Html\Escaper;
$escaper = new Escaper();
$helper = new Doctype($escaper);
//(new \Phalcon\Debug)->listen();
use Phalcon\Support\Debug;
$debug = new Debug();
$debug->listen();
define('BASE_PATH', dirname(__DIR__));
define("BASE_URL", 'https://'. $_SERVER['HTTP_HOST']);
define('APP_PATH', BASE_PATH . '');
define('TEMPLATE', 'templates/');
define('ROOT_PATH', dirname(__DIR__));
$config = include APP_PATH . "/config/config.php";
//try {
/**
* The FactoryDefault Dependency Injector automatically registers
* the services that provide a full stack framework.
*/
$di = new FactoryDefault();
$di->setShared('connection', function () use ($config) {
return new \Phalcon\Db\Adapter\Pdo\Mysql([
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
]);
});
require_once(APP_PATH . '/library/diFile.php');
//Specify routes for modules
$di->set('router', function () {
$router = new Router();
$module = 'www';
$router->setDefaultModule($module);
$router->add(
"/",
array(
"module" => $module,
"controller" => 'index',
"action" => 'index',
));
$router->add(
"/:controller",
array(
"module" => $module,
"controller" => 1,
"action" => 'index'
));
$router->add(
"/:controller/",
array(
"module" => $module,
"controller" => 1,
"action" => 'index'
));
$router->add(
"/:controller/:action",
array(
"module" => $module,
"controller" => 1,
"action" => 2
));
$router->add('/:controller/:action/',
array(
"module" => $module,
"controller"=>1,
"action"=>2,
"params"=>3
)
);
$router->add('/:controller/:action/:params',
array(
"module" => $module,
"controller"=>1,
"action"=>2,
"params"=>3
)
);
//sahara module
//slab module
$sahara = 'sahara';
$router->add(
"/".$sahara,
array(
"module" => 'sahara',
"controller" => 'index',
"action" => 'index',
));
$router->add(
"/".$sahara."/",
array(
"module" => 'sahara',
"controller" => 'index',
"action" => 'index',
));
$router->add(
"/".$sahara."/:controller",
array(
"module" => 'sahara',
"controller" => 1,
"action" => 'index'
));
$router->add(
"/".$sahara."/:controller/",
array(
"module" => 'sahara',
"controller" => 1,
"action" => 'index'
));
$router->add(
"/".$sahara."/:controller/:action",
array(
"module" => 'sahara',
"controller" => 1,
"action" => 2
));
$router->add("/".$sahara."/:controller/:action/",
array(
"module" => 'sahara',
"controller"=>1,
"action"=>2,
"params"=>3
)
);
$router->add("/".$sahara."/:controller/:action/:params",
array(
"module" => 'sahara',
"controller"=>1,
"action"=>2,
"params"=>3
)
);
// $slabmodules = ['inventory','shop','sales','leasing','support','tenders','marketing','website','customers'];
// foreach ($slabmodules as $key => $value) {
// $_controller = 'main';
// $router->add(
// "/".$slab."/".$value,
// array(
// "module" => 'slab',
// "controller" => $_controller,
// "action" => 'index',
// "SLAB_MODULE" => $value
// ));
// $router->add(
// "/".$slab."/".$value."/",
// array(
// "module" => 'slab',
// "controller" => $_controller,
// "action" => 'index',
// "SLAB_MODULE" => $value
// ));
// $router->add(
// "/".$slab."/".$value."/:action",
// array(
// "module" => 'slab',
// "controller" => $_controller,
// "action" => 2,
// "SLAB_MODULE" => $value
// ));
// $router->add("/".$slab."/".$value."/:action/",
// array(
// "module" => 'slab',
// "controller"=>$_controller,
// "action"=>2,
// "SLAB_MODULE" => $value
// )
// );
// $router->add("/".$slab."/".$value."/:action/:params",
// array(
// "module" => 'slab',
// "controller"=>$_controller,
// "action"=>2,
// "params"=>3,
// "SLAB_MODULE" => $value
// )
// );
// }
//end slab module
// products
$products[700911483] = 'copy-printer';
$products[390036435] = 'consumables';
$products[265834157] = 'etr-machines';
$products[262031572] = 'paper-shredders';
$products[507279378] = 'photocopiers';
$products[448243161] = 'printers';
$products[545222025] = 'telephone-systems';
$products[654456067] = 'laptops';
$products[535686558] = 'desktops';
$products[240813391] = 'networking';
$products[319541512] = 'cameras-and-photography';
$products[867537469] = 'electronics';
$products[525003363] = 'electronics';
$products[161610912] = 'phones-and-tablets';
$products[723174557] = 'money-counter';
$products[828362971] = 'shredders';
$products[844223768] = 'binders';
$products[226844082] = 'projectors';
foreach ($products as $key => $value) {
$router->add(
"/".$value,
array(
"module" => $module,
"controller" => 'products',
"action" => 'index',
"product" => $value,
"categoryId" => $key
));
$router->add(
"/".$value."/",
array(
"module" => $module,
"controller" => 'products',
"action" => 'index',
"product" => $value,
"categoryId" => $key
));
// $router->add(
// "/".$value."/:action",
// array(
// "module" => $module,
// "controller" => 'products',
// "action" => 'filter',
// "product" => $value,
// "categoryId" => $key
// ));
// $router->add("/".$value."/:action/",
// array(
// "module" => $module,
// "controller"=> 'products',
// "action"=> 'filter',
// "product" => $value
// )
// );
// $router->add("/".$value."/:action/:params",
// array(
// "module" => $module,
// "controller"=>'products',
// "action"=> 'filter',
// "params"=>2,
// "product" => $value
// )
// );
}
//end products
// product
$productlist = array();
$productlist[939038626] = 'photocopiers/ECOSYS-M3145idn';
foreach ($productlist as $key => $value) {
$router->add(
"/".$value,
array(
"module" => $module,
"controller" => 'product',
"action" => 'index',
"productId" => $key
));
$router->add(
"/".$value."/",
array(
"module" => $module,
"controller" => 'product',
"action" => 'index',
"productId" => $key
));
}
//end product
//images
$images = array();
$images[APP_PATH.'/frontend/image/'] = 'saharabg.png';
foreach ($images as $key => $value) {
$router->add(
"/".$value,
array(
"module" => $module,
"controller" => 'image',
"action" => 'index',
"path" => $key,
"name" => $value,
));
$router->add(
"/".$value."/",
array(
"module" => $module,
"controller" => 'image',
"action" => 'index',
"path" => $key,
"name" => $value,
));
$router->add(
"/".$value."/{token}",
array(
"module" => $module,
"controller" => 'image',
"action" => 'index',
"path" => $key,
"name" => $value,
"token" => 1,
));
}
//end images
return $router;
});
$di->setShared('session', function() {
// $session = new \Phalcon\Session\Adapter\Stream();
// $session->start();
// return $session;
$session = new Phalcon\Session\Manager();
$files = new Phalcon\Session\Adapter\Stream( [
'savePath' => '/tmp',
]);
$session->setAdapter($files)->start();
return $session;
});
// $di->setShared('random', function() {
// $random = new Phalcon\Security\Random();
// return $random;
// });
// $di->set('flash', function () {
// $flash = new \Phalcon\Flash\Direct (
// array(
// 'error' => 'alert alert-danger',
// 'success' => 'alert alert-success',
// 'notice' => 'alert alert-info',
// 'warning' => 'alert alert-warning'
// )
// );
// return $flash;
// });
// $di->setShared('flashSession', function () {
// $flash = new \Phalcon\Flash\Session (
// // array(
// // 'error' => 'alert alert-danger',
// // 'success' => 'alert alert-success',
// // 'notice' => 'alert alert-info',
// // 'warning' => 'alert alert-warning'
// // )
// );
// return $flash;
// });
$di->set(
"logger",
function () {
$logger = new FileAdapter("__DIR__ . '/../../logger.log");
return $logger;
}
);
$di->setShared('controllerPath', function () {
if (!empty($_SERVER['REQUEST_URI'])) {
$uriParts = explode('?', $_SERVER['REQUEST_URI']);
$segment = explode('/', $uriParts[0]);
// $uri = str_replace('/', '', $uriParts[0]);
$uri = $segment[1].'/';
} else {
$uri = '/';
}
return $uri;
});
$di->set('users',function () {
include APP_PATH . '/services/users.php';
return new Users();
},
true
);
$di->set('categories',function () {
include APP_PATH . '/services/categories.php';
return new Categories();
},
true
);
$di->set('flash',function () {
include APP_PATH . '/services/flash.php';
return new Flash();
},
true
);
$di->set('directpay',function () {
include APP_PATH . '/services/directpay.php';
return new Directpay();
},
true
);
$di->set('item',function () {
include APP_PATH . '/services/item.php';
return new Item();
},
true
);
$di->set('redis',function () {
include BASE_PATH . '/vendor/autoload.php';
include BASE_PATH . '/vendor/predis/Autoloader.php';
Predis\Autoloader::register();
/* $client = new Predis\Client();
$client->set('foo', 'bar');
$value = $client->get('foo');*/
$redis = new Predis\Client(array(
"scheme" => "tcp",
"host" => "127.0.0.1",
"port" => 6379
));
return $redis;
});
$application = new \Phalcon\Mvc\Application($di);
//Create an application
// Register the installed modules
$application->registerModules(
array(
'www' => array(
'className' => 'Web\Module',
'path' => APP_PATH.'/www/module.php',
),
'sahara' => array(
'className' => 'Sahara\Module',
'path' => APP_PATH.'/sahara/module.php',
)
)
);
$request = new \Phalcon\Http\Request();
echo $application->handle($request->getURI())->getContent();
/*} catch (\Exception $e) {
echo $e->getMessage() . '<br>';
echo '<pre>' . $e->getTraceAsString() . '</pre>';
}*/
|