Exemplo n.º 1
0
 /**
  * Decode from format 
  *
  * @method decode
  * @param {String} $datastore context identifier
  * @void
  */
 public static function Decode(Resource $resource)
 {
     // TODO: «non-silly-impl»
     // lazy lib work around
     $data = array();
     $tmpfilename = time() . ".tmp.csv";
     file_put_contents($tmpfilename, $resource->content());
     // setup lexer
     $lexer = new Lexer(new LexerConfig());
     $interpreter = new Interpreter();
     // do nothing
     $interpreter->addObserver(function (array $row) use(&$data) {
         $data[] = $row;
     });
     // process file
     $lexer->parse($tmpfilename, $interpreter);
     // cleanup
     unlink($tmpfilename);
     return $data;
 }
Exemplo n.º 2
0
 /**
  * Decode from format 
  *
  * @method decode
  * @param {String} $datastore context identifier
  * @void
  */
 public static function Decode(Resource $resource)
 {
     return unserialize($resource->content());
 }
Exemplo n.º 3
0
 /**
  * Decode from format 
  *
  * @method decode
  * @param {String} $datastore context identifier
  * @void
  */
 public static function Decode(Resource $resource)
 {
     return MarkdownDecoder::defaultTransform($resource->content());
 }
Exemplo n.º 4
0
 /**
  * Decode from format 
  *
  * @method decode
  * @param {String} $datastore context identifier
  * @void
  */
 public static function Decode(Resource $resource)
 {
     return json_decode($resource->content());
 }
Exemplo n.º 5
0
 /**
  * Encode to format
  *
  * @method encode
  * @param {String} $datastore context identifier
  * @void
  */
 public static function Encode(Resource $resource)
 {
     return str_replace(array("\n", "\t", "   ", "   ", "  "), "", "\n      (function (root, factory) {\n        if (typeof define === 'function' && define.amd) {\n          define(factory);\n        } else {\n          root.CommonJs = factory();\n        }\n      }(this, function () {\n        return " . json_encode($resource->data()) . ";\n      }));\n    ");
 }
Exemplo n.º 6
0
 /**
  * Persist data static
  * 
  * @method persistToDisk
  * @param {String} filepath
  * @param {String} contents
  * @void
  */
 public static function persistToDisk(Resource $file)
 {
     // update datastore * perf *
     return file_put_contents($file->path(), $file->content());
 }
Exemplo n.º 7
0
 /**
  * Find resource (currently just: UUID - TODO: enhance signature w/UUID as default / Widespread Merge ?!)
  *
  * @method find
  * @return {Array} List of item instances
  */
 public function find(Resource $resource)
 {
     $instance = $resource->data();
     if (!isset($instance[Store::ENTITY_IDENTIFIER])) {
         return false;
     }
     $this->items = (array) $this->items;
     foreach ($this->items as $index => $resource) {
         $resource = (array) $resource;
         if ($resource[Store::ENTITY_IDENTIFIER] === $instance[Store::ENTITY_IDENTIFIER]) {
             return $index;
         }
     }
     return false;
 }