PHP utility collection with hybrid and fluent APIs.

⌈⌋ branch:  hybrid7 libraries


Check-in [ef20a08626]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Array key traversion. (No idea why I kept this here, not related to the rest of h7.)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ef20a08626148b53fea115994b97bfc3d4da736d
User & Date: mario 2014-12-28 16:30:13
Context
2014-12-28
16:31
Obsolete. db() is just used as plain PDO wrapper anyway. check-in: e6637f6024 user: mario tags: trunk
16:30
Array key traversion. (No idea why I kept this here, not related to the rest of h7.) check-in: ef20a08626 user: mario tags: trunk
16:24
Fix template() description. State: incomplete. (Had a slightly more clever version lounging around somewhere..) check-in: 39a0feb20f user: mario tags: trunk
Changes

Changes to tree.php.

1




2

3




4
5
6







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?











/*hybrid*/ function tree($array) {
  return new tree($array);
}







class tree extends ArrayObject{
  function __construct($array) {
    ArrayObject::__construct($array);
  }
  function __get($route) {
    $r = $this;
    foreach (explode(",", $route) as $i){
      $r = $r[$i];
#      print $i;
    }
    return $r;
  }
}


print tree(array(0,1,2,3=>array(3,4)))->{"3,1"};
|
>
>
>
>
|
>
|
>
>
>
>
|


>
>
>
>
>
>
>






|

<





<
<
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35


<?php
/**
 * type: example
 * state: unused
 * description: Array wrapper for compact index/path traversion
 *
 * print tree([ 0, 1, 2, 3 => [3, 4] ]) -> {"3,1"};
 *
 */


/* @hybrid */
function tree($array) {
  return new tree($array);
}

/**
 * Permits ->{"index,index"} traversion of array trees.
 *
 * @ArrayInterface
 *
 */
class tree extends ArrayObject{
  function __construct($array) {
    ArrayObject::__construct($array);
  }
  function __get($route) {
    $r = $this;
    foreach (str_getcsv($route) as $i){
      $r = $r[$i];

    }
    return $r;
  }
}