Пример #1
0
 /**
  * Generates a unique ID in GUID format
  *
  * @param string $seed Random noise to seed the hash
  *
  * @return string A unique GUID
  */
 public static function generate($seed)
 {
     static $_guid = null;
     $_uuid = uniqid(null, true);
     $_data = $seed . microtime(true) . JsonFile::encode(isset($_SERVER) ? $_SERVER : [microtime(true)]);
     $_hash = strtoupper(hash('ripemd128', $_uuid . $_guid . md5($_data)));
     return $_guid = substr($_hash, 0, 8) . '-' . substr($_hash, 8, 4) . '-' . substr($_hash, 12, 4) . '-' . substr($_hash, 16, 4) . '-' . substr($_hash, 20, 12);
 }
Пример #2
0
 /**
  * @param string $template  A Blade template read into a string
  * @param array  $data      The data to render
  * @param array  $mergeData Data to merge with the existing view data
  *
  * @return mixed|string
  */
 public function makeFromString($template, $data = [], $mergeData = [])
 {
     $_json = false;
     $_workTemplate = $template;
     !is_string($_workTemplate) && ($_workTemplate = JsonFile::encode($_workTemplate)) && ($_json = true);
     /** @type \Wpb\StringBladeCompiler\StringView $_view */
     /** @noinspection PhpUndefinedMethodInspection */
     $_view = StringView::make(['template' => $_workTemplate, 'cache_key' => md5(array_get($data, 'cache_key', microtime(true)) . sha1($_workTemplate)), 'updated_at' => time()], $data, $mergeData);
     $_workTemplate = $_view->render();
     return $_json ? JsonFile::decode($_workTemplate, true) : $_workTemplate;
 }
Пример #3
0
 /**
  * @param string $filename The name of the file relative to /database/dfe/
  * @param mixed  $contents
  * @param bool   $jsonEncode
  *
  * @return bool
  */
 protected function _writeFile($filename, $contents, $jsonEncode = false)
 {
     $_path = base_path() . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'dfe';
     if (!Disk::ensurePath($_path)) {
         $this->writeln('Unable to write to backup path <comment>' . $_path . '</comment>. Aborting.', 'error');
         return false;
     }
     return false !== file_put_contents($_path . DIRECTORY_SEPARATOR . ltrim($filename, DIRECTORY_SEPARATOR), $jsonEncode ? JsonFile::encode($contents) : $contents);
 }
Пример #4
0
 /**
  * Convert the object to its JSON representation.
  *
  * @param  int $options
  *
  * @return string
  */
 public function toJson($options = JsonFile::DEFAULT_JSON_ENCODE_OPTIONS)
 {
     return JsonFile::encode($this->_contents, $options);
 }
Пример #5
0
 /**
  * @return string
  */
 public function __toString()
 {
     return JsonFile::encode($this->toArray());
 }