Ticket #523: bindings.diff

File bindings.diff, 5.2 kB (added by doubleface, 2 years ago)
  • build/manifests/jelix-lib.mn

     
    265265cd lib/jelix/utils/ 
    266266  jAppManager.class.php 
    267267  jClasses.class.php 
     268  jBinding.class.php 
    268269  jCmdUtils.class.php 
    269270  jCrypt.class.php 
    270271  jDatatype.class.php 
  • build/manifests/testapp.mn

     
    11cd testapp 
     2 
    23  project.xml 
    34  .htaccess 
    45  application.init.php 
     
    8182cd testapp/modules/jelix_tests/classes/tests 
    8283  foo.class.php 
    8384  foo.iface.php 
     85  bind.class.php 
    8486cd testapp/modules/jelix_tests/locales/ 
    8587  test_A.properties 
    8688  test_B.properties 
     
    163165  utils.jlog.html_cli.php 
    164166  utils.jdatetime.html_cli.php 
    165167  utils.jinifilemodifier.html_cli.php 
     168  utils.jclasses.html_cli.php 
    166169 
    167170cd testapp/var 
    168171  .htaccess 
  • testapp/modules/jelix_tests/classes/tests/foo.iface.php

     
    11<?php 
    22 
    33interface foo { 
    4  
     4    const JBINDING_BINDED_IMPLEMENTATION = 'jelix_tests~tests/bind'; 
    55} 
    66 
    7 ?> 
    8  Pas de fin de ligne à la fin du fichier 
     7?> 
  • lib/jelix/core/jSelector.class.php

     
    3434     * @param string $selstr  the selector. It should be a full selector : "type:module~resource" (not "module~resource") 
    3535     * @return jISelector the corresponding selector 
    3636     */ 
    37     static public function create ($selstr){ 
     37    static public function create ($selstr, $defaulttype=false){ 
     38        if (is_string($defaulttype) && strpos($selstr, ':') === false) { 
     39            $selstr = "$defaulttype:$selstr"; 
     40        } 
     41 
    3842        if(preg_match("/^([a-z]{3,5})\:([\w~\/\.]+)$/", $selstr, $m)){ 
    3943            $cname='jSelector'.$m[1]; 
    4044            if(class_exists($cname)){ 
     
    412416} 
    413417 
    414418/** 
    415  * selector for business class 
     419 * selector for interface  
    416420 * 
    417  * business class is a class stored in classname.class.php file in the classes/ module directory 
     421 * interface is stored in interfacename.iface.php file in the classes/ module directory 
    418422 * or one of its subdirectory. 
    419  * syntax : "module~classname" or "module~classname. 
     423 * syntax : "iface:module~ifacename" or "module~ifacename. 
    420424 * @package    jelix 
    421425 * @subpackage core_selector 
    422426 * @since 1.0b2 
    423427 */ 
    424 class jSelectorInterface extends jSelectorClass { 
     428class jSelectorIface extends jSelectorClass { 
    425429    protected $type = 'iface'; 
    426430    protected $_dirname = 'classes/'; 
    427431    protected $_suffix = '.iface.php'; 
    428432} 
    429433 
    430434/** 
     435 * selector for interface  
     436 * @package    jelix 
     437 * @subpackage core_selector 
     438 * @since 1.0b2 
     439 * @deprecated  
     440 */ 
     441class jSelectorInterface extends jSelectorIface {} 
     442 
     443/** 
    431444 * selector for localisation string 
    432445 * 
    433446 * localisation string are stored in file properties. 
  • lib/jelix/utils/jClasses.class.php

     
    1919 
    2020    static protected $_instances = array(); 
    2121 
     22    static protected $_bindings = array(); 
     23 
    2224    private function __construct(){} 
    2325 
    2426    /** 
     
    6062    } 
    6163 
    6264    /** 
     65     * Shortcut to corresponding jBinding::getInstance()  
     66     *  
     67     * @param string $selector  Selector to a bindable class|interface 
     68     * @return mixed            Corresponding instance 
     69     */ 
     70    static public function getBindedService($selector){ 
     71        return self::getBinding($selector)->getInstance(); 
     72    } 
     73 
     74    /** 
     75     * Alias of self::getBinding method. Better for use like this : jClasses::bind('selector').to('classselector') 
     76     *  
     77     * @param  string $selector  
     78     * @return jBinding 
     79     * @see jClasses::bind 
     80     */ 
     81    static public function bind($selector) { 
     82        return self::getBinding($selector); 
     83    } 
     84 
     85    /** 
     86     * Get the binding corresponding to the specified selector. 
     87     * Better for use like this : jClasses::getBinding($selector)->getClassName() 
     88     *  
     89     * @param string $selector  
     90     * @return jBinding 
     91     * @see jClasses::bind 
     92     */ 
     93    static public function getBinding($selector) { 
     94        $osel = jSelectorFactory::create($selector, 'iface'); 
     95        $s    = $osel->toString(true); 
     96 
     97        if (!isset(self::$_bindings[$s])) { 
     98            self::$_bindings[$s] = new jBinding($osel); 
     99        } 
     100 
     101        return self::$_bindings[$s]; 
     102    } 
     103 
     104    /** 
     105     * Reset the defined bindings (should only use it for unit tests) 
     106     *  
     107     * @return void 
     108     */ 
     109    static public function resetBindings() { 
     110        self::$_bindings = array(); 
     111    } 
     112 
     113    /** 
    63114     * only include a class 
    64115     * @param string $selector the jelix selector correponding to the class 
    65116     */