Skip to content

Commit 56b2093

Browse files
committed
adding support for ArrayFinder
1 parent 0a1b454 commit 56b2093

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

src/PatternLab/Data.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use \PatternLab\Console;
1717
use \PatternLab\Dispatcher;
1818
use \PatternLab\Timer;
19+
use \Shudrum\Component\ArrayFinder\ArrayFinder;
1920
use \Symfony\Component\Finder\Finder;
2021
use \Symfony\Component\Yaml\Exception\ParseException;
2122
use \Symfony\Component\Yaml\Yaml;
@@ -198,6 +199,8 @@ public static function get() {
198199
return self::$store;
199200
}
200201

202+
203+
201204
/**
202205
* Generate the listItems array
203206
* @param {String} the filename for the pattern to be parsed
@@ -274,20 +277,19 @@ public static function getListItems($filepath,$ext = "json") {
274277
return $listItems;
275278

276279
}
277-
280+
278281
/**
279-
* Return the value for an option
282+
* Get an option for the data store
283+
* @param {String} a string in dot notation dictating where the option is in the data structure
280284
*
281-
* @return {String} the value of the option requested
285+
* @return {Array} the store
282286
*/
283-
public static function getOption($optionName) {
284-
285-
if (isset(self::$store[$optionName])) {
286-
return self::$store[$optionName];
287+
public static function getOption($key = "") {
288+
if (!empty($key)) {
289+
$arrayFinder = new ArrayFinder(self::$store);
290+
return $arrayFinder->get($key);
287291
}
288-
289292
return false;
290-
291293
}
292294

293295
/**
@@ -359,7 +361,34 @@ public static function initPattern($optionName) {
359361
public static function printData() {
360362
print_r(self::$store);
361363
}
362-
364+
365+
/**
366+
* Replace the data store
367+
* @param {Array} the new store
368+
*/
369+
public static function replaceStore($store) {
370+
self::$store = $store;
371+
}
372+
373+
/**
374+
* Set an option for the data store
375+
* @param {String} a string in dot notation dictating where the option is in the data structure
376+
* @param {Mixed} the value for the key
377+
*
378+
* @return {Array} the store
379+
*/
380+
public static function setOption($key = "", $value = "") {
381+
382+
if (empty($key)) {
383+
return false;
384+
}
385+
386+
$arrayFinder = new ArrayFinder(self::$store);
387+
$arrayFinder->set($key, $value);
388+
self::$store = $arrayFinder->get();
389+
390+
}
391+
363392
/**
364393
* Set an option on a sub element of the data array
365394
* @param {String} name of the option

0 commit comments

Comments
 (0)