Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Team Recruitment
Looking to create a new framework.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="7r1n17y" data-source="post: 411570" data-attributes="member: 76124"><p>Hey i am looking t create a new php framework this is to provide simple, reusable, and secure code. Right now i have installed a couple composer packages and created some classes/interfaces and i am currently setup a custom made router. If anyone is interested in contributing email me at <a href="mailto:7r1n17y7@gmail.com">7r1n17y7@gmail.com</a></p><p></p><p>Code snippets:</p><p>[PHP]<?php</p><p>namespace App\r7r1n17y\Framework;</p><p>class Session implements ISessionInterface {</p><p> private $cookie;</p><p> public function __construct(Cookie $cookie) {</p><p> $this->cookie = $cookie;</p><p> }</p><p> public function start() {</p><p> session_start();</p><p> if (!$this->__lock()) {</p><p> $this->destroy();</p><p> redirect('/');</p><p> }</p><p> }</p><p> public function destroy() {</p><p> $_SESSION = array();</p><p> $params = session_get_cookie_params();</p><p> $this->cookie->delete(session_name());</p><p> session_destroy();</p><p> }</p><p> public function regenerate($deleteOldSession = true) {</p><p> return session_regenerate_id($deleteOldSession);</p><p> }</p><p> public function set($key, $value) {</p><p> $_SESSION[$key] = $value;</p><p> }</p><p> public function delete($key) {</p><p> if (isset($_SESSION[$key])) {</p><p> unset($_SESSION[$key]);</p><p> }</p><p> }</p><p> public function get($key, $default = null) {</p><p> if (isset($_SESSION[$key])) {</p><p> return $_SESSION[$key];</p><p> }</p><p> return $default;</p><p> }</p><p> private function __lock() {</p><p> if (!isset($_SERVER['HTTP_USER_AGENT'])) {</p><p> return false;</p><p> }</p><p> if (is_null($this->get('userIp')) || is_null($this->get('userAgent'))) {</p><p> $_SESSION = array();</p><p> $this->set('userIp', $_SERVER['REMOTE_ADDR']);</p><p> $this->set('userAgent', $_SERVER['HTTP_USER_AGENT']);</p><p> return true;</p><p> } elseif (</p><p> !equals($this->get('userIp'), $_SERVER['REMOTE_ADDR'])</p><p> || !equals($this->get('userAgent'), $_SERVER['HTTP_USER_AGENT'])</p><p> ) {</p><p> return false;</p><p> } else {</p><p> return true;</p><p> }</p><p> }</p><p>}</p><p>?>[/PHP]</p><p>[PHP]<?php</p><p>namespace App\r7r1n17y\Framework;</p><p>class Mailer implements IMailerInterface {</p><p> private $_smtp_host;</p><p> private $_smtp_port;</p><p> private $_smtp_auth;</p><p> private $_smtp_user;</p><p> private $_smtp_pass;</p><p> private $_smtp_secure;</p><p> private $_mail_from;</p><p> private $_mail_from_name;</p><p> private $_mail_charset;</p><p> private $_smtp;</p><p> public function __construct(array $config = array()) {</p><p> $this->_smtp_host = isset($config['smtp_host']) ? $config['smtp_host'] : 'mail.localhost';</p><p> $this->_smtp_port = isset($config['smtp_port']) ? $config['smtp_port'] : 25;</p><p> $this->_smtp_auth = isset($config['smtp_auth']) ? $config['smtp_auth'] : true;</p><p> $this->_smtp_user = isset($config['smtp_user']) ? $config['smtp_user'] : 'root@localhost';</p><p> $this->_smtp_pass = isset($config['smtp_pass']) ? $config['smtp_pass'] : 'password';</p><p> $this->_smtp_secure = isset($config['smtp_secure']) ? $config['smtp_secure'] : 'tls';</p><p> $this->_mail_from = isset($config['mail_from']) ? $config['mail_from'] : 'root@localhost';</p><p> $this->_mail_from_name = isset($config['mail_from_name']) ? $config['mail_from_name'] : 'root';</p><p> $this->_mail_charset = isset($config['mail_charset']) ? $config['mail_charset'] : 'utf-8';</p><p> $this->_smtp = isset($config['smtp']) ? $config['smtp'] : false;</p><p> }</p><p> public function send($to, $subject, $bind = array(), $template = 'plain') {</p><p> $mail = $this->__start();</p><p> $templatesDir = base_dir() . '/templates/';</p><p> $mail->addAddress($to);</p><p> $body = file_get_contents($templatesDir . $template . '.html');</p><p> foreach ($bind as $key => $value) {</p><p> $body = str_replace('{{' . $key . '}}', $value, $body);</p><p> }</p><p> $mail->Subject = $subject;</p><p> $mail->Body = $body;</p><p> if (!$mail->send()) {</p><p> throw new r7r1n17yException('E-Mail could not be sent. Info: {err-msg}', array('err-msg' => $mail->ErrorInfo));</p><p> }</p><p> }</p><p> private function __start() {</p><p> $mail = new \PHPMailer;</p><p> if ($this->_smtp) {</p><p> $mail->isSMTP();</p><p> $mail->Host = $this->_smtp_host;</p><p> $mail->Port = $this->_smtp_port;</p><p> $mail->SMTPSecure = $this->_smtp_secure;</p><p> $mail->SMTPAuth = $this->_smtp_auth;</p><p> $mail->Username = $this->_smtp_user;</p><p> $mail->Password = $this->_smtp_pass;</p><p> }</p><p> $mail->setFrom($this->_mail_from, $this->_mail_from_name);</p><p> $mail->CharSet = $this->_mail_charset;</p><p> return $mail;</p><p> }</p><p>}</p><p>?>[/PHP]</p><p>[PHP]<?php</p><p>namespace App\r7r1n17y\Framework;</p><p>date_default_timezone_set(@date_default_timezone_get());</p><p>require_once __DIR__ . '/check/check.php';</p><p>require_once __DIR__ . '/../../vendor/autoload.php';</p><p>require_once __DIR__ . '/config/config.php';</p><p>require_once __DIR__ . '/options/runtime.conf.php';</p><p>require_once __DIR__ . '/options/mb.conf.php';</p><p>require_once __DIR__ . '/options/pc.conf.php';</p><p>require_once __DIR__ . '/options/hybirdauth.conf.php';</p><p>require_once __DIR__ . '/options/func.conf.php';</p><p>require_once __DIR__ . '/options/ssl.conf.php';</p><p>require_once __DIR__ . '/exception.php';</p><p>require_once __DIR__ . '/extend.php';</p><p>require_once __DIR__ . '/ext/ppac.php';</p><p>require_once __DIR__ . '/interfaces/cookie.php';</p><p>require_once __DIR__ . '/cookie.php';</p><p>require_once __DIR__ . '/ext/container.php';</p><p>require_once __DIR__ . '/interfaces/session.php';</p><p>require_once __DIR__ . '/session.php';</p><p>require_once __DIR__ . '/interfaces/mailer.php';</p><p>require_once __DIR__ . '/mailer.php';</p><p>$container = new \Pimple\Container;</p><p>$container['browser'] = $container->factory(function () {</p><p> return new \Browser();</p><p>});</p><p>$container['cookie'] = $container->factory(function () {</p><p> return new Cookie(array(</p><p> 'domain' => 'localhost',</p><p> 'secure' => true</p><p> ));</p><p>});</p><p>$container['session'] = $container->factory(function ($c) {</p><p> return new Session($c['cookie']);</p><p>});</p><p>$container['mailer'] = $container->factory(function () {</p><p> return new Mailer(array(</p><p> 'mail_from' => 'admin@example.com';</p><p> 'mail_from_name' =>'John Doe';</p><p> ));</p><p>});</p><p></p><p></p><p>DI::setContainer($container);</p><p>function app($service = null) {</p><p> $c = DI::getInstance();</p><p> if (is_null($service)) {</p><p> return $c;</p><p> }</p><p> return $c[$service];</p><p>}</p><p></p><p></p><p>?>[/PHP]</p><p>[PHP]<?php</p><p>namespace App\r7r1n17y\Framework;</p><p>abstract class AutoLoadExtender {</p><p> private $_exts = array();</p><p> public $_this;</p><p> public function __construct() {</p><p> $_this = $this;</p><p> } </p><p> public function addExt($object) {</p><p> $this->_exts[] = $object;</p><p> }</p><p> public function __get($varName) {</p><p> foreach($this->_exts as $ext) {</p><p> if (property_exists($ext, $varName)) {</p><p> return $ext->$varName;</p><p> }</p><p> }</p><p> }</p><p> public function __call($method, $args) {</p><p> foreach($this->_exts as $ext) {</p><p> if (method_exists($ext, $method)) {</p><p> return call_user_method_array($method, $ext, $args);</p><p> }</p><p> }</p><p> trigger_error(</p><p> e("This method {$method} doesn\'t exists."),</p><p> E_USER_ERROR</p><p> );</p><p> }</p><p>}</p><p>?>[/PHP]</p></blockquote><p></p>
[QUOTE="7r1n17y, post: 411570, member: 76124"] Hey i am looking t create a new php framework this is to provide simple, reusable, and secure code. Right now i have installed a couple composer packages and created some classes/interfaces and i am currently setup a custom made router. If anyone is interested in contributing email me at [EMAIL]7r1n17y7@gmail.com[/EMAIL] Code snippets: [PHP]<?php namespace App\r7r1n17y\Framework; class Session implements ISessionInterface { private $cookie; public function __construct(Cookie $cookie) { $this->cookie = $cookie; } public function start() { session_start(); if (!$this->__lock()) { $this->destroy(); redirect('/'); } } public function destroy() { $_SESSION = array(); $params = session_get_cookie_params(); $this->cookie->delete(session_name()); session_destroy(); } public function regenerate($deleteOldSession = true) { return session_regenerate_id($deleteOldSession); } public function set($key, $value) { $_SESSION[$key] = $value; } public function delete($key) { if (isset($_SESSION[$key])) { unset($_SESSION[$key]); } } public function get($key, $default = null) { if (isset($_SESSION[$key])) { return $_SESSION[$key]; } return $default; } private function __lock() { if (!isset($_SERVER['HTTP_USER_AGENT'])) { return false; } if (is_null($this->get('userIp')) || is_null($this->get('userAgent'))) { $_SESSION = array(); $this->set('userIp', $_SERVER['REMOTE_ADDR']); $this->set('userAgent', $_SERVER['HTTP_USER_AGENT']); return true; } elseif ( !equals($this->get('userIp'), $_SERVER['REMOTE_ADDR']) || !equals($this->get('userAgent'), $_SERVER['HTTP_USER_AGENT']) ) { return false; } else { return true; } } } ?>[/PHP] [PHP]<?php namespace App\r7r1n17y\Framework; class Mailer implements IMailerInterface { private $_smtp_host; private $_smtp_port; private $_smtp_auth; private $_smtp_user; private $_smtp_pass; private $_smtp_secure; private $_mail_from; private $_mail_from_name; private $_mail_charset; private $_smtp; public function __construct(array $config = array()) { $this->_smtp_host = isset($config['smtp_host']) ? $config['smtp_host'] : 'mail.localhost'; $this->_smtp_port = isset($config['smtp_port']) ? $config['smtp_port'] : 25; $this->_smtp_auth = isset($config['smtp_auth']) ? $config['smtp_auth'] : true; $this->_smtp_user = isset($config['smtp_user']) ? $config['smtp_user'] : 'root@localhost'; $this->_smtp_pass = isset($config['smtp_pass']) ? $config['smtp_pass'] : 'password'; $this->_smtp_secure = isset($config['smtp_secure']) ? $config['smtp_secure'] : 'tls'; $this->_mail_from = isset($config['mail_from']) ? $config['mail_from'] : 'root@localhost'; $this->_mail_from_name = isset($config['mail_from_name']) ? $config['mail_from_name'] : 'root'; $this->_mail_charset = isset($config['mail_charset']) ? $config['mail_charset'] : 'utf-8'; $this->_smtp = isset($config['smtp']) ? $config['smtp'] : false; } public function send($to, $subject, $bind = array(), $template = 'plain') { $mail = $this->__start(); $templatesDir = base_dir() . '/templates/'; $mail->addAddress($to); $body = file_get_contents($templatesDir . $template . '.html'); foreach ($bind as $key => $value) { $body = str_replace('{{' . $key . '}}', $value, $body); } $mail->Subject = $subject; $mail->Body = $body; if (!$mail->send()) { throw new r7r1n17yException('E-Mail could not be sent. Info: {err-msg}', array('err-msg' => $mail->ErrorInfo)); } } private function __start() { $mail = new \PHPMailer; if ($this->_smtp) { $mail->isSMTP(); $mail->Host = $this->_smtp_host; $mail->Port = $this->_smtp_port; $mail->SMTPSecure = $this->_smtp_secure; $mail->SMTPAuth = $this->_smtp_auth; $mail->Username = $this->_smtp_user; $mail->Password = $this->_smtp_pass; } $mail->setFrom($this->_mail_from, $this->_mail_from_name); $mail->CharSet = $this->_mail_charset; return $mail; } } ?>[/PHP] [PHP]<?php namespace App\r7r1n17y\Framework; date_default_timezone_set(@date_default_timezone_get()); require_once __DIR__ . '/check/check.php'; require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/config/config.php'; require_once __DIR__ . '/options/runtime.conf.php'; require_once __DIR__ . '/options/mb.conf.php'; require_once __DIR__ . '/options/pc.conf.php'; require_once __DIR__ . '/options/hybirdauth.conf.php'; require_once __DIR__ . '/options/func.conf.php'; require_once __DIR__ . '/options/ssl.conf.php'; require_once __DIR__ . '/exception.php'; require_once __DIR__ . '/extend.php'; require_once __DIR__ . '/ext/ppac.php'; require_once __DIR__ . '/interfaces/cookie.php'; require_once __DIR__ . '/cookie.php'; require_once __DIR__ . '/ext/container.php'; require_once __DIR__ . '/interfaces/session.php'; require_once __DIR__ . '/session.php'; require_once __DIR__ . '/interfaces/mailer.php'; require_once __DIR__ . '/mailer.php'; $container = new \Pimple\Container; $container['browser'] = $container->factory(function () { return new \Browser(); }); $container['cookie'] = $container->factory(function () { return new Cookie(array( 'domain' => 'localhost', 'secure' => true )); }); $container['session'] = $container->factory(function ($c) { return new Session($c['cookie']); }); $container['mailer'] = $container->factory(function () { return new Mailer(array( 'mail_from' => 'admin@example.com'; 'mail_from_name' =>'John Doe'; )); }); DI::setContainer($container); function app($service = null) { $c = DI::getInstance(); if (is_null($service)) { return $c; } return $c[$service]; } ?>[/PHP] [PHP]<?php namespace App\r7r1n17y\Framework; abstract class AutoLoadExtender { private $_exts = array(); public $_this; public function __construct() { $_this = $this; } public function addExt($object) { $this->_exts[] = $object; } public function __get($varName) { foreach($this->_exts as $ext) { if (property_exists($ext, $varName)) { return $ext->$varName; } } } public function __call($method, $args) { foreach($this->_exts as $ext) { if (method_exists($ext, $method)) { return call_user_method_array($method, $ext, $args); } } trigger_error( e("This method {$method} doesn\'t exists."), E_USER_ERROR ); } } ?>[/PHP] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Team Recruitment
Looking to create a new framework.
Top