示例#1
0
 /**
  * Specifies the data to be shaped
  *
  * @param array|mixed $data
  *
  * @return $this
  */
 public function with($data = [])
 {
     //  Convert to an array and store
     if (!is_array($data)) {
         if (is_scalar($data)) {
             throw new \InvalidArgumentException('The $data provided is a scalar value.');
         }
         if (false === ($_json = Json::encode($data)) || JSON_ERROR_NONE != json_last_error()) {
             throw new \InvalidArgumentException('The $data provided cannot be converted to an array.');
         }
         $data = Json::decode($_json, true);
     }
     $this->data = $data;
     return $this;
 }
 /**
  * @param string          $service The service to retrieve
  * @param int             $index   Which index to return if multiple. NULL returns all
  * @param string|int|null $subkey  Subkey under index to use instead of "credentials"
  *
  * @return array|bool
  * @throws \DreamFactory\Managed\Exceptions\ManagedEnvironmentException
  */
 public function getDatabaseConfig($service = self::BM_DB_SERVICE_KEY, $index = self::BM_DB_INDEX, $subkey = self::BM_DB_CREDS_KEY)
 {
     $this->cacheKey = static::CACHE_KEY_PREFIX . app('request')->getHttpHost();
     //  Decode and examine
     try {
         /** @type string $_envData */
         $_envData = getenv(static::BM_ENV_KEY);
         if (!empty($_availableServices = Json::decode($_envData, true))) {
             $_serviceSet = array_get($_availableServices, $service);
             //  Get credentials environment data
             $_config = array_get(isset($_serviceSet[$index]) ? $_serviceSet[$index] : [], $subkey, []);
             if (empty($_config)) {
                 throw new \RuntimeException('DB credentials not found in env: ' . print_r($_serviceSet, true));
             }
             $_db = ['driver' => 'mysql', 'host' => array_get($_config, 'host', array_get($_config, 'hostname', 'localhost')), 'database' => $_config['name'], 'username' => $_config['username'], 'password' => $_config['password'], 'port' => $_config['port'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false];
             unset($_envData, $_config, $_serviceSet);
             return $_db;
         }
     } catch (\InvalidArgumentException $_ex) {
         //  Environment not set correctly for this deployment
     }
     //  Database configuration not found for bluemix
     throw new ManagedEnvironmentException('Bluemix platform detected but no database services are available.');
 }
示例#3
0
 /**
  * Reads the file and returns the contents
  *
  * @param bool $decoded If true (the default), the read data is decoded
  * @param int  $depth   The maximum recursion depth
  * @param int  $options Any json_decode options
  *
  * @return array|bool|string
  */
 protected function doRead($decoded = true, $depth = 512, $options = 0)
 {
     //  Always start with an empty array
     $_result = $this->template;
     //  No existing file, empty array back
     if (!$this->filename || !$this->filesystem->has($this->filename)) {
         return $_result;
     }
     //  Error reading file, false back...
     if (false === ($_json = $this->filesystem->read($this->filename))) {
         return false;
     }
     //  Not decoded gets string back
     if (!$decoded) {
         return $_json;
     }
     return Json::decode($_json, true, $depth, $options);
 }