API Docs for: 1.0.1
Show:

File: src/server/php/Store/Format/CommonJs.php

  1. <?php namespace Store\Format;
  2.  
  3. use Store\Format;
  4. use Store\Resource;
  5.  
  6. /**
  7. * Json Formatted Contents
  8. *
  9. * @class CommonJs
  10. * @module Server
  11. */
  12. class CommonJs implements Format {
  13.  
  14. /**
  15. * File extension
  16. * @property FILE_EXTENSION
  17. * @const
  18. * @type {String}
  19. */
  20. const FILE_EXTENSION = 'cjs';
  21. /**
  22. * Encode to format
  23. *
  24. * @method encode
  25. * @param {String} $datastore context identifier
  26. * @void
  27. */
  28. public static function Encode(Resource $resource){
  29. return str_replace(array("\n", "\t", " ", " ", " "), "","
  30. (function (root, factory) {
  31. if (typeof define === 'function' && define.amd) {
  32. define(factory);
  33. } else {
  34. root.CommonJs = factory();
  35. }
  36. }(this, function () {
  37. return ".json_encode($resource->data()).";
  38. }));
  39. ");
  40. }
  41.  
  42. /**
  43. * Decode from format
  44. *
  45. * @method decode
  46. * @param {String} $datastore context identifier
  47. * @void
  48. */
  49. public static function Decode(Resource $resource){
  50. throw new Error('Decoding not supported.');
  51. }
  52. }