]> git.andy128k.dev Git - ipf.git/commitdiff
use composer and class maps
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 22 Jun 2013 10:37:15 +0000 (13:37 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 22 Jun 2013 10:37:15 +0000 (13:37 +0300)
composer.json
composer.lock
index.php
ipf.php

index c09cfafc1ec46c3864357f014cbd32b01fca2fd8..6983e78b9bb1a683142febde75d53af455419ec5 100644 (file)
       "email": "andy128k@gmail.com"
     }
   ],
+  "autoload": {
+    "classmap" : ["."]
+  },
+  "require": {
+    "andy128k/routeexpression": "dev-master"
+  },
   "require-dev": {
     "phpunit/phpunit": "3.7.*"
-  }
+  },
+  "repositories": [
+    {
+      "type": "composer",
+      "url": "http://packages.andy128k.net/php/"
+    }
+  ]
 }
 
index 576434e94c812d79eb47c62eafc11ac82dfeeab1..adb9fdc9a5c769bb2dd5396e2c324a54008da59b 100644 (file)
@@ -3,9 +3,47 @@
         "This file locks the dependencies of your project to a known state",
         "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
     ],
-    "hash": "1177f075c09daf9849c259a2f3c79236",
+    "hash": "20bffa57e6d8564e8b9bf75a6d2f70af",
     "packages": [
-
+        {
+            "name": "andy128k/routeexpression",
+            "version": "dev-master",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/andy128k/routeexpression.git",
+                "reference": "60f822ca0f7ea50a3bccdd29970d7ee1900c10a8"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/andy128k/routeexpression/zipball/60f822ca0f7ea50a3bccdd29970d7ee1900c10a8",
+                "reference": "60f822ca0f7ea50a3bccdd29970d7ee1900c10a8",
+                "shasum": ""
+            },
+            "require-dev": {
+                "phpunit/phpunit": "3.7.*"
+            },
+            "type": "library",
+            "autoload": {
+                "classmap": [
+                    "src"
+                ]
+            },
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Andrey Kutejko",
+                    "email": "andy128k@gmail.com"
+                }
+            ],
+            "description": "Route expression",
+            "support": {
+                "source": "https://github.com/andy128k/routeexpression/tree/master",
+                "issues": "https://github.com/andy128k/routeexpression/issues"
+            },
+            "time": "2013-06-22 08:01:38"
+        }
     ],
     "packages-dev": [
         {
 
     ],
     "minimum-stability": "stable",
-    "stability-flags": [
-
-    ],
+    "stability-flags": {
+        "andy128k/routeexpression": 20
+    },
     "platform": [
 
     ],
index 93fb5ce66e406332dd0e4ec845d50b88c4c57757..adeedf7ace9c62f0cff7032a84c39a983e26126a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,9 +3,7 @@
 // This is a index stub for a IPF Projects
 
 $here = dirname(__FILE__);
-$ipf_path = $here.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'ipf';
-$project_path = $here.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'project';
-set_include_path(get_include_path() . PATH_SEPARATOR . $ipf_path . PATH_SEPARATOR . $project_path);
-require 'ipf.php';
-return IPF::boot($ipf_path, $project_path, $here) && IPF_Project::getInstance()->run();
+$project_path = $here . '/../project';
+require $project_path . '/vendor/andy128k/ipf/ipf.php';
+return IPF::setUp($project_path, $here) && IPF_Project::getInstance()->run();
 
diff --git a/ipf.php b/ipf.php
index 2edf6c8cc32200389f054ebcf3192d06611955d0..e4c99e0399667a8764a647ab0f4a0ad9e6b33199 100644 (file)
--- a/ipf.php
+++ b/ipf.php
@@ -1,12 +1,5 @@
 <?php
 
-function IPF_Autoload($class_name)
-{
-    require_once strtolower(str_replace('_', '/', $class_name)) . '.php';
-}
-
-spl_autoload_register('IPF_Autoload');
-
 final class IPF
 {
     private static $settings = array();
@@ -112,19 +105,21 @@ final class IPF
         return is_file($path);
     }
 
-    public static function boot($ipf_path, $project_path, $document_root)
+    public static function setUp($project_path, $document_root)
     {
         if (php_sapi_name() === 'cli-server' && IPF::requestedFileExists())
             return false;
 
-        IPF::$settings['ipf_path'] = $ipf_path;
+        IPF_ClassLoader::getInstance($project_path);
+
+        IPF::$settings['ipf_path'] = dirname(__FILE__);
         IPF::$settings['project_path'] = $project_path;
         IPF::$settings['document_root'] = $document_root;
 
         try {
             IPF::loadSettings();
             date_default_timezone_set(IPF::$settings['time_zone']);
-        } catch(IPF_Exception_Settings $e) {
+        } catch (IPF_Exception_Settings $e) {
             die('Setting Error: '.$e->getMessage()."\n");
         }
         return true;
@@ -144,10 +139,10 @@ final class IPF
     {
         if (function_exists($function))
             return;
-        if (preg_match('/^(\w+)::\w+$/', $function, $m)) {
-            IPF_Autoload($m[1]);
-            return;
-        }
+
+        if (preg_match('/^(\w+)::\w+$/', $function, $m))
+            return; // nothing to do. autoloader will load a class.
+
         $elts = explode('_', $function);
         array_pop($elts);
         $file = strtolower(implode(DIRECTORY_SEPARATOR, $elts)).'.php';
@@ -174,6 +169,40 @@ final class IPF
     }
 }
 
+class IPF_ClassLoader
+{
+    private $classMap;
+
+    private static $loader = null;
+
+    public static function getInstance($project_path)
+    {
+        if (self::$loader == null)
+            self::$loader = new IPF_ClassLoader($project_path);
+        return self::$loader;
+    }
+
+    private function __construct($project_path)
+    {
+        $dir = $project_path . '/vendor/composer/';
+
+        $includePaths = require $project_path . '/vendor/composer/include_paths.php';
+        array_push($includePaths, get_include_path());
+        set_include_path(join(PATH_SEPARATOR, $includePaths));
+
+        $this->classMap = require $project_path . '/vendor/composer/autoload_classmap.php';
+
+        spl_autoload_register(array($this, 'load'), true, true);
+    }
+
+    public function load($class)
+    {
+        if (isset($this->classMap[$class])) {
+            include $this->classMap[$class];
+        }
+    }
+}
+
 function __($str)
 {
     $t = trim($str);