Esempio n. 1
0
 public function testStore()
 {
     Repository::store('items', 'item', 'value');
     $config = Config::item('item');
     $this->assertInternalType('string', $config);
     $this->assertEquals('value', $config);
 }
Esempio n. 2
0
 /**
  * @covers Repository
  */
 public function testRepository()
 {
     Repository::store('data', 'str', 'value');
     $stored = Repository::retrieve('data', 'str');
     $this->assertInternalType('string', $stored);
     $this->assertEquals('value', $stored);
     Repository::store('data', 'arr', ['key' => 'value']);
     $stored = Repository::retrieve('data', 'arr');
     $this->assertInternalType('array', $stored);
     $this->assertArrayHasKey('key', $stored);
     $this->assertEquals('value', $stored['key']);
     Repository::store('data', 'bool', true);
     $stored = Repository::retrieve('data', 'bool');
     $this->assertInternalType('bool', $stored);
     $this->assertTrue($stored);
 }
Esempio n. 3
0
 /**
  * Loads a config file.
  *
  * @param  string  $path   Path to the config.
  * @param  string  $group  The items group.
  * @return bool            Successfully loaded.
  */
 public static function file(string $path, string $group = 'items')
 {
     // Check that the file exists before we attempt to load it.
     if (file_exists($path)) {
         // Get items from the file.
         $items = (include $path);
         // Items must be an array.
         if (is_array($items)) {
             // Store items.
             foreach ($items as $key => $value) {
                 Repository::store($group, $key, $value);
             }
             // Successful file load.
             return true;
         } else {
             throw new Exception(sprintf('Config file <strong>%s</strong> is not a valid array.', $path));
         }
     } else {
         throw new Exception(sprintf('Cannot load config from file, file <strong>%s</strong> does not exist.', $path));
     }
     // File load unsuccessful.
     return false;
 }