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.diff

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

Support Doctrine

  • build/manifests/jelix-lib.mn

    diff -r b54f2024d817 build/manifests/jelix-lib.mn
    a b  
    320320  plugin.xml
    321321  history.coord.ini.php.dist
    322322
     323cd lib/jelix/plugins/coord/doctrine
     324  doctrine.coord.ini.php.dist
     325  doctrine.coord.php
     326  jDoctrine.class.php
     327  jSelectorDoctrine.class.php 
     328  plugin.xml
     329 
    323330cd lib/jelix/plugins/db/intuition
    324331  intuition.dbconnection.php
    325332  intuition.dbresultset.php
  • lib/jelix/CREDITS

    diff -r b54f2024d817 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/plugins/coord/doctrine/doctrine.coord.ini.php.dist

    diff -r b54f2024d817 lib/jelix/plugins/coord/doctrine/doctrine.coord.ini.php.dist
    - +  
     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"
     6; put here the connectionName used when you generate yours Doctrine Models :
     7doctrineConnectionName = "myDoctrineConnection"
  • new file lib/jelix/plugins/coord/doctrine/doctrine.coord.php

    diff -r b54f2024d817 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 Doctrine 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    public $config;
     20    /**
     21    * @param array $config list of configuration parameters
     22    */
     23    public function __construct($config) {
     24        $this->config = $config;
     25    }
     26    /**
     27    * Autoload the Doctrine library directory
     28    * Include the Doctrine Manager class to enable the use of Doctrine_*::* classes
     29    **/
     30    public function beforeAction($params) {
     31        if (isset($params['doctrine.active']) && $params['doctrine.active'] == 'true') {
     32
     33            if (! file_exists($this->config['doctrineLibPath'].'/Doctrine.php'))
     34                throw new Exception('you should have a look to the doctrine Coord plugin config, because, I do not find the Doctrine.php bootstrap file');
     35
     36            require_once ($this->config['doctrineLibPath'].'/Doctrine.php');
     37
     38            spl_autoload_register(array('Doctrine', 'autoload'));
     39            $manager = Doctrine_Manager::getInstance();
     40            spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
     41            $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
     42
     43            require_once dirname(__FILE__).'/jSelectorDoctrine.class.php';
     44            require_once dirname(__FILE__).'/jDoctrine.class.php';
     45
     46        }
     47        return null;
     48    }
     49    public function beforeOutput() {}
     50    public function afterProcess() {}
     51}
  • new file lib/jelix/plugins/coord/doctrine/jDoctrine.class.php

    diff -r b54f2024d817 lib/jelix/plugins/coord/doctrine/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 * Doctrine Factory to get the expected Table and retreave the needed records
     14 * @package  jelix
     15 * @subpackage doctrine
     16 */
     17class jDoctrine {
     18    public static function get ($DoctrineId, $profile='') {
     19        global $gJConfig, $gJCoord;
     20        static $_doctrineSingleton = array();
     21
     22        $sel = new jSelectorDoctrine($DoctrineId, $profile);
     23
     24        $DoctrineId = $sel->toString ();
     25        /* create a Doctrine connection */
     26        if (! isset ($_doctrineSingleton[$DoctrineId])){
     27            $p = jDb::getProfile($profile);
     28            /**
     29             * Below, the second parm of Doctrine_Manager::connection
     30             * is the "connection name" here set to jelix as default.
     31             * when generating the classes with Doctrine this will give the line
     32             * for example :
     33             * Doctrine_Manager::getInstance()->bindComponent('Authors', 'jelix');
     34             * in the file doctrineModels/generated/BaseAuthors.php
     35             **/
     36            $connStr  = $p['driver'].'://'.$p['user'].':'.$p['password'].'@'.$p['host'].'/'.$p['database'];
     37            $connName = $gJCoord->plugins['doctrine']->config['doctrineConnectionName'];
     38
     39            $_doctrineSingleton[$DoctrineId] = Doctrine_Manager::connection($connStr , $connName);
     40        }
     41        /* use an existing Doctrine connection */
     42        else {
     43            Doctrine_Manager::connection();
     44        }
     45        //load the Models from the given path $sel->path()
     46        Doctrine_Core::loadModels(dirname($sel->getPath()));
     47        // $sel->resource is the name of the Model to get
     48        return Doctrine_Core::getTable($sel->resource);
     49    }
     50}
  • new file lib/jelix/plugins/coord/doctrine/jSelectorDoctrine.class.php

    diff -r b54f2024d817 lib/jelix/plugins/coord/doctrine/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 : doctrineModels/model.php
     17 * @package    jelix
     18 * @subpackage core_selector
     19 */
     20class jSelectorDoctrine extends jSelectorModule {
     21    protected $type = 'models';
     22    public $driver;
     23    protected $_dirname = 'doctrineModels/';
     24    protected $_suffix = '.php';
     25    protected $_where;
     26
     27    function __construct($sel, $driver, $isprofile=true){
     28        parent::__construct($sel);
     29    }
     30
     31}
  • new file lib/jelix/plugins/coord/doctrine/plugin.xml

    diff -r b54f2024d817 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    <info id="doctrine@jelix.org" name="doctrine" createdate="2010-03-29">
     4        <version stability="alpha" date="2010-03-29">0.0.1</version>
     5        <label lang="en_EN">doctrine</label>
     6        <description lang="en_EN">Coord plugin to be able to use Doctrine Framework inside a Jelix application</description>
     7        <label lang="fr_FR">doctrine</label>
     8        <description lang="fr_FR">Plugin Coord pour permettre d'utiliser le Framework Doctrine zu drin d'une application Jelix</description>
     9        <licence URL="http://www.gnu.org/licenses/gpl.html">GNU General Public Licence</licence>
     10        <copyright>2010 FoxMaSk</copyright>
     11        <creator name="FoxMaSk" email="foxmask@foxmask.info" active="true" />
     12        <homepageURL>http://www.jelix.org/</homepageURL>
     13        <updateURL></updateURL>
     14    </info>
     15    <dependencies>
     16        <jelix minversion="1.1.5" maxversion="1.2.0" />
     17    </dependencies>
     18</plugin>