Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Oct 29, 2016
0 parents commit 1faeb4e
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
/vendor/
/composer.lock
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Matthieu Napoli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
14 changes: 14 additions & 0 deletions composer.json
@@ -0,0 +1,14 @@
{
"name": "wizacha/thephp6framework",
"description": "The one and only PHP 6 framework!",
"license": "MIT",
"type": "library",
"autoload": {
"files": [
"theframework.php"
]
},
"require": {
"php": "^6.0"
}
}
13 changes: 13 additions & 0 deletions index.php
@@ -0,0 +1,13 @@
<?php

require_once dirname(__FILE__) . '/vendor/autoload.php';

test(array(
'$_GET["foo"] = "bar\'bar"; $next();',
'security_middleware(); $next();',
'echo "1!\n"; $next(); echo "3!\n";',
'echo "2!\n"; $next();',
'echo $_GET["foo"] . "\n"; $next();',
))

;
62 changes: 62 additions & 0 deletions theframework.php
@@ -0,0 +1,62 @@
<?php

/* -----------------------------------------------------------------------------*/
/* THEPHP6FRAMEWORK */
/* -----------------------------------------------------------------------------*/

// FRAMEWORK CORE
function test(array $middlewares)
{
$next = 'nothing';
foreach (array_reverse($middlewares) as $middleware) {
$next = array(new LazyNext($middleware, $next), 'run');
}
$next();
}

class LazyNext
{
function __construct($middleware, $next)
{
$this->middleware = $middleware;
$this->next = $next;
}
function run()
{
// Put the variable in the local scope so that it's available in the middleware
$next = $this->next;
// TODO replace eval with Closures if they are ever implemented in PHP
eval($this->middleware);
}
}

// Does nothing
function nothing() {}


/* -----------------------------------------------------------------------------*/
/* MIDDLEWARE MARKETPLACE */
/* -----------------------------------------------------------------------------*/
/* Edit this file and add your open source middlewares!!! :) */
/* -----------------------------------------------------------------------------*/

// Secures the application BIG TIME
// @see http://php.net/manual/en/security.magicquotes.php
function security_middleware()
{
if (isset($_GET)) {
foreach ($_GET as &$value) {
$value = addslashes($value);
}
}
if (isset($_POST)) {
foreach ($_POST as &$value) {
$value = addslashes($value);
}
}
if (isset($_SESSION)) {
foreach ($_SESSION as &$value) {
$value = addslashes($value);
}
}
}

0 comments on commit 1faeb4e

Please sign in to comment.