isundil 10 gadi atpakaļ
vecāks
revīzija
3a0497101a

+ 5 - 0
core/autoload.php

@@ -1,5 +1,10 @@
 <?php
 
+/**
+ * Load classes from core directories 
+ * @param string $classname Class to load
+ * @return file path loaded
+**/
 function __autoload($className)
 {
     list($namespace, $class) = explode('\\', $className, 2);

+ 1 - 3
core/models/ModelBase.php

@@ -99,7 +99,6 @@ abstract class ModelBase
     {
         \Tools\Hook::trigger("onBeforeEntitySave");
         \Tools\Hook::trigger("onBeforeEntitySave".$this->getTableName());
-        //TODO send pre-hook
         if ($this->id === null)
         {
             if (empty ($this->changed))
@@ -134,7 +133,6 @@ abstract class ModelBase
                 $this->changed = array();
             }
         }
-        //TODO send hook
         \Tools\Hook::trigger("onAfterEntitySave");
         \Tools\Hook::trigger("onAfterEntitySave".$this->getTableName());
     }
@@ -169,7 +167,7 @@ abstract class ModelBase
         return $resultObj;
     }
 
-    //TODO
+    //TODO@1
     public function selectById($id)
     {
     }

+ 1 - 1
core/models/ModuleHook.php

@@ -23,7 +23,7 @@ class ModuleHook extends ModelBase
     public static function getModules($moduleIds)
     {
         $fetcher = new self();
-        //TODO order by
+        //TODO@1 order by
         return $fetcher->selects(array("module_id" => $moduleIds));
     }
 }

+ 48 - 0
core/tools/Context.php

@@ -2,14 +2,59 @@
 
 namespace Tools;
 
+/**
+ * Cms context
+ * Contains all website informations
+ * Will be passed to themes files and to modules
+**/
 class Context
 {
+    /**
+     * @var \Tools\Hooks $hookManager
+     * /core/tools/Hooks.php
+     * allow triggering hooks and registers module's endpoints
+     * Can be accessed read-only via $instance->hookManager
+    **/
     private $hookManager;
+
+    /**
+     * @var \Tools\ModuleManager $moduleManager
+     * /core/tools/ModuleManager.php
+     * load all active modules and contains informations about them
+     * Can be accessed read-only via $instance->moduleManager
+    **/
     private $moduleManager;
+
+    /**
+     * @var \Tools\Router $router
+     * /core/tools/Router.php
+     * Contains information about directories and paths
+     * Allow user to generate links
+     * Can be accessed read-only via $instance->router
+    **/
     private $router;
+
+    /**
+     * TODO
+     * @var \Tools\Cart $cart
+     * /core/tools/Cart.php
+     * Not defined yet
+     * Can be accessed read-only via $instance->cart
+    **/
     private $cart;
+
+    /**
+     * TODO
+     * @var \Tools\User $user (entity ?)
+     * /core/tools/User.php
+     * Can be accessed read-only via $instance->user
+    **/
     private $user;
 
+    /**
+     * Create context from $_SERVER environment
+     * and initialize all data
+    **/
     public function __construct()
     {
         $this->hookManager = new Hooks($this);
@@ -25,6 +70,9 @@ class Context
         $this->router->serveUrl();
     }
 
+    /**
+     * Getter function
+    **/
     public function __get($key)
     {
         switch ($key)

+ 29 - 2
core/tools/Hooks.php

@@ -2,28 +2,55 @@
 
 namespace Tools;
 
+/**
+ * Allow user to manage hooks
+**/
 class Hooks
 {
+    /**
+     * @var \Tools\Context $context
+     * /core/tools/Context.php
+     * Contains website's informations
+    **/
     private $context;
 
+    /**
+     * ctor. Initialize context for having them passed to hook as parameter
+    **/
     public function __construct($context)
     {
         $this->context = $context;
     }
 
+    /**
+     * @param \Tool\AModule $module
+     * @param string $hookname
+     * Attach module $module to $hookName
+     * Can only be called while installing the module.
+     * When fired, the AModule::doAction($hookName, $context) function will be called.
+    **/
     public function register($module, $hookName)
     {
         if (!\Tools\ModuleManager::isInstalling())
             throw new \Exception("You can only register hooks while installing");
-        //TODO
+        //TODO@2
     }
 
+    /**
+     * @param string $hookName
+     * fire the hook hookName
+     * call the AModule::doAction($hookName, $context) function for each attached modules
+    **/
     public function trigger($hookName)
     {
         echo "Triggering hook `{$hookName}'";
-        //TODO
+        //TODO@2
     }
 
+    /**
+     * @param array(\Entity\ModuleHook) $module_hookEntities entities to load
+     * Reload hooks from entities
+    **/
     public function loadHooks($hookEntities)
     {
     }

+ 40 - 2
core/tools/ModuleManager.php

@@ -2,15 +2,37 @@
 
 namespace Tools;
 
+/**
+ * Container all modules.
+ * Allow module managment
+**/
 class ModuleManager
 {
+    /**
+     * @var \Tools\Context $context
+     * /core/tools/Context.php
+     * Contains website's informations
+    **/
     private $context;
+
+    /**
+     * @var array(\Tool\AModule) $modules
+     * /core/tools/AModule.php
+     * Contains all loaded modules
+     * Can be accessed read-only via $instance->modules
+    **/
     private $modules = array();
 
+    /**
+     * @param \Tool\Context $context
+     * Load all active modules from database.
+     * Enable hooks for these modules
+     * Disable them if the module cannot be loaded
+    **/
     public function __construct($context)
     {
         $this->context = $context;
-        $modulesRoot = $context->router->getModulesPath();
+        $modulesRoot = $context->router->modulesPath;
         $modules = \Entity\Module::getActivated();
         $ids = array();
         foreach ($modules as $i)
@@ -29,15 +51,31 @@ class ModuleManager
         \Tools\Hooks::loadHooks(\Entity\ModuleHook::getModules($ids));
     }
 
+    /**
+     * @param string $path path to module's main file
+     * @param \Entity\Module $module module's database object to load
+     * /core/models/Module.php
+     * @return TRUE on success
+     * Will try to load module located at $path.
+     * This function will include the main.php file located in the module's directory
+     * The file MUST return an AModule object to be considered as successfull
+     * /core/tools/AModule.php
+    **/
     private function loadModule($path, $module)
     {
         $this->modules[] = $module;
         return true;
     }
 
+    /*
+     * TODO revoir tout
+     * @return array(AModule)
+     * Will load every modules, and return them.
+    **/
     public function listAvailableModules()
     {
-        $modulesRoot = $context->router->getModulesPath();
+        $modulesRoot = $context->router->modulesPath;
+        $result = array();
         $modules = scandir($modulesRoot, SCANDIR_SORT_NONE);
         foreach ($modules as $i)
         {

+ 53 - 5
core/tools/Router.php

@@ -2,11 +2,34 @@
 
 namespace Tools;
 
+/**
+ * Will manager new connections to the server
+ * and try to match the requests and the controllers
+**/
 class Router
 {
+    /**
+     * @var string $rootPath
+     * Contains the application's root path (ex: http://myshop.com/) with trailing slash
+     * Can be accessed read-only via $instance->rootPath
+    **/
     private $rootPath;
+
+    /**
+     * @var string $rootPath
+     * Contains the application's root path (ex: /srv/http/myshop/) with trailing slash
+     * Can be accessed read-only via $instance->rootUrl
+    **/
     private $rootUrl;
 
+    /**
+     * @var string $modulePath
+     * Contains the module directory
+    **/
+
+    /**
+     * Create the router, initialize url and path
+    **/
     public function __construct()
     {
         $pos = strrpos($_SERVER["SCRIPT_NAME"], "/");
@@ -15,6 +38,11 @@ class Router
         $this->rootUrl = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . $relativePath ."/";
     }
 
+    /**
+     * TODO@1 This function SHOULD be disabled by configuration
+     * Called after database initialization
+     * Check the site url and redirect user if the HOST does not match
+    **/
     public function init()
     {
         $siteUrl = \Entity\Config::getConfig(null, "siteUrl");
@@ -25,18 +53,38 @@ class Router
         }
     }
 
-    public function getModulesPath()
-    { return $this->rootPath . "content/modules/"; }
-
+    /**
+     * @return \Controller\AController controller
+     * /core/controller/AController.php
+     * Match request to a controller
+     * return FALSE on failure (eg. 404)
+    **/
     public function serveUrl()
     {
         $this->prepareUrl();
-        //TODO
+        //TODO@2
     }
 
+    /**
+     * Append local routes to router
+     * Will load CMS pages, categories page, products page, cart pages, etc.
+    **/
     private function prepareUrl()
     {
-        //TODO add internal route config
+        //TODO@2 add internal route config
+    }
+
+    /**
+     * TODO@1 check end of tag to format url and paths
+    **/
+    public function __get($key)
+    {
+        switch ($key)
+        {
+        case "rootPath": return $this->rootPath; break;
+        case "rootUrl": return $this->rootUrl; break;
+        case "modulesPath": return $this->rootPath."content/modules/"; break;
+        }
     }
 }