developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #1075: ticket_1075_doctrine_support.2.diff

File ticket_1075_doctrine_support.2.diff, 7.2 KB (added by foxmask, 10 years ago)

Support Doctrine ; avec un plugin coord en plus pour eviter de toucher a application.ini.php (typos fix)

  • build/manifests/jelix-no-opt.mn

    diff -r 7f81086f0d97 build/manifests/jelix-no-opt.mn
    a b  
    1010  jContext.class.php
    1111* jController.class.php
    1212* jCoordinator.class.php
     13  jDoctrine.class.php
    1314  jErrorHandler.lib.php
    1415  jException.lib.php
    1516* jIncluder.class.php
     
    2728* jSelectorActFast.class.php
    2829* jSelectorClass.class.php
    2930  jSelectorDao.class.php
     31  jSelectorDoctrine.class.php
    3032  jSelectorFile.lib.php
    3133  jSelectorForm.class.php
    3234  jSelectorIface.class.php
  • lib/jelix/CREDITS

    diff -r 7f81086f0d97 lib/jelix/CREDITS
    a b  
    1818 - tpl plugin hook (#1019)
    1919 - tpl plugin gravatar (#993)
    2020 - meta supplementaires (author,generator) (#1063)
     21 - jDoctrine and jSelectorDoctrine (#1075)
    2122
    2223Mickaël Fradin (aka mike/kewix)
    2324 - improvements in the jtpl plugin: formcontrols (#223)
  • new file lib/jelix/core/jDoctrine.class.php

    diff -r 7f81086f0d97 lib/jelix/core/jDoctrine.class.php
    - +  
     1<?php
     2/**
     3* @package    jelix
     4* @subpackage doctrine
     5* @author     Laurent Jouanneau
     6* @contributor Olivier Demah
     7* @copyright   2010 Olivier Demah
     8* @link        http://www.jelix.org
     9* @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
     10*/
     11
     12/**
     13 * Factory to get the expected Table
     14 * @package  jelix
     15 * @subpackage doctrine
     16 */
     17class jDoctrine {
     18    /**
     19    *
     20    */
     21    public static function get ($DoctrineId, $profile='') {
     22        global $gJConfig, $gJCoord;
     23        static $_doctrineSingleton = array();
     24
     25        if (file_exists($gJCoord->plugins['doctrine']->config['doctrineLibPath']))
     26            require_once ($gJCoord->plugins['doctrine']->config['doctrineLibPath'].'/Doctrine.php');
     27        else
     28            jException('you should have a look to the doctrine Coord plugin config');
     29
     30        $sel = new jSelectorDoctrine($DoctrineId, $profile);
     31        $DoctrineId = $sel->toString ();
     32
     33        if (! isset ($_doctrineSingleton[$DoctrineId])){
     34            $db = jIniFile::read(JELIX_APP_CONFIG_PATH.$gJConfig->dbProfils);
     35            $_doctrineSingleton[$DoctrineId] = Doctrine_Manager::connection($db[$db['default']]['driver'].'://'.$db[$db['default']]['user'].':'.$db[$db['default']]['password'].'@'.$db[$db['default']]['host'].'/'.$db[$db['default']]['database']);
     36        }
     37        else {
     38            Doctrine_Manager::connection();
     39        }
     40        Doctrine_Core::loadModels(dirname($sel->getPath()));
     41        // $sel->resource is the name of the Model to get
     42        return Doctrine_Core::getTable($sel->resource);
     43    }
     44}
  • new file lib/jelix/core/selector/jSelectorDoctrine.class.php

    diff -r 7f81086f0d97 lib/jelix/core/selector/jSelectorDoctrine.class.php
    - +  
     1<?php
     2/**
     3* see jISelector.iface.php for documentation about selectors.
     4* @package     jelix
     5* @subpackage  core_selector
     6* @author      Laurent Jouanneau
     7* @contributor Olivier Demah
     8* @copyright   2010 Olivier Demah
     9* @link        http://www.jelix.org
     10* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
     11*/
     12
     13/**
     14 * Selector for Doctrine models file
     15 * syntax : "module~modelName".
     16 * file : models/model.php
     17 * @package    jelix
     18 * @subpackage core_selector
     19 */
     20class jSelectorDoctrine extends jSelectorModule {
     21    protected $type = 'models';
     22    public $driver;
     23    protected $_dirname = 'models/';
     24    protected $_suffix = '.php';
     25    protected $_where;
     26
     27    function __construct($sel, $driver, $isprofile=true){
     28        parent::__construct($sel);
     29    }
     30
     31}
  • lib/jelix/init.php

    diff -r 7f81086f0d97 lib/jelix/init.php
    a b  
    135135require (JELIX_LIB_CORE_PATH . 'selector/jSelectorZone.class.php');
    136136require (JELIX_LIB_CORE_PATH . 'selector/jSelectorSimpleFile.class.php');
    137137require (JELIX_LIB_CORE_PATH . 'selector/jSelectorFile.lib.php');
     138require (JELIX_LIB_CORE_PATH . 'selector/jSelectorDoctrine.class.php');
    138139require (JELIX_LIB_CORE_PATH . 'jUrlBase.class.php');
    139140require (JELIX_LIB_CORE_PATH . 'jUrlAction.class.php');
    140141require (JELIX_LIB_CORE_PATH . 'jUrl.class.php');
     
    146147require (JELIX_LIB_CORE_PATH . 'jLocale.class.php');
    147148require (JELIX_LIB_CORE_PATH . 'jIncluder.class.php');
    148149require (JELIX_LIB_CORE_PATH . 'jSession.class.php');
     150require (JELIX_LIB_CORE_PATH . 'jDoctrine.class.php');
    149151#endif
    150152
    151153/**
  • new file lib/jelix/plugins/coord/doctrine/doctrine.coord.ini.php

    diff -r 7f81086f0d97 lib/jelix/plugins/coord/doctrine/doctrine.coord.ini.php
    - +  
     1;<?php die('');?>
     2; for security reasons, don't remove or modify the first line
     3
     4; edit the realpath to the library directory of the doctrine framework
     5doctrineLibPath = "/path/to/doctrine"
  • new file lib/jelix/plugins/coord/doctrine/doctrine.coord.php

    diff -r 7f81086f0d97 lib/jelix/plugins/coord/doctrine/doctrine.coord.php
    - +  
     1<?php
     2/**
     3* @package      jelix
     4* @subpackage   coord_plugin
     5* @author       Olivier Demah
     6* @copyright    2010 Olivier Demah
     7* @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
     8*/
     9
     10/**
     11* Jelix plugin to use the Dotrine Framework library
     12*
     13* In order not to load Zend at each action, you need to explicitely activate it !
     14*
     15* Use the $pluginParams property of the controller
     16* Example : public $pluginParams = array('index' => array('doctrine.active' => true));
     17*/
     18class doctrineCoordPlugin implements jICoordPlugin {
     19   
     20    public $config;
     21   
     22    /**
     23    * @param array $config list of configuration parameters
     24    */
     25    public function __construct($config) {
     26        $this->config = $config;
     27    }
     28
     29    /**
     30    * Autoload the Doctrine library directory
     31    * Include the Doctrine Manager class to enable the use of Doctrine_*::* class
     32    */
     33    public function beforeAction($params) {
     34        if (isset($params['doctrine.active']) && $params['doctrine.active'] == 'true') {
     35            require_once ($this->config['doctrineLibPath'].'/Doctrine.php');
     36            spl_autoload_register(array('Doctrine', 'autoload'));
     37            $manager = Doctrine_Manager::getInstance();
     38            spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
     39            $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
     40        }
     41        return null;
     42    }
     43
     44    public function beforeOutput() {}
     45    public function afterProcess() {}
     46}
     47
  • new file lib/jelix/plugins/coord/doctrine/plugin.xml

    diff -r 7f81086f0d97 lib/jelix/plugins/coord/doctrine/plugin.xml
    - +  
     1<?xml version="1.0" encoding="iso-8859-1"?>
     2<plugin name="doctrine" xmlns="http://jelix.org/ns/plugin/1.0">
     3</plugin>