white43 / yii2-cloud-asset-manager

This extension uploads your local yii2 assets to CDN services
MIT License
6 stars 1 forks source link

Setting unknown property: white43\CloudAssetManager\LocalAssetManager::adapter #2

Open sahilr2050 opened 9 months ago

sahilr2050 commented 9 months ago

I am using below settings

main.php

'assetManager' => [
  'class'    => \white43\CloudAssetManager\CloudAssetManager::class,
  'basePath' => 'assets',
  'baseUrl'  => ArrayHelper::getValue($params, 'AWS_URL').'assets',
  'cache'    => 'cache', // Name of your cache component
  'adapter'  => static function() use ($params): \League\Flysystem\FilesystemAdapter {
      $s3 = new \Aws\S3\S3Client([
          'region' => ArrayHelper::getValue($_SERVER, 'AWS_REGION'),
          'version' => 'latest',
          'use_path_style_endpoint' => true,
      ]);
      return new \League\Flysystem\AwsS3V3\AwsS3V3Adapter($s3, ArrayHelper::getValue($params, 'AWS_BUCKET_NAME'), '', null, null, ['params' => ['ACL' => 'public-read']]);
  },
  'appendTimestamp' => true,
  ],
],

For local development main-local.php

'assetManager' => [
    'class' => LocalAssetManager::class,
    'cache' => 'cache', // Name of your cache component
    'basePath' => '@app/web/assets', // @webroot doesn't exist in CLI mode
],

I can see in LocalAssetManager there is no property with Adapter. Can you please define all the parameters in BaseAssetManager or can you suggest alternative way to work like above.

white43 commented 9 months ago

@sahilr2050 There is no need for the adapter property, as all of your assets are simply copied from one directory to another one using the \yii\web\AssetManager::publishDirectory method which is a part of the Yii2 framework. The example you provided in the main-local.php snippet is sufficient for both development and production environments. On some of the projects I am in charge of, I use pretty the same configuration for the LocalAssetManager::class.

white43 commented 9 months ago

And this is how I deal with different environments:

if (YII_ENV_PROD) {
    $config['components']['assetManager'] = [
        'class' => white43\CloudAssetManager\CloudAssetManager::class,
        // ...
    ];
} else {
    $config['components']['assetManager'] = [
        'class' => white43\CloudAssetManager\LocalAssetManager::class,
        // ...
    ];
}
sahilr2050 commented 9 months ago

Yes, I did same. Thanks for the library.