Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
sayed-cse authored Mar 11, 2024
1 parent 4a76bbe commit 09a0118
Show file tree
Hide file tree
Showing 75 changed files with 6,919 additions and 0 deletions.
188 changes: 188 additions & 0 deletions apps/back/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php declare(strict_types=1);
namespace F\Back;
use Phalcon\Autoload\Loader;
use Phalcon\Di\DiInterface;
use Exception;
use Phalcon\Dispatcher\Exception as DispatcherException;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Events\Event;
use Phalcon\Events\Manager as evManager;
use Phalcon\Mvc\ModuleDefinitionInterface;
use Phalcon\Mvc\ViewBaseInterface;
use Phalcon\Mvc\View;
use Phalcon\Mvc\View\Engine\Volt;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Encryption\Security;
use Phalcon\Encryption\Crypt;
use Phalcon\Http\Request;
use Phalcon\Http\Response\Cookies;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
// use Phalcon\Session\Adapter\Redis;
// use Phalcon\Storage\AdapterFactory;
// use Phalcon\Storage\SerializerFactory;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Session\Manager as SessionManager;
use Phalcon\Session\Adapter\Stream as Stream;
use Phalcon\Flash\Session as FlashSession;

class Module implements ModuleDefinitionInterface
{
public function registerAutoloaders(DiInterface $di = null)
{
$loader = new Loader();
#Register NameSpaces
$loader->setNamespaces(
[
'F\Back\Controllers' => APP_PATH . '/back/controllers/',
'F\Back\Models' => APP_PATH . '/back/models/',
]
);
# Register Classes
$loader->setClasses([
'PHPMailer' => BASE_PATH . '/library/PHPMailer.php',
]);
# Register Dir
$loader->setDirectories(array(
APP_PATH . '/back/models/',
BASE_PATH . '/plugins/',
BASE_PATH . '/library/',
BASE_PATH . '/helpers/',
),true);
# Register Files
$loader->setFiles([
BASE_PATH . '/library/fpdf.php',
BASE_PATH . '/library/phpMailer/PHPMailer.php',
]);
$loader->register();
}
public function registerServices(DiInterface $di = null)
{
require(APP_PATH . '/config/config.php');
$di->setShared('config', $config);

$di->setShared('url', function() use ($config){
$url = new UrlResolver();
$url->setBaseUri($config->appB->BaseUri);
if($config->settings->production === true){$url->setStaticBaseUri($config->appB->StaticBaseUri);} //For CDN Uri
return $url;
});
// Registering a dispatcher
$di->set('dispatcher',function () {
$eventManager = new evManager();
$eventManager->attach("dispatch:beforeException", function (Event $event, $dispatcher, DispatcherException $exception) {
$action = 'show503';
if($exception instanceof DispatcherException){
$action = 'show404';
switch ($exception->getCode()){
case DispatcherException::EXCEPTION_HANDLER_NOT_FOUND:
case DispatcherException::EXCEPTION_ACTION_NOT_FOUND:
case DispatcherException::EXCEPTION_INVALID_HANDLER:
case DispatcherException::EXCEPTION_INVALID_PARAMS:
$dispatcher->forward(array('controller' => 'error','action' => $action));
return false;
}
}else{$dispatcher->forward(array('controller' => 'error','action' => $action));}
});
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('F\Back\Controllers');
$dispatcher->setEventsManager($eventManager);
return $dispatcher;
},true);

# Registering the view component
$di->setShared('voltService',function (ViewBaseInterface $view) use ($config) {
if(true !== is_dir(BASE_PATH . $config->appB->cacheDir)){ mkdir(BASE_PATH . $config->appB->cacheDir, 777,true); }
$volt = new Volt($view);
$volt->setOptions(
[
'always' => true,
'extension' => '.php',
'separator' => '_',
'stat' => true,
'path' => BASE_PATH . $config->appB->cacheDir,
'prefix' => '%%',
]
);
return $volt;
});

$di->set('view',function () use ($config){
$view = new View();
$view->setViewsDir(APP_PATH . $config->appB->viewsDir);
$view->registerEngines([ '.volt' => 'voltService', ]);
return $view;
},true);

# Database
$di->setShared('db', function() use ($config){
$db = new DbAdapter(array(
'adapter' => $config->database->mysql->adapter,
'host' => $config->database->mysql->host,
'username' => $config->database->mysql->username,
'password' => $config->database->mysql->password,
'dbname' => $config->database->mysql->dbname,
'charset' => $config->database->mysql->charset,
'options' => array(
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4, time_zone = "+06:00"',
\PDO::ATTR_CASE => \PDO::CASE_LOWER,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_BOTH,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_PERSISTENT => FALSE,
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE,
\PDO::MYSQL_ATTR_COMPRESS => TRUE,
\PDO::ATTR_AUTOCOMMIT => TRUE,
#\PDO::MYSQL_ATTR_SSL_CA => "/home/ubuntu/YOUR_PEM_FILE_HERE",
)
));
return $db;
});
# Session
# For Redis
// $di->setShared('session', function(){
// $options = [
// 'host' => '127.0.0.1',
// 'port' => 6379,
// 'index' => '1',
// ];
// $session = new SessionManager();
// $serializerFactory = new SerializerFactory();
// $factory = new AdapterFactory($serializerFactory);
// $redis = new Redis($factory, $options);
// $session->setAdapter($redis)->start();
// return $session;
// });
# For Stream
$di->set('session', function() use ($config){
$session = new SessionManager();
# if(true !== is_dir(BASE_PATH . $config->appF->sessionDir)){ mkdir(BASE_PATH . $config->appF->sessionDir, 0777,true); }
#$files = new Stream(array('savePath' => BASE_PATH . $config->appB->sessionDir,));
$files = new Stream();
$session->setAdapter($files)->start();
return $session;
});
# Security
$di->set('security', function() {
$security= new Security();
$security->setWorkFactor(12);// Set the password hashing factor to 12 rounds
$security->setDefaultHash(Security::CRYPT_MD5);
return $security;
}, true);
# Crypt
$di->set('crypt',function() use ($config){
$crypt = new Crypt();
$crypt->setKey($config->appF->encryptKey);
return $crypt;
},true);
# Cookies
$di->set('cookies', function() {
$cookies = new Cookies();
$cookies->useEncryption(true);
return $cookies;
},true);
# Cache
# Queue
# ACL
# Logging
#EOF
}
}
56 changes: 56 additions & 0 deletions apps/back/controllers/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php declare(strict_types=1);
namespace F\Back\Controllers;
use Phalcon\Mvc\Controller;
use Phalcon\Http\Request;
use Phalcon\Tag;
class BaseController extends Controller
{
protected function initialize()
{
Tag::setTitleSeparator('::');
Tag::prependTitle('Kiyani');
#Tag::appendTitle('::');
Tag::setTitle('A Most Trusted Online Shopping in Bangladesh');
$this->view->siteName = $this->view->articlePublisher = $this->view->dynaArticleTitle = $this->view->dynaArticle = 'Kiyani';
$this->view->bizTel = '+8801965573738';
$this->view->bizMail = 'sales@kiyani.com';
$this->view->copyYear = '2023';
$this->view->dynarobot = "noindex,nofollow,noarchive,nosnippet,noodp,noydir,noimagechache";
$this->view->dynadesc = 'Online Shopping at a cheapest price for Automotive, Phones &amp; Accessories, Computers &amp; Electronics, Fashion, Beauty &amp; Health, Home &amp; Garden, Toys &amp; Sports, Weddings &amp; Events and more; just about anything else
Enjoy Free Shipping! Limited Time Sale Easy Return.';
$this->view->dynakey = 'Kiyani, kiyani.com, Online shopping, Automotive, Phones & Accessories, Computers & Electronics, Fashion, Beauty & Health, Home & Garden, Toys & Sports, Weddings & Events,Buy, Sale, Online shopping, Automotive, Phones, Accessories, Computers, Electronics, Fashion, Beauty, Health, Home, Garden, Toys, Sports, Weddings';
$this->view->dynagooglebot = 'noindex,nofollow';
$this->view->dynaGetAuthor = 'FireFly';
$this->view->author = '\/\/ebmaster:+880 1615577997,+880 1915577997';
$this->view->googleKey = '';
$this->view->dynaOgImg = 'img/favicon.png';
if($this->session->exists())
{
$uid = $this->session->get('id');$name = $this->session->get('uname');$active = $this->session->get('active');$level = $this->session->get('level');$type = $this->session->get('type');
}else{ $uid = $name = $active = $level = $type = 0; }
$this->view->uid = $uid;
$this->view->uname = $name;
$this->view->active = $active;
$this->view->level = $level;
$this->view->type = $type;
//$this->view->userip = $this->getuserip();


}
// public function beforeExecuteRoute() {




// /*
// * Force HTTPS.
// */
// if(!$this->request->isSecureRequest()){
// $url = "https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
// $this->response->redirect($url);
// return false;
// }
// return true;
// }
}

34 changes: 34 additions & 0 deletions apps/back/controllers/ErrorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);
namespace F\Back\Controllers;
class ErrorController extends BaseController
{
public function initialize()
{
parent::initialize();
$this->view->dynaOgImg = "/img/favicon.png";
$this->view->dynarobot = "noindex,nofollow,noarchive,nosnippet,noodp,noydir,noimagechache";
$this->view->dynagooglebot = "noindex,nofollow";
}
public function show503Action()
{
$this->view->dynaArticleTitle = "Error 503 Service Unavailable";
$this->view->dynaArticle = "Error 404 page not found";
$this->view->dynaOgUrl = $this->router->getControllerName();
$this->view->dynadesc = "Error 503 Service Unavailable";
$this->view->dynakey = "503, service Unavailable, internal server error";
$this->response->setHeader('HTTP/1.1 503','Service Unavailable');
$this->response->setStatusCode(503, 'Service Unavailable');
$this->view->pick('errors/503');
}
public function show404Action()
{
$this->view->dynaArticleTitle = "Error 404 page not found";
$this->view->dynaArticle = "Error 404 page not found";
$this->view->dynaOgUrl = $this->router->getControllerName();
$this->view->dynadesc = "Error 404 page not found";
$this->view->dynakey = "404, not found";
$this->response->setHeader('HTTP/1.0 404','Not Found');
$this->response->setStatusCode(404, 'Not Found');
$this->view->pick('errors/404');
}
}
Loading

0 comments on commit 09a0118

Please sign in to comment.