Esempio n. 1
0
 /**
  * @param	Huxtable\Core\FileInfo	$file
  * @return	self	For chaining
  */
 public function returnFileContents(FileInfo $sourceFile)
 {
     $this->sourceFile = $sourceFile;
     $closure = function () {
         return $this->sourceFile->getContents();
     };
     $this->closure = $closure->bindTo($this);
     return $this;
 }
Esempio n. 2
0
 /**
  * @param	Huxtable\Core\FileInfo	$fileInfo
  */
 public function __construct(FileInfo $fileInfo)
 {
     $this->source = $fileInfo;
     // Defaults
     $defaultMeta = ['nextId' => 1, 'uniqueKeys' => [], 'foreignKeys' => []];
     if ($this->source->isFile()) {
         $json = $this->source->getContents();
         $contents = json_decode($json, true);
         if (json_last_error() != JSON_ERROR_NONE) {
             // @todo	Error handling
         }
         if (isset($contents['records'])) {
             $this->records = $contents['records'];
         }
         if (isset($contents['meta'])) {
             $this->meta = $contents['meta'];
         } else {
             $this->meta = $defaultMeta;
         }
     } else {
         $this->meta = $defaultMeta;
     }
 }