Ticket #523: bindings.diff
| File bindings.diff, 5.2 kB (added by doubleface, 2 years ago) |
|---|
-
build/manifests/jelix-lib.mn
265 265 cd lib/jelix/utils/ 266 266 jAppManager.class.php 267 267 jClasses.class.php 268 jBinding.class.php 268 269 jCmdUtils.class.php 269 270 jCrypt.class.php 270 271 jDatatype.class.php -
build/manifests/testapp.mn
1 1 cd testapp 2 2 3 project.xml 3 4 .htaccess 4 5 application.init.php … … 81 82 cd testapp/modules/jelix_tests/classes/tests 82 83 foo.class.php 83 84 foo.iface.php 85 bind.class.php 84 86 cd testapp/modules/jelix_tests/locales/ 85 87 test_A.properties 86 88 test_B.properties … … 163 165 utils.jlog.html_cli.php 164 166 utils.jdatetime.html_cli.php 165 167 utils.jinifilemodifier.html_cli.php 168 utils.jclasses.html_cli.php 166 169 167 170 cd testapp/var 168 171 .htaccess -
testapp/modules/jelix_tests/classes/tests/foo.iface.php
1 1 <?php 2 2 3 3 interface foo { 4 4 const JBINDING_BINDED_IMPLEMENTATION = 'jelix_tests~tests/bind'; 5 5 } 6 6 7 ?> 8 Pas de fin de ligne à la fin du fichier 7 ?> -
lib/jelix/core/jSelector.class.php
34 34 * @param string $selstr the selector. It should be a full selector : "type:module~resource" (not "module~resource") 35 35 * @return jISelector the corresponding selector 36 36 */ 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 38 42 if(preg_match("/^([a-z]{3,5})\:([\w~\/\.]+)$/", $selstr, $m)){ 39 43 $cname='jSelector'.$m[1]; 40 44 if(class_exists($cname)){ … … 412 416 } 413 417 414 418 /** 415 * selector for business class419 * selector for interface 416 420 * 417 * business class is a class stored in classname.class.php file in the classes/ module directory421 * interface is stored in interfacename.iface.php file in the classes/ module directory 418 422 * or one of its subdirectory. 419 * syntax : " module~classname" or "module~classname.423 * syntax : "iface:module~ifacename" or "module~ifacename. 420 424 * @package jelix 421 425 * @subpackage core_selector 422 426 * @since 1.0b2 423 427 */ 424 class jSelectorI nterface extends jSelectorClass {428 class jSelectorIface extends jSelectorClass { 425 429 protected $type = 'iface'; 426 430 protected $_dirname = 'classes/'; 427 431 protected $_suffix = '.iface.php'; 428 432 } 429 433 430 434 /** 435 * selector for interface 436 * @package jelix 437 * @subpackage core_selector 438 * @since 1.0b2 439 * @deprecated 440 */ 441 class jSelectorInterface extends jSelectorIface {} 442 443 /** 431 444 * selector for localisation string 432 445 * 433 446 * localisation string are stored in file properties. -
lib/jelix/utils/jClasses.class.php
19 19 20 20 static protected $_instances = array(); 21 21 22 static protected $_bindings = array(); 23 22 24 private function __construct(){} 23 25 24 26 /** … … 60 62 } 61 63 62 64 /** 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 /** 63 114 * only include a class 64 115 * @param string $selector the jelix selector correponding to the class 65 116 */
