AWS PHP SDK 2(aws.phar)不与Restler框架工作 [英] AWS PHP SDK 2 (aws.phar) does not work with Restler Framework

查看:289
本文介绍了AWS PHP SDK 2(aws.phar)不与Restler框架工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在测试使用的AWS-SDK-php的文件上传到S3存储一些PHP脚本。这些脚本似乎很好地工作时,他们直接从浏览器中执行,但没有试图通过在Luracast Restler 3.0

I have been testing some PHP scripts that uses the aws-sdk-php to upload files to S3 storage. These scripts seems to work nicely when they are executed directly from the browser, but fails when trying to use it through an API class in Luracast Restler 3.0

这是上传一些虚拟文件一个示例脚本是这样的:

A sample script that upload some dummy file is like the following:

<?php

require_once (dirname(__FILE__) . "/../lib/aws/aws.phar");

use Aws\Common\Aws;
use Aws\S3\Enum\CannedAcl;
use Aws\S3\Exception\S3Exception;
use Aws\Common\Enum\Region;

function test(){
    // Instantiate an S3 client
    $s3 = Aws::factory(array(
        'key'    => 'key',
        'secret' => 'secret',
        'region' => Region::EU_WEST_1
    ))->get('s3');

    try {
        $s3->putObject(array(
            'Bucket' => 'my-bucket',
            'Key'    => '/test/test.txt',
            'Body'   => 'example file uploaded from php!',
            'ACL'    => CannedAcl::PUBLIC_READ
        ));
    } catch (S3Exception $e) {
        echo "There was an error uploading the file.\n";
    }
}

该脚本放在该文件夹中的 /util/test.php ,而AWS-PHP-SDK是 /lib/aws/aws.phar

This script is placed in the folder /util/test.php, while the aws-php-sdk is at /lib/aws/aws.phar

要测试这种测试方法是写得很好,我已经创建另一个PHP脚本 /test/upload.php 有以下code:

To test that this test method is well written I have created another php script at /test/upload.php with the following code:

<?php

require_once (dirname(__FILE__) . '/../util/test.php');

test();

这样我就可以在浏览器中 http://mydomain.com/test/upload.php,所有工作正常,文件上传的S3存储。

So I can enter in the browser http://mydomain.com/test/upload.php and all is working as expected and the file is uploaded in S3 storage.

然而,当我打电话的功能测试()从与Restler框架中的API类,我有一个错误,指出AWS无法找到:

However when I call the function test() from an API class with the Restler framework, I have an error that says that Aws cannot be found:

Fatal error: Class 'Aws\Common\Aws' not found in /var/app/current/util/test.php on line 12

然而,code是完全从upload.php的调用时,完美的工作原理相同。我一直在浪费时间试图找出这里发生了什么,但我不能得到任何结论。就像AWS-PHP-SDK磁带自动加载机不会在某些情况下正常工作。

However the code is exactly the same that perfectly works when called from upload.php. I have been wasting hours trying to figure out what is happening here, but I cannot get any conclusion. Is like the aws-php-sdk autoloader does not work well under some circumstances.

任何提示?

推荐答案

此举行我回相当长的一段时间,

This held me back quite some time,

该问题是由reslters自动加载机这台spl_autoload_unregiste 这里描述: https://github.com/Luracast/Restler/issues/72

The issue is caused by reslters autoloader which sets spl_autoload_unregiste as described here: https://github.com/Luracast/Restler/issues/72

要得到角落找寻这个问题的方法之一是注释掉相关线路的供应商/ Luracast / Restler / AutoLoader.php

One way to get arround the problem is to comment out the relevant lines in vendor/Luracast/Restler/AutoLoader.php

    public static function thereCanBeOnlyOne() {
    if (static::$perfectLoaders === spl_autoload_functions())
        return static::$instance;

/*
    if (false !== $loaders = spl_autoload_functions())
        if (0 < $count = count($loaders))
            for ($i = 0, static::$rogueLoaders += $loaders;
                 $i < $count && false != ($loader = $loaders[$i]);
                 $i++)
                if ($loader !== static::$perfectLoaders[0])
                    spl_autoload_unregister($loader);
    */
    return static::$instance;
}

这篇关于AWS PHP SDK 2(aws.phar)不与Restler框架工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆