File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " lovullo/libliza-php" ,
33 "description" : " PHP client for the Liza Data Collection Framework" ,
4- "version" : " 0.7.1 " ,
4+ "version" : " 0.7.2 " ,
55 "type" : " project" ,
66 "keywords" : [ " liza" ],
77 "license" : " GPL-3.0+" ,
Original file line number Diff line number Diff line change @@ -50,6 +50,18 @@ interface Bucket
5050 public function getDataByName ( $ name , $ index = null );
5151
5252
53+ /**
54+ * Return the values associated with the provided regex
55+ *
56+ * @param string $regex regex for key
57+ *
58+ * @return array values associated with the key
59+ *
60+ * @throws \DomainException if requested index does not exist
61+ */
62+ public function getDataByRegEx ( $ regex );
63+
64+
5365 /**
5466 * Whether the given key and (optionally) index exist
5567 *
Original file line number Diff line number Diff line change @@ -61,13 +61,34 @@ public function __construct( array $data )
6161 }
6262
6363
64+ /**
65+ * Return the values associated with the provided regex
66+ *
67+ * @param string $regex regex for key
68+ *
69+ * @return array values associated with the key
70+ */
71+ public function getDataByRegEx ( $ regex )
72+ {
73+ $ data = [];
74+ $ data_keys = preg_grep ( $ regex , array_keys ( $ this ->_data ) );
75+
76+ foreach ( $ data_keys as $ key )
77+ {
78+ $ data [ $ key ] = $ this ->getDataByName ( $ key );
79+ }
80+
81+ return $ data ;
82+ }
83+
84+
6485 /**
6586 * Return the values associated with the provided key
6687 *
6788 * This method accepts an index due to PHP's lack of array dereferencing
6889 * support prior to 5.4.
6990 *
70- * @param string $name name of key
91+ * @param string $name name of key
7192 * @param int $index index to return
7293 *
7394 * @return array values associated with the key
Original file line number Diff line number Diff line change @@ -75,6 +75,23 @@ public function testCanRetrieveBucketDataByName()
7575 }
7676
7777
78+ /**
79+ * The bucket data should be retrievable by the RegEx, so long as
80+ * it exists.
81+ */
82+ public function testGetDataByRegEx ()
83+ {
84+ $ key = '_foo ' ;
85+ $ result = $ this ->getSut ( $ this ->_initialData )->getDataByRegEx ( '/ ' . $ key .'/ ' );
86+ $ this ->assertEquals (
87+ $ this ->_initialData [ $ key ],
88+ $ result [ $ key ],
89+ 'Bucket should return the value identified by a given name '
90+ );
91+ }
92+
93+
94+
7895 /**
7996 * PHP < 5.4's lack of array dereferencing support can be rather
8097 * frustrating. As such, getDataByName() should also accept an index to
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ protected function getDummyBucket()
3232 return $ this ->getMockBuilder (
3333 "Lovullo\Liza\Bucket\Bucket "
3434 )
35- ->setMethods ( array ( "getDataByName " , "hasData " ) )
35+ ->setMethods ( array ( "getDataByName " , "hasData " , " getDataByRegEx " ) )
3636 ->getMock ();
3737 }
3838
You can’t perform that action at this time.
0 commit comments