Skip to content

Instantly share code, notes, and snippets.

View geggleto's full-sized avatar

Glenn Eggleton geggleto

View GitHub Profile
## 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 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);
}
});
@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);
/*
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 = []);
}
//...
ob_start();
include "home.php";
$body = ob_get_clean();
returen $response->write($body);
<?php
namespace Space;
class RouteManager {
public function __construct() {
$app = \Slim\Slim::getInstance();
$app->get('/', function () {
print "hi";
});
<?php
class UserTest extends \PHPUnit_Framework_TestCase {
/**
*
* @var GuzzleHttp\Client
*/
private $client;
public function setUp() {
@geggleto
geggleto / gist:968e35cc2b3b7a3db7d2
Created April 23, 2015 13:17
htaccess for slim on windows
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
<?php
namespace VMS\Traits;
trait UserRelationshipTrait {
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function users() {
return $this->hasOne("VMS\Models\User");
Capsule::connection()
->table('jobs')
->join('job_codes', 'jobs.id', '=', 'job_codes.job_id')
->join('codes', 'codes.id', '=', 'job_codes.code_id')
->where('date', '=', $date, 'and')
->where('user_id', '=', $pein)
->select("*");