/** * Wrapper around the singleton call to StorageManager::config() * * Makes it easy to mock the adapter in tests. * * @throws \InvalidArgumentException * @param string $configName * @return array */ public function storageConfig($configName) { if (empty($configName) || !is_string($configName)) { throw new \InvalidArgumentException('First arg must be a non empty string!'); } return StorageManager::config($configName); }
/** * testAdapter * * @todo more tests * @return void */ public function testAdapter() { $result = StorageManager::adapter('Local'); $this->assertEqual(get_class($result), 'Gaufrette\\Filesystem'); $result = StorageManager::activeAdapter(); $this->assertEqual($result, 'Local'); $result = StorageManager::activeAdapter('invalid-adapter'); $this->assertFalse($result); $result = StorageManager::config(); }
/** * Setup test folders and files * * @return void */ public function setUp() { parent::setUp(); $this->testPath = TMP . 'file-storage-test' . DS; Configure::write('Media.basePath', $this->testPath); if (!is_dir($this->testPath)) { $Folder = new Folder($this->testPath, true); } Configure::write('Media.imageSizes', array('Test' => array('t50' => array('thumbnail' => array('mode' => 'outbound', 'width' => 50, 'height' => 50)), 't150' => array('thumbnail' => array('mode' => 'outbound', 'width' => 150, 'height' => 150))))); ClassRegistry::init('FileStorage.ImageStorage')->generateHashes(); StorageManager::config('Local', array('adapterOptions' => array($this->testPath, true), 'adapterClass' => '\\Gaufrette\\Adapter\\Local', 'class' => '\\Gaufrette\\Filesystem')); }
spl_autoload_register(function ($class) { $defaultPath = CakePlugin::path('Assets') . 'Vendor' . DS . 'Gaufrette' . DS . 'src' . DS; $base = Configure::read('Assets.GaufretteLib'); if (empty($base)) { $base = $defaultPath; } $class = str_replace('\\', DS, $class); if (file_exists($base . $class . '.php')) { include $base . $class . '.php'; } }); Configure::write('Wysiwyg.attachmentBrowseUrl', array('plugin' => 'assets', 'controller' => 'assets_attachments', 'action' => 'browse')); Configure::write('Wysiwyg.uploadsPath', ''); Croogo::mergeConfig('Wysiwyg.actions', array('AssetsAttachments/admin_browse')); App::uses('StorageManager', 'Assets.Lib'); StorageManager::config('LocalAttachment', array('description' => 'Local Attachment', 'adapterOptions' => array(WWW_ROOT . 'assets', true), 'adapterClass' => '\\Gaufrette\\Adapter\\Local', 'class' => '\\Gaufrette\\Filesystem')); StorageManager::config('LegacyLocalAttachment', array('description' => 'Local Attachment (Legacy)', 'adapterOptions' => array(WWW_ROOT . 'uploads', true), 'adapterClass' => '\\Gaufrette\\Adapter\\Local', 'class' => '\\Gaufrette\\Filesystem')); // TODO: make this configurable via backend $actions = array('Nodes/admin_edit', 'Blocks/admin_edit', 'Types/admin_edit'); $tabTitle = __d('assets', 'Assets'); foreach ($actions as $action) { list($controller, ) = explode('/', $action); Croogo::hookAdminTab($action, $tabTitle, 'Assets.admin/asset_list'); Croogo::hookHelper($controller, 'Assets.AssetsAdmin'); } // TODO: make this configurable via backend $models = array('Block', 'Node', 'Type'); foreach ($models as $model) { Croogo::hookBehavior($model, 'Assets.LinkedAssets', array('priority' => 9)); } Croogo::hookHelper('*', 'Assets.AssetsFilter');
/** * Gets the adapter class name from the adapter configuration key * * @param string * @return void */ public function getAdapterClassName($adapterConfigName) { $config = StorageManager::config($adapterConfigName); switch ($config['adapterClass']) { case '\\Gaufrette\\Adapter\\Local': $this->adapterClass = 'Local'; return $this->adapterClass; case '\\Gaufrette\\Adapter\\AwsS3': $this->adapterClass = 'AwsS3'; return $this->adapterClass; case '\\Gaufrette\\Adapter\\AmazonS3': $this->adapterClass = 'AwsS3'; return $this->adapterClass; case '\\Gaufrette\\Adapter\\AwsS3': $this->adapterClass = 'AwsS3'; return $this->adapterClass; default: return false; } }
/** * Wrapper around the singleton call to StorageManager::config * * @param string $configName * @return array */ public function getAdapterconfig($configName) { return StorageManager::config($configName); }
<?php require_once ROOT . DS . APP_DIR . DS . 'Plugin' . DS . 'FileStorage' . DS . 'Vendor' . DS . 'AWSsdk' . DS . 'aws-autoloader.php'; App::uses('S3StorageListener', 'FileStorage.Event'); App::uses('FileStorageUtils', 'FileStorage.Lib/Utility'); App::uses('StorageManager', 'FileStorage.Lib'); App::uses('ImageProcessingListener', 'FileStorage.Event'); App::uses('CakeEventManager', 'Event'); App::uses('ClassRegistry', 'Utility'); CakePlugin::load(array('Imagine' => array('bootstrap' => true))); Configure::write('Imagine.salt', 'T!6stub6f=as5e4U#u8u7!ut9wRuphUS'); // Only required if you're *NOT* using composer or another autoloader! spl_autoload_register(__NAMESPACE__ . '\\FileStorageUtils::gaufretteLoader'); // Attach the Image Processing Listener to the global CakeEventManager $listener = new ImageProcessingListener(); CakeEventManager::instance()->attach($listener); Configure::write('Media', array('imageSizes' => array('ImageStorage' => array('large' => array('thumbnail' => array('mode' => 'inbound', 'width' => 800, 'height' => 800)), 'medium' => array('thumbnail' => array('mode' => 'inbound', 'width' => 200, 'height' => 200)), 'small' => array('thumbnail' => array('mode' => 'inbound', 'width' => 80, 'height' => 80)))))); // This is very important! The hashes are needed to calculate the image versions! ClassRegistry::init('FileStorage.ImageStorage')->generateHashes(); use Aws\S3; App::uses('ConnectionManager', 'Model'); $dataSource = ConnectionManager::enumConnectionObjects(); if (isset($dataSource['aws'])) { // Attach the S3 Listener to the global CakeEventManager $listener = new S3StorageListener(); CakeEventManager::instance()->attach($listener); $S3Client = \Aws\S3\S3Client::factory($dataSource['aws']); StorageManager::config('S3Storage', array('adapterOptions' => array($S3Client, 'isby', array(), true), 'adapterClass' => '\\Gaufrette\\Adapter\\AwsS3', 'class' => '\\Gaufrette\\Filesystem')); }