aws / aws-sdk-php-zf2

ZF2 module for using the AWS SDK for PHP to interact with AWS services like S3, DynamoDB, SQS, EC2, etc.
http://aws.amazon.com/sdkforphp/
Apache License 2.0
103 stars 63 forks source link

How would I use the s3link in a layout? #53

Closed jarrettj closed 1 year ago

jarrettj commented 6 years ago

Hi,

Good day.

This seems to work for ZF2 but not ZF3. If I try and use:

$this->plugin('s3Link')->setDefaultBucket($bucket);

In the main view layout, I get the following error:

Fatal error: Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: A plugin by the name "s3Link" was not found in the plugin manager Zend\View\HelperPluginManager in /var/www/html/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php on line 131

I'm using v4 of this module so it should work with ZF3. Thanks.

Regards. JJ

jarrettj commented 6 years ago

These are my installed packages if that helps:

aws/aws-sdk-php                              3.57.0            
aws/aws-sdk-php-zf2                          v4.1.0            
behat/transliterator                         v1.2.0            
container-interop/container-interop          1.2.0             
doctrine/annotations                         v1.6.0            
doctrine/cache                               v1.7.1            
doctrine/collections                         v1.5.0            
doctrine/common                              v2.8.1            
doctrine/dbal                                v2.7.1            
doctrine/doctrine-module                     1.2.0             
doctrine/doctrine-orm-module                 1.1.8             
doctrine/inflector                           v1.3.0            
doctrine/instantiator                        1.1.0             
doctrine/lexer                               v1.0.1            
doctrine/migrations                          v1.7.2            
doctrine/orm                                 v2.6.1            
gedmo/doctrine-extensions                    v2.4.35           
guzzlehttp/guzzle                            6.3.3             
guzzlehttp/promises                          v1.3.1            
guzzlehttp/psr7                              1.4.2             
kriswallsmith/assetic                        v1.4.0            
mtdowling/jmespath.php                       2.4.0             
neilime/zf2-twb-bundle                       3.2.2             
ocramius/package-versions                    1.3.0             
ocramius/proxy-manager                       2.1.1             
paragonie/random_compat                      v2.0.12           
psr/cache                                    1.0.1             
psr/container                                1.0.0             
psr/http-message                             1.0.1             
psr/log                                      1.0.2             
psr/simple-cache                             1.0.1             
symfony/console                              v3.4.10           
symfony/debug                                v4.0.10           
symfony/polyfill-mbstring                    v1.8.0            
symfony/process                              v3.4.10           
widmogrod/php-exceptions                     0.1.0             
widmogrod/php-functional                     1.4.0             
widmogrod/zf2-assetic-module                 2.4.0             
zendframework/zend-authentication            2.6.0             
zendframework/zend-cache                     2.8.2             
zendframework/zend-code                      3.3.0             
zendframework/zend-component-installer       2.1.1             
zendframework/zend-config                    3.2.0             
zendframework/zend-console                   2.7.0             
zendframework/zend-crypt                     3.3.0             
zendframework/zend-db                        2.9.3             
zendframework/zend-debug                     2.6.0             
zendframework/zend-developer-tools           1.2.1             
zendframework/zend-escaper                   2.6.0             
zendframework/zend-eventmanager              3.2.1             
zendframework/zend-file                      2.8.1             
zendframework/zend-filter                    2.7.2             
zendframework/zend-form                      2.12.0            
zendframework/zend-http                      2.8.0             
zendframework/zend-hydrator                  2.4.0             
zendframework/zend-i18n                      2.9.0             
zendframework/zend-inputfilter               2.8.2             
zendframework/zend-json                      2.6.1             
zendframework/zend-loader                    2.6.0             
zendframework/zend-log                       2.10.0            
zendframework/zend-math                      3.1.0             
zendframework/zend-modulemanager             2.8.2             
zendframework/zend-mvc                       3.1.1             
zendframework/zend-mvc-console               1.2.0             
zendframework/zend-mvc-form                  1.0.0             
zendframework/zend-mvc-i18n                  1.1.0             
zendframework/zend-mvc-plugin-fileprg        1.0.0             
zendframework/zend-mvc-plugin-flashmessenger 1.0.0             
zendframework/zend-mvc-plugin-identity       1.1.0             
zendframework/zend-mvc-plugin-prg            1.0.0             
zendframework/zend-mvc-plugins               1.0.1             
zendframework/zend-paginator                 2.8.1             
zendframework/zend-permissions-acl           2.7.0             
zendframework/zend-router                    3.0.2             
zendframework/zend-serializer                2.9.0             
zendframework/zend-servicemanager            3.3.2             
zendframework/zend-session                   2.7.0             
zendframework/zend-stdlib                    3.2.0             
zendframework/zend-text                      2.7.0             
zendframework/zend-uri                       2.6.1             
zendframework/zend-validator                 2.10.2            
zendframework/zend-version                   2.5.1             
zendframework/zend-view                      2.10.0            
zendframework/zenddiagnostics                v1.1.0            
zendframework/zftool                         v0.1.0            
zf-commons/zfc-user                          3.0.0             
zf-commons/zfc-user-doctrine-orm             2.0.0             
zfcampus/zf-development-mode                 3.2.0
kstich commented 6 years ago

It looks like Zend can't find the plugin at all. Please make sure you have followed the configuration steps.

jarrettj commented 3 years ago

@kstich Strangely this is still an issue. It works out the box with the ZF2 version. Busy migrating to Laminas. Trying the V4 and it can't find the plugin. Any ideas? Maybe another config I am missing? Thanks.

Composer:

"aws/aws-sdk-php-zf2": "^4",
...

Application config:

$modules = array(
    'DoctrineModule',
    'DoctrineORMModule',
    'AwsModule',
...
);

Regards. Jarrett

jarrettj commented 3 years ago

Even tried using the laminas skeleton instead of my application code. But it does not work there as well.

vincequeiroz commented 2 years ago

The alias to the view helper is case sensitive.

These are the possibilities:

$this->plugin('s3link')->setDefaultBucket($bucket);
$this->plugin('AwsModule\View\Helper\S3Link')->setDefaultBucket($bucket);

Here you can find the answers: https://github.com/aws/aws-sdk-php-zf2/blob/master/config/module.config.php#L39

jarrettj commented 1 year ago

Hi,

Had forgot about this, managed to step through the code.

The issue is here https://github.com/aws/aws-sdk-php-zf2/blob/94ac0ed17992bc94648988a4dfcd9ad9b49a4f68/src/Factory/S3LinkViewHelperFactory.php#L8C13-L8C13

laminas-servicemanager version 2.7 the FactoryInterface is at Laminas\ServiceManager\FactoryInterface.

namespace Laminas\ServiceManager;

interface FactoryInterface
...

Will try and to step through and figure this out. As I'm stuck on the 3x version.

Regards, Jarrett

jarrettj commented 1 year ago

Bit late, but it works for me now when using: $this->plugin('AwsModule\View\Helper\S3Link')->setDefaultBucket($bucket);

Upgraded to PHP 7.4 and using version 4.4.0

Regards, Jarrett

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.