#1 Ceci est un test

Öppen
noa wants to merge 12 commits from noa/feature/session_debug into noa/master
57 ändrade filer med 1583 tillägg och 66 borttagningar
  1. 5 0
      .gitignore
  2. 0 27
      conf/nginx/hosts.d/default.conf
  3. 34 0
      config/nginx/default.conf
  4. 6 7
      docker-compose.yml
  5. 31 0
      docker/php/Dockerfile
  6. 13 0
      src/admin/ajax/ajax.session_handling.php
  7. 11 0
      src/admin/ajax/ajax.test.php
  8. 21 0
      src/admin/dist/bower.json
  9. 7 0
      src/admin/dist/css/debug.css
  10. 15 0
      src/admin/dist/home.html.tpl
  11. 10 0
      src/admin/dist/js/admin.js
  12. 29 0
      src/admin/dist/js/middleware/session.js
  13. 21 0
      src/admin/dist/login.html.tpl
  14. 10 0
      src/admin/dist/partial/debug.html.tpl
  15. 11 0
      src/admin/dist/partial/footer.html.tpl
  16. 22 0
      src/admin/dist/partial/header.html.tpl
  17. 22 0
      src/admin/dist/partial/navbar.html.tpl
  18. 8 0
      src/admin/dist/scss/debug.scss
  19. 12 0
      src/admin/index.php
  20. 32 0
      src/admin/login.php
  21. 10 0
      src/admin/test.php
  22. 7 8
      src/api/index.php
  23. 3 1
      src/api/v1.0/json.AbstractJson.php
  24. 9 0
      src/api/v1.0/object/json.Test.php
  25. 83 0
      src/class/class.Auth.php
  26. 24 0
      src/class/class.Autoloader.php
  27. 41 0
      src/class/class.AutoloaderClassMap.php
  28. 43 8
      src/class/class.Core.php
  29. 10 4
      src/class/class.CoreException.php
  30. 4 3
      src/class/class.Mysql.php
  31. 76 0
      src/class/class.StaticFileMap.php
  32. 22 0
      src/class/middleware/abstract.Middleware.php
  33. 81 0
      src/class/middleware/class.MiddlewareHandler.php
  34. 26 0
      src/class/middleware/interface.Middlewareable.php
  35. 18 0
      src/class/middleware/middlewares/auth/class.MiddlewareOauth.php
  36. 35 0
      src/class/middleware/middlewares/auth/class.MiddlewarePassword.php
  37. 43 0
      src/class/middleware/middlewares/class.MiddlewareAuth.php
  38. 73 0
      src/class/middleware/middlewares/class.MiddlewareDebug.php
  39. 21 0
      src/class/middleware/middlewares/class.MiddlewareMySQL.php
  40. 31 0
      src/class/middleware/middlewares/class.MiddlewareRender.php
  41. 28 0
      src/class/middleware/middlewares/class.MiddlewareRouter.php
  42. 23 0
      src/class/middleware/middlewares/class.MiddlewareTemplate.php
  43. 27 0
      src/class/middleware/middlewares/class.MiddlewareTranspiler.php
  44. 67 0
      src/class/middleware/middlewares/debug/abstract.MiddlewareDebug.php
  45. 58 0
      src/class/middleware/middlewares/debug/class.MiddlewareSession.php
  46. 22 0
      src/class/middleware/middlewares/debug/class.MiddlewareTiming.php
  47. 15 0
      src/class/middleware/middlewares/debug/interface.MiddlewareDegugable.php
  48. 31 0
      src/class/middleware/middlewares/templates/class.MiddlewareFlow.php
  49. 66 0
      src/class/middleware/middlewares/transpiler/class.MiddlewareCss.php
  50. 23 0
      src/class/url/class.UrlAdmin.php
  51. 74 0
      src/class/user/class.User.php
  52. 16 0
      src/composer.json
  53. 27 5
      src/config.php
  54. 2 2
      src/index.php
  55. 0 1
      src/lib/Savant3
  56. 22 0
      src/pipeline.yml
  57. 102 0
      src/script/script.generate_autoload_map_file.php

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+.idea
+src/vendor
+src/template
+src/admin/dist/bower_components
+src/composer.lock

+ 0 - 27
conf/nginx/hosts.d/default.conf

@@ -1,27 +0,0 @@
-server {
-  listen   80;
-  root /data/www;
-  index index.php index.html index.htm;
-  server_name milkyway.guern.eu;
-
-  # add locations for static files to not forward these requests to PHP
-  location /images {
-    try_files $uri $uri/ =404;
-  }
-
-  location /scripts {
-    try_files $uri $uri/ =404;
-  }
-
-  location /api {
-    include fastcgi_params;
-    fastcgi_param  SCRIPT_FILENAME /data/www/api/index.php;
-    fastcgi_pass php-upstream;
-  }
-
-  location / {
-    include fastcgi_params;
-    fastcgi_param  SCRIPT_FILENAME /data/www/index.php;
-    fastcgi_pass php-upstream;
-  }
-}

+ 34 - 0
config/nginx/default.conf

@@ -0,0 +1,34 @@
+upstream php-upstream {
+    server unix:/var/run/php/php5-fpm.sock;
+}
+
+server {
+  listen   80;
+  root /var/www/app;
+  index index.php index.html index.htm;
+  server_name milkyway.guern.eu;
+  sendfile off;
+
+  # add locations for static files to not forward these requests to PHP
+  location  ~* \.(css|js|png|gif) {
+    alias /var/www/app/admin/dist;
+    try_files $uri uri/ =404;
+  }
+
+  location /api {
+    include fastcgi_params;
+    fastcgi_param  SCRIPT_FILENAME /var/www/app/api/index.php;
+    fastcgi_pass php-upstream;
+  }
+
+  location /admin {
+    include fastcgi_params;
+    fastcgi_param  SCRIPT_FILENAME /var/www/app/index.php;
+    fastcgi_pass php-upstream;
+  }
+
+  location / {
+    try_files $uri =404;
+
+  }
+}

+ 6 - 7
docker-compose.yml

@@ -1,12 +1,11 @@
-nginx:
-  image: million12/nginx-php:php70
+nginx :
+  build : docker/php/
   volumes:
-    - "./src:/data/www"
-    - "./conf:/data/conf"
+    - "./src:/var/www/app"
+    - "./config/nginx:/etc/nginx/sites-enabled"
+    - "./config/php:/etc/php/7.0/fpm/conf.d"
   ports:
-    - "8080:80"
-  environment:
-    - "NGINX_GENERATE_DEFAULT_VHOST=false"
+    - "80:80"
 
 mysql:
   image: mysql/mysql-server:5.7

+ 31 - 0
docker/php/Dockerfile

@@ -0,0 +1,31 @@
+FROM romeoz/docker-nginx-php:5.6
+
+RUN locale-gen fr_FR.utf8
+
+# Relocate the timezone file
+RUN mkdir -p /config/etc && mv /etc/timezone /config/etc/ && ln -s /config/etc/timezone /etc/
+
+# Set the time zone
+RUN echo "Europe/Paris" > /config/etc/timezone
+
+# Set timezone as specified in /config/etc/timezone
+RUN dpkg-reconfigure -f noninteractive tzdata
+
+
+RUN echo "START" \
+    && apt-get update \
+    && apt-get install -y php-pear \
+    && pear config-set php_ini  /etc/php5/fpm/php.ini \
+    && apt-get install -y build-essential \
+    && apt-get install -y php5-dev \
+    && apt-get install -y libcurl3-openssl-dev \
+    && apt-get install -y libyaml-dev \
+    && pecl install yaml \
+    && rm -rf /var/lib/apt/lists/* \
+    && echo "END"
+
+WORKDIR /var/www/app/
+
+EXPOSE 80 433
+
+CMD ["/usr/bin/supervisord"]

+ 13 - 0
src/admin/ajax/ajax.session_handling.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 20:17
+ */
+
+MiddlewareHandler::$breakPipe = true;
+echo MiddlewareSession::ajaxRequest();
+//echo "[{\"text\":\"Root node\",\"children\":[{\"text\":\"Child node 1\"},{\"text\":\"Child node 2\"}]}]";
+
+//echo "[{\"text\":\"root\",\"children\":[{\"text\":\"child1\",\"children\":[]},{\"text\":\"child2\",\"children\":[]}]}]";

+ 11 - 0
src/admin/ajax/ajax.test.php

@@ -0,0 +1,11 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 15:35
+ */
+
+MiddlewareHandler::$breakPipe = true;
+
+echo 'test';

+ 21 - 0
src/admin/dist/bower.json

@@ -0,0 +1,21 @@
+{
+  "name": "dist",
+  "version": "0.0.0",
+  "authors": [
+    "Yannick Guern <yannick.guern.bzh@gmail.com>"
+  ],
+  "license": "MIT",
+  "ignore": [
+    "**/.*",
+    "node_modules",
+    "bower_components",
+    "test",
+    "tests"
+  ],
+  "dependencies": {
+    "bootstrap-tabs-x": "^1.3.2",
+    "bootstrap": "3.3.6",
+    "jquery": "2.2.2",
+    "jstree": "3.0.9"
+  }
+}

+ 7 - 0
src/admin/dist/css/debug.css

@@ -0,0 +1,7 @@
+.container-debug {
+  width: 20%;
+  float: right;
+}
+.vakata-context {
+  z-index: 10052 !important;
+}

+ 15 - 0
src/admin/dist/home.html.tpl

@@ -0,0 +1,15 @@
+{% extends "partial/header.html.tpl" %}
+
+{% block content %}
+    <div class="container">
+
+        <div class="starter-template">
+            <h1>Bootstrap starter template</h1>
+            <p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
+        </div>
+
+    </div>
+
+    <div id="test">a</div>
+
+{% endblock %}

+ 10 - 0
src/admin/dist/js/admin.js

@@ -0,0 +1,10 @@
+$(document).ready(function () {
+
+    $.ajax({
+        url : "/admin/ajax/ajax.test.php",
+        success : function(result) {
+            console.log(result);
+            $('#test').html(result);
+        }
+    });
+});

+ 29 - 0
src/admin/dist/js/middleware/session.js

@@ -0,0 +1,29 @@
+$(document).ready(function () {
+
+    if ($('#container-debug-session').length > 0) {
+
+        $.jstree.defaults.contextmenu.show_at_node = false;
+        $.jstree.defaults.contextmenu.select_node = true;
+
+        $('#container-debug-session').jstree({
+           core : {
+               check_callback : true,
+               data : {
+                   url : "/admin/ajax/ajax.session_handling.php",
+                   dataType : "json"
+               },
+               themes : {
+                   theme : 'default',
+                   icons : true,
+                   dots : false,
+                   //url : "/bower_components/jstree/dist/themes/default/style.min.css",
+               }
+            },
+
+            plugins : [
+                "contextmenu"
+            ]
+        });
+    }
+
+});

+ 21 - 0
src/admin/dist/login.html.tpl

@@ -0,0 +1,21 @@
+{% extends "partial/header.html.tpl" %}
+
+{% block content %}
+    <div class="container">
+
+        <form action="login.php" method="post">
+            <input type="hidden" value="{{ redirection }}" name="redirection">
+            <div class="form-group">
+                <label for="exampleInputEmail1">Email address</label>
+                <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email" name="email">
+            </div>
+            <div class="form-group">
+                <label for="exampleInputPassword1">Password</label>
+                <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password">
+            </div>
+            <button type="submit" class="btn btn-default">Submit</button>
+        </form>
+
+    </div>
+
+{% endblock %}

+ 10 - 0
src/admin/dist/partial/debug.html.tpl

@@ -0,0 +1,10 @@
+{% block debug %}
+
+    <div class="navbar-fixed-bottom row-fluid">
+        <div class="navbar-inner">
+            <div class="container-debug row">
+                {{ debugHtml }}
+            </div>
+        </div>
+    </div>
+{% endblock %}

+ 11 - 0
src/admin/dist/partial/footer.html.tpl

@@ -0,0 +1,11 @@
+{% include "debug.html.tpl" if debug %}
+
+{% for jsScript in jsScripts %}
+    {% if is_array(jsScript) and jsScript.interpolated  %}
+    <script type="text/javascript">{% include jsScript.src %}</script>
+    {% else %}
+    <script src="{{ jsScript }}" type="text/javascript"></script>
+    {% endif %}
+{% endfor %}
+</body>
+</html>

+ 22 - 0
src/admin/dist/partial/header.html.tpl

@@ -0,0 +1,22 @@
+<!doctype html>
+<html lang="fr">
+<head>
+    <meta charset="UTF-8">
+    <title>Cloud</title>
+    {% for cssFile in cssFiles %}
+        {% if is_array(cssFile) and cssFile.interpolated %}
+            <style type="text/css">{% include cssFile.src %}</style>
+        {% else %}
+            <link href="{{ cssFile }}" rel="stylesheet">
+        {% endif %}
+    {% endfor %}
+
+</head>
+<body>
+
+{% include "navbar.html.tpl" if navbar %}
+
+{% block content %}
+{% endblock %}
+
+{% include "footer.html.tpl" %}

+ 22 - 0
src/admin/dist/partial/navbar.html.tpl

@@ -0,0 +1,22 @@
+{% block header %}
+<nav class="navbar navbar-inverse ">
+    <div class="container">
+        <div class="navbar-header">
+            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
+                <span class="sr-only">Toggle navigation</span>
+                <span class="icon-bar"></span>
+                <span class="icon-bar"></span>
+                <span class="icon-bar"></span>
+            </button>
+            <a class="navbar-brand" href="#">Project name</a>
+        </div>
+        <div id="navbar" class="collapse navbar-collapse">
+            <ul class="nav navbar-nav">
+                <li class="active"><a href="#">Home</a></li>
+                <li><a href="#about">About</a></li>
+                <li><a href="#contact">Contact</a></li>
+            </ul>
+        </div><!--/.nav-collapse -->
+    </div>
+</nav>
+{% endblock %}

+ 8 - 0
src/admin/dist/scss/debug.scss

@@ -0,0 +1,8 @@
+.container-debug {
+    width: 20%;
+    float: right;
+}
+
+.vakata-context {
+    z-index:10052 !important;
+}

+ 12 - 0
src/admin/index.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 28/03/2016
+ * Time: 14:55
+ */
+
+Core::set("execFile", 'home.html.tpl');
+Core::set("optParams",array(
+
+));

+ 32 - 0
src/admin/login.php

@@ -0,0 +1,32 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 30/03/2016
+ * Time: 23:34
+ */
+
+if (isset($_POST)) {
+
+    if (isset($_POST['email']) and !empty($_POST['email']) and isset($_POST['password']) and !empty($_POST['password'])) {
+
+        $logged = Auth::checkLogin($_POST);
+        $redirection = isset($_POST['redirection']) ? rawurldecode($_POST['redirection']) : '';
+
+        if ($logged) {
+            echo 'test';
+            header("Location: $redirection");
+        }
+
+    }
+}
+
+
+
+Core::set('execFile', 'login.html.tpl');
+$optParams = array(
+    'navbar' => false,
+    'redirection' => isset($_GET['redirection']) ? rawurlencode($_GET['redirection']) : ''
+);
+
+Core::merge('optParams', $optParams);

+ 10 - 0
src/admin/test.php

@@ -0,0 +1,10 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 14:58
+ */
+
+MiddlewareHandler::$breakPipe = true;
+echo "test";

+ 7 - 8
src/api/index.php

@@ -7,20 +7,19 @@ try {
 	require_once dirname(__FILE__).'/../class/class.Core.php';
 
 	// init core app
-	Core::init();
-
-	// load API status
-	require_once API_DIR.'/v1.0/class.ApiStatus.php';
-
-	// load access rights
-	require_once API_DIR.'/v1.0/class.AccessRights.php';
+	Core::init("api");
 
 	// set header
 	header("HTTP/1.0 200 OK");
 	header("Content-Type : application/json");
 
 	// explode URL
-	$askedUrl = $_SERVER['PATH_INFO'];
+	$askedUrl = $_SERVER['SCRIPT_NAME'];
+
+	if(!preg_match('/(\/.*){4,}/', $askedUrl)) {
+		throw new CoreException(CoreException::UNAUTHORIZED_API_METHOD);
+	}
+
 	list($version, $module, $action) = array_slice(explode('/', $askedUrl), 2);
 	$verb = strtolower($_SERVER['REQUEST_METHOD']);
 

+ 3 - 1
src/api/v1.0/json.AbstractJson.php

@@ -2,13 +2,15 @@
 
 require_once API_DIR.'/v1.0/json.Objectable.php';
 
+/**
+ * Class AbstractJson
+ */
 class AbstractJson implements Objectable{ // TODO : This class must inherited from an oauth2 class
 
 
 	/**
 	* Associates provided params to class property
 	*/
-
 	public function sanitizeArgs() {
 
 		foreach ($_REQUEST as $key => $value) {

+ 9 - 0
src/api/v1.0/object/json.Test.php

@@ -27,6 +27,15 @@ class Test extends AbstractJson {
 			);
 	}
 
+	public function get_test() {
+		$message = sprintf("This is the value passed from post value : %s", $this->value);
+
+		return array(
+			"status" => ApiStatus::API_SUCCESS_STATUS,
+			"message" => $message,
+		);
+	}
+
 	protected function get_protected() {
 
 	}

+ 83 - 0
src/class/class.Auth.php

@@ -0,0 +1,83 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 30/03/2016
+ * Time: 23:32
+ */
+
+class Auth {
+
+    static function isLogged() {
+
+        if (!self::checkSession()) {
+            return false;
+        }
+
+        return true;
+
+    }
+
+
+
+    static function checkLogin($userData) {
+
+        extract($userData);
+        $query = "
+            SELECT id_user
+            FROM mw_users
+            WHERE email=\"$email\"
+            AND password = \"$password\"
+        ";
+        $result = Core::database()->query($query);
+
+
+        if($result->num_rows) {
+
+            $user = $result->fetch_assoc();
+
+            $_SESSION = array(
+                "uid" => $user['id_user'],
+                "hash" => sha1(SALT.$_SERVER['HTTP_USER_AGENT']),
+                'created_at' => time()
+            );
+
+            return true;
+        }
+
+        return false;
+
+    }
+
+    /**
+     * @return bool
+     */
+    static function checkSession() {
+
+        // Check if superglobal SESSION exists
+        if (!isset($_SESSION) or empty($_SESSION)) {
+            return false;
+        }
+
+        // Check if session owns mandatory fields
+        if (!isset($_SESSION['created_at']) or !isset($_SESSION['hash'])) {
+            return false;
+        }
+
+        // if this seesion is too old, then invalidate it
+        if (time() - $_SESSION['created_at'] > SESSION_TIME ) {
+            return false;
+        }
+
+        // if this session has been forged, then invalidate it
+        if ($_SESSION['hash'] != sha1(SALT.$_SERVER['HTTP_USER_AGENT'])) {
+            return false;
+        }
+
+        //update session creation time
+        $_SESSION['created_at'] = time();
+
+        return true;
+    }
+
+}

+ 24 - 0
src/class/class.Autoloader.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 27/03/2016
+ * Time: 16:42
+ */
+
+class Autoloader {
+
+    static function register() {
+        spl_autoload_register(array('Autoloader', 'autoload'));
+    }
+
+    static function autoload($class) {
+
+        require_once 'class.AutoloaderClassMap.php';
+        if (isset(AutoloaderClassMap::$mapClass[$class])) {
+            require CLASS_DIR . SEPARATOR . AutoloaderClassMap::$mapClass[$class];
+        }
+
+    }
+
+}

+ 41 - 0
src/class/class.AutoloaderClassMap.php

@@ -0,0 +1,41 @@
+<?php
+/**
+* This file have been automatically generated by autoloading script
+*/
+
+class AutoloaderClassMap {
+
+    public static $mapClass = array (
+
+		"Auth" => "/class.Auth.php",
+		"Core" => "/class.Core.php",
+		"CoreException" => "/class.CoreException.php",
+		"MysqliWrapper" => "/class.Mysql.php",
+		"JsScriptMap" => "/class.StaticFileMap.php",
+		"CssFileMap" => "/class.StaticFileMap.php",
+		"AbstractMiddleware" => "/middleware/abstract.Middleware.php",
+		"MiddlewareHandler" => "/middleware/class.MiddlewareHandler.php",
+		"Middlewareable" => "/middleware/interface.Middlewareable.php",
+		"MiddlewareOauth" => "/middleware/middlewares/auth/class.MiddlewareOauth.php",
+		"MiddlewarePassword" => "/middleware/middlewares/auth/class.MiddlewarePassword.php",
+		"MiddlewareAuth" => "/middleware/middlewares/class.MiddlewareAuth.php",
+		"MiddlewareDebug" => "/middleware/middlewares/class.MiddlewareDebug.php",
+		"MiddlewareMySQL" => "/middleware/middlewares/class.MiddlewareMySQL.php",
+		"MiddlewareRender" => "/middleware/middlewares/class.MiddlewareRender.php",
+		"MiddlewareRouter" => "/middleware/middlewares/class.MiddlewareRouter.php",
+		"MiddlewareTemplate" => "/middleware/middlewares/class.MiddlewareTemplate.php",
+		"MiddlewareTranspiler" => "/middleware/middlewares/class.MiddlewareTranspiler.php",
+		"AbstractMiddlewareDebug" => "/middleware/middlewares/debug/abstract.MiddlewareDebug.php",
+		"MiddlewareSession" => "/middleware/middlewares/debug/class.MiddlewareSession.php",
+		"MiddlewareTiming" => "/middleware/middlewares/debug/class.MiddlewareTiming.php",
+		"MiddlewareDebugable" => "/middleware/middlewares/debug/interface.MiddlewareDegugable.php",
+		"MiddlewareFlow" => "/middleware/middlewares/templates/class.MiddlewareFlow.php",
+		"MiddlewareCss" => "/middleware/middlewares/transpiler/class.MiddlewareCss.php",
+		"UrlAdmin" => "/url/class.UrlAdmin.php",
+		"User" => "/user/class.User.php",
+		"AccessRights" => "../api/v1.0/class.AccessRights.php",
+		"ApiStatus" => "../api/v1.0/class.ApiStatus.php",
+		"AbstractJson" => "../api/v1.0/json.AbstractJson.php",
+		"Objectable" => "../api/v1.0/json.Objectable.php",
+	);
+}

+ 43 - 8
src/class/class.Core.php

@@ -2,19 +2,54 @@
 
 class Core {
 
-	public static function init() {
+	/**
+	 * @var array $app
+	 */
+	public static  $app = array();
+
+	/**
+	 * @param string $key
+	 * @return mixed
+	 */
+	public static function __callStatic($name, $params) {
+		return Core::$app[$name];
+	}
+
+	/**
+	 * Append data to app array
+	 * @param string $key
+	 * @param mixed $element
+	 */
+	public static function set($key, $element) {
+		Core::$app[$key] = $element;
+	}
+
+    public static function merge($key, $element) {
+
+        if(!isset(Core::$app[$key])) {
+            Core::$app[$key] = array();
+        }
+
+        $old = Core::$app[$key];
+        Core::$app[$key] = array_merge($old, $element);
+    }
+
+	public static function init($pipe) {
+
+		//start sessions
+		session_start();
 
 		// load configuration file
-		require_once dirname(__FILE__).'/../config.php';
+		require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config.php';
 
-		// load core exceptions
-		require_once CLASS_DIR.'/class.CoreException.php';
+		// register autoloading
+		require LIB_DIR.SEPARATOR.'autoload.php';
+		require_once CLASS_DIR.SEPARATOR.'class.Autoloader.php';
+		Autoloader::register();
 
-		//load template engine
-		require_once LIB_DIR.'/Savant3/Savant3.php';
 
-		$tpl = new Savant3();
+		$handler = new MiddlewareHandler();
+		$handler->generate(ROOT_DIR.SEPARATOR.'pipeline.yml', $pipe);
 
 	}
-
 }

+ 10 - 4
src/class/class.CoreException.php

@@ -5,12 +5,17 @@ class CoreException extends Exception {
 	/**
 	* This method doesn't exist
 	*/
-	const INVALID_API_METHOD = 1000;
+	const INVALID_API_METHOD = 10;
 
-		/**
+    /**
 	* This method is forbidden from public interface
 	*/
-	const UNAUTHORIZED_API_METHOD = 1001;
+	const UNAUTHORIZED_API_METHOD = 11;
+
+	/**
+	 * Mandatory parameter doesn't given
+	 */
+    const INVALID_PARAMETERS = 12;
 
 	private $debug ='';
 
@@ -21,12 +26,13 @@ class CoreException extends Exception {
 		switch ($code) {
 			case CoreException::INVALID_API_METHOD : $message = "This API method doesn't exist"; break;
 			case CoreException::UNAUTHORIZED_API_METHOD : $message = "This API method isn't allowed"; break;
+            case CoreException::INVALID_PARAMETERS : $message = "Mandatory parameter doesn't given"; break;
 			
 			default : $message = "An unknown core error happened"; break;
 		}
 
 		if (!empty($complement)) {
-			$message .= "[".$complement."]";
+			$message .= " [".$complement."]";
 		}
 
 		$this->debug = $debug;

+ 4 - 3
src/class/class.Mysql.php

@@ -1,6 +1,6 @@
 <?php
 
-class Mysql {
+class MysqliWrapper extends mysqli {
 
 	//mysql instance
 	public static $db = null;
@@ -15,7 +15,7 @@ class Mysql {
 			return self::$db;
 		}
 
-		self::$db = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
+		self::$db = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB, MYSQL_PORT);
 
 		if (self::$db->connect_error) {
 
@@ -24,7 +24,8 @@ class Mysql {
 		}
 
 		return self::$db;
-
 	}
 
+
+
 }

+ 76 - 0
src/class/class.StaticFileMap.php

@@ -0,0 +1,76 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 30/03/2016
+ * Time: 21:56
+ */
+
+class JsScriptMap {
+
+    public static function getFilePath($page) {
+
+        if(DEBUG) {
+            self::$defaultFiles = array_merge(self::$defaultFiles, self::$debugFiles);
+        }
+
+        if(isset(self::$mapJs[$page])) {
+            return array_merge(self::$defaultFiles, self::$mapJs[$page]);
+        }
+        return self::$defaultFiles;
+
+    }
+
+    public static $debugFiles = array(
+        "/bower_components/bootstrap-tabs-x/js/bootstrap-tabs-x.min.js",
+        "/bower_components/jstree/dist/jstree.min.js"
+    );
+
+    private static $defaultFiles = array(
+        "/bower_components/jquery/dist/jquery.min.js",
+        "/bower_components/bootstrap/dist/js/bootstrap.min.js",
+    );
+
+    private static $mapJs = array (
+
+        'home.html.tpl' => array(
+            //'/js/admin.js'
+        ),
+
+    );
+}
+
+class CssFileMap {
+
+    public static function getFilePath($page) {
+
+        if(DEBUG) {
+            self::$defaultFiles = array_merge(self::$defaultFiles, self::$debugFiles);
+        }
+
+        if(isset(self::$mapCss[$page])) {
+            return array_merge(self::$defaultFiles, self::$mapCss[$page]);
+        }
+        return self::$defaultFiles;
+
+    }
+
+    public static $debugFiles = array(
+        '/bower_components/bootstrap-tabs-x/css/bootstrap-tabs-x.min.css',
+        '/css/debug.css',
+        //'/bower_components/bootstrap-jstree-theme/dist/themes/bootstrap/style.min.css'
+        "/bower_components/jstree/dist/themes/default/style.min.css"
+    );
+
+    private static $defaultFiles = array(
+        '/bower_components/bootstrap/dist/css/bootstrap.min.css',
+    );
+
+    public static $mapCss = array (
+
+//        'home.html.tpl' => array(
+//            '/css/debug.css'
+//        ),
+
+    );
+}

+ 22 - 0
src/class/middleware/abstract.Middleware.php

@@ -0,0 +1,22 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 06/04/2016
+ * Time: 21:57
+ */
+
+/**
+ * Class AbstractMiddleware
+ * Define the abstract Middleware which all Middleware
+ * must inherited
+ */
+abstract class AbstractMiddleware implements Middlewareable {
+
+    public function run($param = array() )
+    {
+        // TODO check param validity
+        $this->action($param);
+    }
+
+}

+ 81 - 0
src/class/middleware/class.MiddlewareHandler.php

@@ -0,0 +1,81 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 06/04/2016
+ * Time: 23:10
+ */
+
+class MiddlewareHandler {
+
+    private $configFilePath = '';
+
+    private $pipeline = null;
+
+    public static $breakPipe = false;
+
+    /**
+     * Applies sequentially all middleware in the order define into
+     * config file, propagates parameters to Middlewares if they exists
+     * @param string $configFilePath
+     */
+    public function generate($configFilePath, $pipeName="admin") {
+
+        $this->configFilePath = $configFilePath;
+        $this->readConfig();
+
+        if (!isset($this->pipeline[$pipeName])) {
+            return;
+        }
+
+        foreach($this->pipeline[$pipeName] as $index => $value) {
+
+            if(MiddlewareHandler::$breakPipe) {
+                break;
+            }
+
+            extract(MiddlewareHandler::retrieveClassAndParameters($value));
+
+            $reflection  = new ReflectionClass($className);
+
+            $middleware = $reflection->newInstance();
+
+            /**
+             * @var AbstractMiddleware $middleware
+             */
+            $middleware->run($params);
+        }
+
+    }
+
+    protected function readConfig() {
+
+        $pipeline = yaml_parse_file($this->configFilePath);
+
+        if ($pipeline) {
+            $this->pipeline = $pipeline;
+        }
+
+    }
+
+    public static function retrieveClassAndParameters($value) {
+        $params = array();
+
+        if (gettype($value) == 'string') {
+
+            $className = "Middleware".ucfirst($value);
+        } else {
+            reset($value);
+            $middlewareName = key($value);
+            $params = $value[$middlewareName];
+            $className = "Middleware".ucfirst($middlewareName);
+
+        }
+
+        return array(
+            "className" => $className,
+            "params" => $params
+        );
+    }
+
+}

+ 26 - 0
src/class/middleware/interface.Middlewareable.php

@@ -0,0 +1,26 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 06/04/2016
+ * Time: 21:59
+ */
+
+/**
+ * Interface Middlewareable
+ * This interface defines which methods must be defined by class
+ * to be considered as Middleware
+ */
+interface Middlewareable {
+
+    /**
+     * Apply modification on Core::$app object
+     */
+    public function run($param);
+
+    /**
+     *
+     */
+    public function action($param);
+
+}

+ 18 - 0
src/class/middleware/middlewares/auth/class.MiddlewareOauth.php

@@ -0,0 +1,18 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 15:07
+ */
+
+class MiddlewareOauth extends AbstractMiddleware {
+    /**
+     * @inheritDoc
+     */
+    public function action($param)
+    {
+        // TODO: Implement action() method.
+    }
+
+}

+ 35 - 0
src/class/middleware/middlewares/auth/class.MiddlewarePassword.php

@@ -0,0 +1,35 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 11:43
+ */
+
+class MiddlewarePassword extends AbstractMiddleware {
+
+    /**
+     * @inheritDoc
+     */
+    public function action($param) {
+
+        //If user isn't logged, redirect him toward login page
+        if (!Auth::isLogged() and !isset($_GET['redirection'])) {
+
+            header('Location: /admin/login.php?redirection='.rawurlencode($_SERVER['REQUEST_URI']));
+
+        } else if (Auth::isLogged()){
+
+            $redirection = isset($_GET['redirection']) ? $_GET['redirection'] : '';
+
+            if ($redirection != "") {
+
+                $location = rawurldecode($redirection);
+
+                header('Location: '.$location);
+            }
+
+        }
+
+    }
+}

+ 43 - 0
src/class/middleware/middlewares/class.MiddlewareAuth.php

@@ -0,0 +1,43 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 11:21
+ */
+
+class MiddlewareAuth extends AbstractMiddleware {
+
+    /**
+     * @inheritDoc
+     */
+    public function action($param)
+    {
+        $param = $param[0];
+
+        if (!isset($param['params'])) {
+            throw new CoreException(CoreException::INVALID_PARAMETERS, 'MiddlewareAuth : params parameter required');
+        }
+
+        $param = $param['params'];
+
+        $param = array_reduce($param, function($carry, $item) {
+            return array_merge($carry, $item);
+        }, array());
+
+
+        if (!isset($param['type'])) {
+            throw new CoreException(CoreException::INVALID_PARAMETERS, 'MiddlewareAuth : type parameter required');
+        }
+
+        $className = "Middleware".ucfirst($param['type']);
+        $reflection  = new ReflectionClass($className);
+
+        $middleware = $reflection->newInstance();
+
+        /**
+         * @var AbstractMiddleware $middleware
+         */
+        $middleware->run($param);
+    }
+}

+ 73 - 0
src/class/middleware/middlewares/class.MiddlewareDebug.php

@@ -0,0 +1,73 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 13:20
+ */
+
+class MiddlewareDebug extends AbstractMiddleware {
+
+    /**
+     * @inheritDoc
+     */
+    public function action($param) {
+
+        $middlewares = array();
+
+        foreach($param as $element) {
+
+            extract(MiddlewareHandler::retrieveClassAndParameters($element));
+
+            $active = $params == 'active' ? true : false;
+
+            $reflection = new ReflectionClass($className);
+            $middleware = $reflection->newInstance($active);
+            $middlewares[] = $middleware;
+        }
+
+        $html = $this->generateDebugHtml($middlewares);
+
+        $optParams = array('debugHtml' => $html);
+
+        Core::merge('optParams', $optParams);
+
+
+    }
+
+    public function generateDebugHtml($debugMiddlewares) {
+
+        $tabs = '';
+        $content = '';
+
+        /**
+         * @var AbstractMiddlewareDebug $middleware
+         */
+        foreach($debugMiddlewares as $middleware) {
+
+            $data = $middleware->getData();
+
+            $active = $data['active'];
+            $name = $data['name'];
+
+            $activeStringContent = $active ? 'in active' : '';
+            $activeStringTab = $active ? 'active' : '';
+
+            $tabs .= sprintf('<li class="%s"><a href="#%s" role="tab" data-toggle="tab">%s</a></li>', $activeStringTab, $name, ucfirst($name));
+            $content .= $middleware->getHtml() ? $middleware->getHtml() : sprintf('<div class="tab-pane fade %s" id="%s"><div id="container-debug-%s"></div></div>', $activeStringContent, $name, $name);
+        }
+
+        return <<< HTML
+        <!-- Tabs Below Right -->
+                <div class='tabs-x tabs-below tab-bordered tab-align-right'>
+                    <div class="tab-content">
+                        {$content}
+                    </div>
+                    <ul class="nav nav-tabs" role="tablist">
+                        {$tabs}
+                    </ul>
+                </div>
+            </div>
+HTML;
+    }
+}

+ 21 - 0
src/class/middleware/middlewares/class.MiddlewareMySQL.php

@@ -0,0 +1,21 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 06/04/2016
+ * Time: 22:13
+ */
+
+class MiddlewareMySQL extends AbstractMiddleware {
+
+    public function action($param)
+    {
+        try {
+            $instance = MysqliWrapper::getInstance();
+            Core::set('database', $instance);
+
+        } catch (mysqli_sql_exception $e) {
+            error_log($e->getMessage());
+        }
+    }
+}

+ 31 - 0
src/class/middleware/middlewares/class.MiddlewareRender.php

@@ -0,0 +1,31 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 13:04
+ */
+
+class MiddlewareRender extends AbstractMiddleware {
+
+    /**
+     * @inheritDoc
+     */
+    public function action($param) {
+
+        if (!is_null(Core::execFile())) {
+            $template  = Core::template()->load(Core::execFile());
+            $defaultParams = array(
+                "jsScripts" => JsScriptMap::getFilePath(Core::execFile()),
+                "cssFiles" => CssFileMap::getFilePath(Core::execFile()),
+                "navbar" => true,
+                "debug" => DEBUG
+            );
+
+            Core::set("optParams", array_merge($defaultParams, Core::optParams()));
+
+            $template->display(Core::optParams());
+        }
+
+    }
+}

+ 28 - 0
src/class/middleware/middlewares/class.MiddlewareRouter.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 12:44
+ */
+
+class MiddlewareRouter extends AbstractMiddleware {
+    /**
+     * @inheritDoc
+     */
+    public function action($param) {
+
+        if ($param == "admin") {
+
+            $askedUrl = $_SERVER['SCRIPT_NAME'];
+
+            //admin url
+            UrlAdmin::template($askedUrl);
+        }
+
+
+
+        // TODO: Implement action() method.
+    }
+
+}

+ 23 - 0
src/class/middleware/middlewares/class.MiddlewareTemplate.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 06/04/2016
+ * Time: 22:55
+ */
+
+class MiddlewareTemplate extends AbstractMiddleware {
+    /**
+     * @inheritDoc
+     */
+    public function action($param) {
+
+        /**@var AbstractMiddleware $middleware */
+        $module = 'Middleware'.ucfirst($param);
+        $reflection = new ReflectionClass($module);
+        $middleware = $reflection->newInstance();
+        $middleware->run();
+    }
+
+
+}

+ 27 - 0
src/class/middleware/middlewares/class.MiddlewareTranspiler.php

@@ -0,0 +1,27 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 18:28
+ */
+
+class MiddlewareTranspiler extends AbstractMiddleware {
+    /**
+     * @inheritDoc
+     */
+    public function action($param)
+    {
+        // TODO: Implement action() method.
+
+        foreach($param as $element) {
+
+            extract(MiddlewareHandler::retrieveClassAndParameters($element));
+
+            $reflection = new ReflectionClass($className);
+            $middleware = $reflection->newInstance();
+            $middleware->run($params);
+        }
+    }
+
+}

+ 67 - 0
src/class/middleware/middlewares/debug/abstract.MiddlewareDebug.php

@@ -0,0 +1,67 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 13:39
+ */
+
+abstract class AbstractMiddlewareDebug implements MiddlewareDebugable{
+
+    protected $name = '';
+    protected $activeTab = false;
+
+    public function __construct($activeTab = false) {
+        $this->activeTab = $activeTab;
+    }
+
+
+    public function getData() {
+        return array(
+            "name" => $this->name,
+            "active" => $this->activeTab
+        );
+    }
+
+    public function getHtml() {
+        // TODO: Implement getHtml() method.
+        return false;
+    }
+
+    public static function toJstreeData ($data, $name) {
+
+        $jstreeData = array(
+            array(
+                'text' => $name,
+                'children' => array()
+            )
+        );
+
+        function createLeaf($name, $data) {
+
+            return array(
+                'text' => $name,
+                'children' => array($data)
+            );
+        }
+
+        function walk($root, $tree) {
+
+            foreach ($root as $element => $value) {
+
+                if (is_array($element)) {
+                    walk($element);
+                }
+
+                $tree[0]['children'][] = createLeaf($element, $value);
+            }
+
+            return $tree;
+        }
+
+        $jstreeData = walk($data, $jstreeData);
+
+        return $jstreeData;
+    }
+
+}

+ 58 - 0
src/class/middleware/middlewares/debug/class.MiddlewareSession.php

@@ -0,0 +1,58 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 31/03/2016
+ * Time: 23:05
+ */
+
+class MiddlewareSession extends AbstractMiddlewareDebug {
+
+    public function __construct($activeTab=false) {
+
+        parent::__construct($activeTab);
+        $this->name = "session";
+
+        array_push(JsScriptMap::$debugFiles, '/js/middleware/session.js');
+
+    }
+
+    static function ajaxRequest($params=array()) {
+
+        $session = $_SESSION;
+
+        //reformat data
+        if (isset($session['created_at'])) {
+
+            $old = new DateTime();
+            $old->setTimestamp($session['created_at']);
+
+            $delta = new DateInterval("PT".SESSION_TIME."S");
+
+            $new = $old->add($delta);
+
+            $session['created_at'] = date("D j F Y  H:i:s", $session['created_at']);
+            $session['end_at'] = $new->format("D j F Y  H:i:s");
+        }
+
+        $session = AbstractMiddlewareDebug::toJstreeData($session, "session");
+
+        //var_dump($session);
+
+        return json_encode($session);
+
+    }
+
+    public function getHtml() {
+
+        $html = <<< HTML
+        <div class="tab-pane fade in active" id="session">
+            <h2>Session</h2>
+            <div id="container-debug-session"></div>
+        </div>
+HTML;
+
+        return $html;
+
+    }
+}

+ 22 - 0
src/class/middleware/middlewares/debug/class.MiddlewareTiming.php

@@ -0,0 +1,22 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 31/03/2016
+ * Time: 23:05
+ */
+
+class MiddlewareTiming extends AbstractMiddlewareDebug {
+
+    public function __construct($activeTab=false) {
+
+        parent::__construct($activeTab);
+        $this->name = "timing";
+
+    }
+
+    public static function ajaxRequest($params=array())
+    {
+        // TODO: Implement ajaxRequest() method.
+    }
+}

+ 15 - 0
src/class/middleware/middlewares/debug/interface.MiddlewareDegugable.php

@@ -0,0 +1,15 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 13:40
+ */
+
+interface MiddlewareDebugable {
+
+    function getData();
+    function getHtml();
+    static function ajaxRequest($params=array());
+
+}

+ 31 - 0
src/class/middleware/middlewares/templates/class.MiddlewareFlow.php

@@ -0,0 +1,31 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 06/04/2016
+ * Time: 22:55
+ */
+
+class MiddlewareFlow extends AbstractMiddleware {
+    /**
+     * @inheritDoc
+     */
+    public function action($param)
+    {
+        //define some helpers
+        $helpers = array(
+            'is_array' => function($object) { return is_array($object); },
+        );
+
+        //Flow config
+        $flow = new Flow\Loader(array(
+            'source' => ADMIN_DIR.SEPARATOR.'dist',
+            'target' => TEMPLATE_DIR,
+            'helpers' =>$helpers
+        ));
+
+        Core::set('template', $flow);
+    }
+
+
+}

+ 66 - 0
src/class/middleware/middlewares/transpiler/class.MiddlewareCss.php

@@ -0,0 +1,66 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 09/04/2016
+ * Time: 18:41
+ */
+
+class MiddlewareCss extends AbstractMiddleware {
+    /**
+     * @inheritDoc
+     */
+    public function action($param) {
+        // TODO: Implement action() method.
+
+        $param = array_reduce($param, function($carry, $item) {
+            return array_merge($carry, $item);
+        }, array());
+
+        if (!isset($param['input'])) {
+            throw new CoreException(CoreException::INVALID_PARAMETERS, 'MiddlewareCss : input parameter required');
+        }
+
+        if (!isset($param['output'])) {
+            throw new CoreException(CoreException::INVALID_PARAMETERS, 'MiddlewareCss : output parameter required');
+        }
+
+        $input = ROOT_DIR.SEPARATOR.$param['input'];
+        $output = ROOT_DIR.SEPARATOR.$param['output'];
+
+        if (!is_dir($output)) {
+            mkdir($output);
+        }
+
+        $this->walk($input, $output);
+
+    }
+
+    /**
+     * Walk on dir to found files
+     * @param $base_dir string Absolute root dir to scanned dir
+     * @return array <string> Relative file path to files found
+     */
+    protected function walk($base_dir, $prec) {
+
+        SassCompiler::run($base_dir.SEPARATOR, $prec.SEPARATOR);
+
+        $scan = scandir($base_dir);
+
+        foreach($scan as $elem) {
+
+            if (in_array($elem, array('.', '..'))) { continue; }
+
+            if (is_dir($base_dir.SEPARATOR.$elem)) {
+
+                if (!is_dir($prec.SEPARATOR.$elem)) {
+                    mkdir($prec.SEPARATOR.$elem);
+                }
+
+                $this->walk($base_dir.SEPARATOR.$elem, $prec.$elem.SEPARATOR);
+            }
+
+        }
+    }
+
+}

+ 23 - 0
src/class/url/class.UrlAdmin.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 27/03/2016
+ * Time: 15:07
+ */
+
+class UrlAdmin {
+
+    static function template ($askedUrl) {
+
+        // Check if user is logged and have rights to get this page
+        // TODO
+
+        if (is_file(ROOT_DIR.SEPARATOR.$askedUrl)) {
+            require ROOT_DIR.SEPARATOR.$askedUrl;
+        } else {
+            require ADMIN_DIR.SEPARATOR."index.php";
+        }
+    }
+    
+}

+ 74 - 0
src/class/user/class.User.php

@@ -0,0 +1,74 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 28/03/2016
+ * Time: 21:50
+ */
+
+class User {
+
+    /**
+     * @var string
+     */
+    private $firstname = "";
+
+    /**
+     * @var string
+     */
+    private $lastname = "";
+
+    /**
+     * @var string
+     */
+    private $email = "";
+
+    /**
+     * @return string
+     */
+    public function getEmail()
+    {
+        return $this->email;
+    }
+
+    /**
+     * @param string $email
+     */
+    public function setEmail($email)
+    {
+        $this->email = $email;
+    }
+
+    /**
+     * @return string
+     */
+    public function getFirstname()
+    {
+        return $this->firstname;
+    }
+
+    /**
+     * @param string $firstname
+     */
+    public function setFirstname($firstname)
+    {
+        $this->firstname = $firstname;
+    }
+
+    /**
+     * @return string
+     */
+    public function getLastname()
+    {
+        return $this->lastname;
+    }
+
+    /**
+     * @param string $lastname
+     */
+    public function setLastname($lastname)
+    {
+        $this->lastname = $lastname;
+    }
+
+}

+ 16 - 0
src/composer.json

@@ -0,0 +1,16 @@
+{
+  "name": "noa/milkyway",
+  "description": "administrative site to milkyway project",
+  "minimum-stability": "alpha",
+  "license": "MIT",
+  "authors": [
+    {
+      "name": "Yannick Guern",
+      "email": "yannick.guern.bzh@gmail.com"
+    }
+  ],
+  "require": {
+    "flow/flow": "0.7.2",
+    "panique/php-sass": "v1.0"
+  }
+}

+ 27 - 5
src/config.php

@@ -1,17 +1,39 @@
 <?php
 
+//Separator
+if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
+    define("SEPARATOR", "\\");
+else
+    define("SEPARATOR", "/");
+
+//debug
+define('DEBUG', 1);
+setlocale(LC_TIME, 'fr_FR');
+
+//error reporting
+error_reporting(E_ALL);
+ini_set('display_errors', 1);
+
 //Database config
 define('DB_PREFIX', 'mw_');
 
 //File system
 define('ROOT_DIR', dirname(__FILE__));
-define('LIB_DIR', ROOT_DIR.'/lib');
-define('CLASS_DIR', ROOT_DIR.'/class');
-define('API_DIR', ROOT_DIR.'/api');
+define('LIB_DIR', ROOT_DIR.SEPARATOR.'vendor');
+define('CLASS_DIR', ROOT_DIR.SEPARATOR.'class');
+define('API_DIR', ROOT_DIR.SEPARATOR.'api');
+define('TEMPLATE_DIR', ROOT_DIR.SEPARATOR.'template');
+define('ADMIN_DIR', ROOT_DIR.SEPARATOR.'admin');
 
 //MySQL configuration
 define('MYSQL_USER', 'operator');
 define('MYSQL_PASSWORD', 'LWnbeHn57Fwh');
-define('MYSQL_HOST', 'localhost');
+define('MYSQL_HOST', '192.168.99.100');
 define('MYSQL_PORT', 3306);
-define('MySQL_DB', 'milky_way');
+define('MYSQL_DB', 'milky_way');
+
+//Salt
+define('SALT', "!06rG%Unx)@VfePE1bb@B4poeJvl67Bmv_4y-1y%P^IJFuOSerQBw5kvn5M1g4JW");
+
+//Session configuration
+define('SESSION_TIME', 8 * 60 * 60); //8 hours

+ 2 - 2
src/index.php

@@ -3,9 +3,9 @@ require_once dirname(__FILE__).'/class/class.Core.php';
 
 try {
 
-	Core::init();
+	Core::init("admin");
 
 } catch (Exception $e) {
 	header("HTTP/1.0 404 Not Found");
-	error_log($e);
+	var_dump($e);
 }

+ 0 - 1
src/lib/Savant3

@@ -1 +0,0 @@
-Subproject commit ebf4385bf44bec8c7a169571ac178f626017c466

+ 22 - 0
src/pipeline.yml

@@ -0,0 +1,22 @@
+"api":
+  - mySQL
+  - auth :
+      - params :
+        - type : "oauth"
+
+admin:
+  - mySQL
+  - auth :
+    - params :
+      - type : "password"
+  - template : "flow"
+  - router :  "admin"
+  - "debug" :
+    - "session" : "active"
+    - "timing"
+  - "transpiler":
+#    - "js"
+    - "css" :
+      - input : "admin/dist/scss/"
+      - output : "admin/dist/css/"
+  - "render"

+ 102 - 0
src/script/script.generate_autoload_map_file.php

@@ -0,0 +1,102 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Noa
+ * Date: 27/03/2016
+ * Time: 17:02
+ */
+require_once __DIR__."/../config.php";
+
+// generate map autoloader map file
+
+/**
+ * Walk on dir to found files
+ * @param $base_dir string Absolute root dir to scanned dir
+ * @return array <string> Relative file path to files found
+ */
+function walk($base_dir) {
+    $scan = scandir($base_dir);
+    $files = array();
+    $blacklisted = array('.', '..', 'class.AutoloaderClassMap.php', 'class.Autoloader.php', 'object');
+
+    foreach($scan as $elem) {
+
+        if (in_array($elem, $blacklisted)) continue;
+
+        if (is_dir($base_dir.'\\'.$elem)) {
+
+            $deeperFiles = walk($base_dir.'\\'.$elem);
+            $deeperFiles = array_reduce( $deeperFiles, function($result, $file) use($elem) {
+                $result [] = $elem.SEPARATOR.$file;
+                return $result;
+            }, array());
+
+            $files = array_merge($files, $deeperFiles);
+
+        }else {
+             $files [] = $elem;
+        }
+
+    }
+    return $files;
+}
+
+/** Check whether file contains some class
+ * @param $filePath string absolute path dir to checked file
+ * @return array <string> Class name found
+ */
+function checkClassExistence($filePath) {
+    $tokens = token_get_all( file_get_contents($filePath) );
+    $class_token = false;
+    $classes = array();
+    foreach ($tokens as $token) {
+        if ( !is_array($token) ) continue;
+        if (in_array($token[0], array(T_CLASS, T_INTERFACE, T_ABSTRACT))) {
+            $class_token = true;
+        } else if ($class_token && $token[0] == T_STRING) {
+            $class_token = false;
+            $classes [] = $token[1];
+        }
+    }
+
+    return $classes;
+}
+
+
+
+$classFilesDiretories[CLASS_DIR] = array( "files" => walk(CLASS_DIR), "dir" => "");
+$classFilesDiretories[API_DIR] = array( "files" => walk(API_DIR), "dir" => "../api");
+
+$handler = fopen(CLASS_DIR.SEPARATOR."class.AutoloaderClassMap.php", "w");
+
+$header = "<?php
+/**
+* This file have been automatically generated by autoloading script
+*/
+
+class AutoloaderClassMap {
+
+    public static \$mapClass = array (
+
+";
+
+$footer = "\t);\n}";
+
+fwrite($handler, $header);
+
+foreach ($classFilesDiretories as $classFilesDiretory => $details) {
+    foreach ($details['files'] as $classFile) {
+        $classes = checkClassExistence( $classFilesDiretory . SEPARATOR . $classFile);
+
+        foreach ($classes as $class) {
+            fwrite($handler, sprintf("\t\t\"%s\" => \"%s\",\n", $class, str_replace('\\', '/', $details['dir'] . SEPARATOR . $classFile)));
+        }
+    }
+}
+
+fwrite($handler, $footer);
+
+fclose($handler);
+
+
+