/**
  * 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.');
     }
 }
Esempio n. 2
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();
 }
Esempio n. 3
0
 /**
  * Reload the cache
  */
 protected function loadCachedValues()
 {
     $_cached = null;
     $_cacheFile = Disk::path([$this->getCachePath(true), $this->getCacheKey()]);
     if (file_exists($_cacheFile)) {
         $_cached = JsonFile::decodeFile($_cacheFile);
         if (isset($_cached, $_cached['.expires']) && $_cached['.expires'] < time()) {
             $_cached = null;
         }
         array_forget($_cached, '.expires');
     }
     //  These must exist otherwise we need to phone home
     if (empty($_cached) || !is_array($_cached) || !isset($_cached['paths'], $_cached['env'], $_cached['db'], $_cached['audit'])) {
         return false;
     }
     //  Cool, we got's what we needs's
     $this->config = $_cached;
     $this->middleware = array_get($_cached, '.middleware', []);
     $this->routeMiddleware = array_get($_cached, '.route-middleware', []);
     return true;
 }
 /**
  * Reads and loads the manifest into memory
  *
  * @return $this
  */
 public function read()
 {
     try {
         $_contents = JsonFile::decodeFile($this->getFullFilename());
     } catch (\InvalidArgumentException $_ex) {
         //  Reset contents to default
         $this->_contents = $this->_template;
         //  No file there...
         return $this;
     }
     if (!empty($_contents)) {
         $_cleaned = $this->_template;
         foreach ($_contents as $_key => $_value) {
             $_key = str_replace(['_', ' '], ['-', null], strtolower(trim($_key)));
             if (array_key_exists($_key, $_cleaned)) {
                 $_cleaned[$_key] = !is_scalar($_value) && !is_array($_value) ? null === $_value ? null : (array) $_value : $_value;
             }
         }
         $this->_contents = $_cleaned;
         $this->_existed = true;
     }
     return $this;
 }
Esempio n. 5
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);
     }
 }