Skip to content

Instantly share code, notes, and snippets.

View geggleto's full-sized avatar

Glenn Eggleton geggleto

View GitHub Profile
//...
ob_start();
include "home.php";
$body = ob_get_clean();
returen $response->write($body);
/*
Building a Middleware for Authentication
Components:
1) AuthFactory
- Responsible for creating the the session and loading it with data
*/
interface IAuthFactory {
public function setData($data = []);
}
@geggleto
geggleto / haha.php
Created November 18, 2015 14:12
production code atm
function ew_GetKeyword(&$src, &$kwlist, &$x, &$y, &$kw) {
$thisy = -1;
$thiskw = "";
foreach ($kwlist as $wrkkw) {
$wrkkw = trim($wrkkw);
if (EW_HIGHLIGHT_COMPARE) { // Case-insensitive
if (function_exists('stripos')) { // PHP 5
$wrky = stripos($src, $wrkkw, $x);
} else {
$wrky = strpos(strtoupper($src), strtoupper($wrkkw), $x);
@geggleto
geggleto / index.php
Created December 9, 2015 00:02
Slim 3 Middleware - Force HTTPS
$app->add(function (Request $request, Response $response, $next) {
if ($request->getUri()->getScheme() !== 'https') {
$uri = $request->getUri()->withScheme("https")->withPort(null);
return $response->withRedirect( (string)$uri );
} else {
return $next($request, $response);
}
});
## Use case
I have several "components" which are standalone Slim applications.
Maybe its a "UserManagement"... while I can run this module at /users on it's own... I want to install this package on another larger project.
In my main app,
I load "components"...
$components = [
"UserManagement" => [
"routes" => "../usermanagement/routes.php",
@geggleto
geggleto / index.php
Created January 26, 2016 20:56
slim 3 gist 1
$app->get('/hello[/[{name}]]', function ($req, $res, $args) {
if (!empty($args['name'])) {
return $res->write("Why Hello " . $args['name']);
} else {
return $res->write("Hello!");
}
});
@geggleto
geggleto / index.php
Last active January 26, 2016 22:12
slim 3 gist 2
//Let's configure it.
// Fetch DI Container
$container = $app->getContainer();
// Register Twig View helper and configure it
$container['view'] = function ($c) {
//You can change this as you want
$view = new \Slim\Views\Twig('templates', [
'cache' => false //or specify a cache directory
]);
@geggleto
geggleto / index.php
Created January 26, 2016 21:00
slim 3 gist 3
$app->get('/hello[/[{name}]]', function ($req, $res, $args) {
$get = $req->getQueryParams(); // Grab the Query Params... ["test" => "true"]
if (!empty($args['name'])) {
return $this->view->render($res, "hello.twig", ["name" => $args['name'], "test" => $get['test']]);
} else {
return $this->view->render($res, "hello.twig", ["name" => "", "test" => $get['test']]);
}
});
@geggleto
geggleto / index.php
Created January 26, 2016 22:12
slim 3 gist 4
//Let's use it!
$app->get('/hello[/[{name}]]', function ($req, $res, $args) {
if (!empty($args['name'])) {
return $this->view->render($res, "hello.twig", ["name" => $args['name']]);
} else {
return $this->view->render($res, "hello.twig", ["name" => ""]);
}
});
$app->run();
@geggleto
geggleto / index.php
Created January 26, 2016 22:20
slim 3 gist 5
<?php
$myGET = $request->getQueryParams();