Пример #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
 /**
  * Locate and load the cluster manifest
  *
  * @throws \DreamFactory\Managed\Exceptions\ManagedEnvironmentException
  */
 protected function load()
 {
     if (false === ($_file = $this->locateClusterEnvironmentFile())) {
         throw new ManagedEnvironmentException('No cluster manifest file was found.');
     }
     try {
         $_manifest = JsonFile::decodeFile($_file);
         $this->validateManifest($_manifest);
         foreach ($_manifest as $_key => $_value) {
             $this->put($_key, $_value);
         }
     } catch (\InvalidArgumentException $_ex) {
         throw new ManagedEnvironmentException('The cluster manifest file is corrupt, invalid, or otherwise unreadable.');
     }
 }
Пример #4
0
 /** @inheritdoc */
 public function fire()
 {
     parent::fire();
     $this->setOutputPrefix('[' . $this->name . ']');
     if ($this->option('all')) {
         $this->info('Migrating <comment>all</comment> instances');
         $_results = $this->migrateAllInstances();
     } elseif (null !== ($_instanceId = $this->argument('instance-id'))) {
         $this->info('Migrating instance "<comment>' . $_instanceId . '</comment>"');
         $_results = [$_instanceId => $this->migrateSingleInstance($_instanceId)];
     } else {
         $this->error('You must specify an <instance-id> or use the "--all" option.');
         return 1;
     }
     $_file = storage_path(date('YmdHis') . '-migrate-instance.json');
     if (false === JsonFile::encodeFile($_file, $_results)) {
         $this->error('Error storing results to file.');
     }
     return 0;
 }
Пример #5
0
 /** ctor  */
 public function __construct()
 {
     $this->formData = $this->cleanData = [];
     $this->outputFile = storage_path() . DIRECTORY_SEPARATOR . self::OUTPUT_FILE_NAME;
     $this->jsonFile = storage_path() . DIRECTORY_SEPARATOR . self::JSON_FILE_NAME;
     $this->defaults['token_name'] = 'dfe-installer-on-' . gethostname() . '-' . date('YmdHis');
     logger('Output files set to:');
     logger(' > shell source file ' . $this->outputFile);
     logger(' > json source file ' . $this->outputFile);
     logger('Checking for last values in "' . $this->jsonFile . '"');
     //  If an existing run's data is available, pre-fill form with it
     if (file_exists($this->jsonFile)) {
         logger('Found existing file "' . $this->jsonFile . '"');
         try {
             $this->defaults = array_merge($this->defaults, JsonFile::decodeFile($this->jsonFile, true));
             logger('Prior values read from "' . $this->jsonFile . '": ' . print_r($this->defaults, true));
         } catch (\Exception $_ex) {
             //  Bogus JSON, just ignore
             logger('No prior values found to seed page. Defaults: ' . print_r($this->defaults, true));
         }
     }
     //        $this->getRequiredPackages();
 }
Пример #6
0
 /**
  * Refreshes the cache with fresh values
  */
 protected function freshenCache()
 {
     $_cacheFile = Disk::path($this->getCachePath(), true, 0775) . DIRECTORY_SEPARATOR . $this->getCacheKey();
     $this->config['.expires'] = time() + static::CACHE_TTL * 60;
     $this->config['.middleware'] = $this->middleware;
     $this->config['.route-middleware'] = $this->routeMiddleware;
     return JsonFile::encodeFile($_cacheFile, $this->config);
 }
Пример #7
0
 /**
  * @return bool
  */
 protected function _backupServiceUsers()
 {
     $_backupPath = base_path() . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'dfe';
     if (!Disk::ensurePath($_backupPath)) {
         $this->writeln('Unable to write to backup path <comment>' . $_backupPath . '</comment>. Aborting.', 'error');
         return false;
     }
     $_users = [];
     /** @type ServiceUser $_user */
     foreach (ServiceUser::all() as $_user) {
         $_users[] = $_user->toArray();
     }
     JsonFile::encodeFile($_backupPath . DIRECTORY_SEPARATOR . 'service-user.backup.' . date('YmdHis') . '.json', $_users);
     return true;
 }
Пример #8
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);
 }
Пример #9
0
 /**
  * @return string
  */
 public function __toString()
 {
     return JsonFile::encode($this->toArray());
 }
Пример #10
0
 /**
  * Commits a blueprint to the repo
  *
  * @param string $instanceId
  * @param array  $blueprint
  *
  * @return bool
  */
 protected function commitBlueprint($instanceId, $blueprint)
 {
     //  Create/update the file
     $_file = Disk::path([$this->repoPath, $instanceId . '.json']);
     JsonFile::encodeFile($_file, $blueprint, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     //  Commit it
     $_commitMessage = 'Blueprint for instance "' . $instanceId . '" created on ' . date('Y-m-d H:i:s');
     $_response = \Event::fire('dfe.blueprint.pre-commit', ['instance-id' => $instanceId, 'blueprint' => $blueprint, 'repository-path' => $this->repoPath, 'commit-message' => $_commitMessage]);
     //  See if the commit message has changed...
     if (!empty($_response) && null !== ($_message = array_get($_response, 'commit-message'))) {
         $_commitMessage = $_message;
     }
     if (0 !== $this->git->commitChange($_file, $_commitMessage)) {
         \Log::error('Error committing blueprint file "' . $_file . '".');
         return false;
     }
     \Event::fire('dfe.blueprint.post-commit', ['instance-id' => $instanceId, 'blueprint' => $blueprint, 'repository-path' => $this->repoPath]);
     return true;
 }
 /**
  * Retrieves an input argument and checks for valid JSON.
  *
  * @param string|null $optionKey The option name to retrieve
  * @param string|null $arrayKey  If specified, decoded array will be placed into $array[$arrayKey]
  * @param array|null  $array     The $array in which to place the result
  * @param bool        $required  If this is required
  *
  * @return bool|array
  */
 protected function optionArray($optionKey = null, $arrayKey = null, array &$array = null, $required = false)
 {
     /** @noinspection PhpUndefinedMethodInspection */
     $_data = $this->option($optionKey);
     if (null === $arrayKey) {
         return $_data;
     }
     if (empty($_data)) {
         if ($required) {
             /** @noinspection PhpUndefinedMethodInspection */
             $this->writeln('"' . $optionKey . '" is a required option for this operation.');
             return false;
         }
         $array[$arrayKey] = $_data = [];
         return true;
     }
     try {
         $_data = JsonFile::decode($_data);
     } catch (\Exception $_ex) {
         /** @noinspection PhpUndefinedMethodInspection */
         $this->writeln('the "' . $optionKey . '" provided does not contain valid JSON.');
         return false;
     }
     $array[$arrayKey] = $_data;
     return true;
 }
Пример #12
0
 /**
  * Constructor
  *
  * @param string  $configFile The CORS config file, if any
  * @param Request $request    Optional request object. If not given, one will be created
  */
 public function __construct($configFile = null, $request = null)
 {
     //  Set defaults
     $this->_configFile = $configFile;
     $this->_request = $request ?: Request::createFromGlobals();
     $this->_headers = explode(',', static::DEFAULT_ALLOWED_HEADERS);
     $this->_verbs = explode(',', static::DEFAULT_ALLOWED_VERBS);
     //  See if we even need CORS
     $this->_requestOrigin = trim($this->_request->headers->get('http-origin'));
     $this->_requestVerb = $this->_request->getMethod();
     $this->_corsRequest = !empty($this->_requestOrigin);
     //  Load whitelist from file
     // if there...
     if ($this->_configFile) {
         $this->_whitelist = JsonFile::decodeFile($configFile);
     }
 }