public function testGet() { $config = new Config(); $this->assertFalse($config->has('setting')); $this->assertNull($config->get('setting')); $config->set('setting', 'value'); $this->assertEquals('value', $config->get('setting')); $fallback = new Config(['fallback_setting' => 'fallback_value']); $config->setFallback($fallback); $this->assertEquals('fallback_value', $config->get('fallback_setting')); }
/** * Write a new file. * * @param string $path * @param string $contents * @param Config $config Config object * * @return array|false false on failure file meta data on success */ public function write($path, $contents, Config $config) { if ($config->has('ttl') && !$config->has('expirationType')) { $config->set('expirationType', self::EXPIRE_IN_SECONDS); } $args = array_merge([$path, $contents], array_filter([$config->get('expirationType'), $config->get('ttl'), $config->get('setFlag')], function ($value) { return !is_null($value); })); if (!call_user_func_array([$this->client, 'set'], $args)) { return false; } return compact('path', 'contents'); }
/** * Upload an object. * * @param $path * @param $body * @param Config $config * * @return array */ protected function upload($path, $body, Config $config) { $key = $this->applyPathPrefix($path); $mimetype = MimeType::detectByFileExtension(pathinfo($path, PATHINFO_EXTENSION)); $config->set('mimetype', $mimetype); $return = parent::upload($path, $body, $config); if (function_exists('getimagesizefromstring') && strpos($mimetype, 'image') !== false) { if (is_resource($body)) { rewind($body); $size = getimagesizefromstring(stream_get_contents($body)); } else { $size = getimagesizefromstring($body); } $this->s3Client->copyObject(['Bucket' => $this->bucket, 'CopySource' => $this->bucket . DS . $key, 'ContentType' => $mimetype, 'Metadata' => ['width' => $size[0], 'height' => $size[1]], 'MetadataDirective' => 'REPLACE', 'Key' => $key]); } return $return; }
/** * {@inheritdoc} */ public function updateStream($path, $resource, Config $config) { if (!$config->has('visibility') && !$config->has('ACL')) { $config->set('ACL', $this->getObjectACL($path)); } return $this->writeStream($path, $resource, $config); }
/** * Configure server files for this store * * @param bool $forceOverwrite Force regeneration even if files already exist * @throws \Exception */ protected function configureServer($forceOverwrite = false) { // Get server type $type = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '*'; list($type) = explode('/', strtolower($type)); // Determine configurations to write $rules = Config::inst()->get(get_class($this), 'server_configuration', Config::FIRST_SET); if (empty($rules[$type])) { return; } $configurations = $rules[$type]; // Apply each configuration $config = new FlysystemConfig(); $config->set('visibility', 'private'); foreach ($configurations as $file => $template) { if ($forceOverwrite || !$this->has($file)) { // Evaluate file $content = $this->renderTemplate($template); $success = $this->write($file, $content, $config); if (!$success) { throw new \Exception("Error writing server configuration file \"{$file}\""); } } } }