diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..28b9aaf --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +.gitattributes export-ignore +.github export-ignore +.gitignore export-ignore +.travis.yml export-ignore +CHANGELOG.md export-ignore +CONTRIBUTING.md export-ignore +Makefile export-ignore +README.md export-ignore +phpunit.xml export-ignore +tests/ export-ignore diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 0000000..946fd2f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,81 @@ +--- +name: "🐛 Bug Report" +description: Report a bug +title: "(short issue description)" +labels: [bug, needs-triage] +assignees: [] +body: + - type: textarea + id: description + attributes: + label: Describe the bug + description: What is the problem? A clear and concise description of the bug. + validations: + required: true + - type: checkboxes + id: regression + attributes: + label: Regression Issue + description: What is a regression? If it worked in a previous version but doesn't in the latest version, it's considered a regression. In this case, please provide specific version number in the report. + options: + - label: Select this option if this issue appears to be a regression. + required: false + - type: textarea + id: expected + attributes: + label: Expected Behavior + description: | + What did you expect to happen? + validations: + required: true + - type: textarea + id: current + attributes: + label: Current Behavior + description: | + What actually happened? + + Please include full errors, uncaught exceptions, stack traces, and relevant logs. + If service responses are relevant, please include wire logs. + validations: + required: true + - type: textarea + id: reproduction + attributes: + label: Reproduction Steps + description: | + Provide a self-contained, concise snippet of code that can be used to reproduce the issue. + For more complex issues provide a repo with the smallest sample that reproduces the bug. + + Avoid including business logic or unrelated code, it makes diagnosis more difficult. + The code sample should be an SSCCE. See http://sscce.org/ for details. In short, please provide a code sample that we can copy/paste, run and reproduce. + validations: + required: true + - type: textarea + id: solution + attributes: + label: Possible Solution + description: | + Suggest a fix/reason for the bug + validations: + required: false + - type: textarea + id: context + attributes: + label: Additional Information/Context + description: | + Anything else that might be relevant for troubleshooting this bug. Providing context helps us come up with a solution that is most useful in the real world. + validations: + required: false + - type: input + id: sdk-version + attributes: + label: SDK version used + validations: + required: true + - type: input + id: environment + attributes: + label: Environment details (OS name and version, etc.) + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..7c7ea35 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,6 @@ +--- +blank_issues_enabled: false +contact_links: + - name: 💬 General Question + url: https://github.com/aws/aws-sdk-php-laravel/discussions/categories/q-a + about: Please ask and answer questions as a discussion thread \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml new file mode 100644 index 0000000..7d73869 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -0,0 +1,23 @@ +--- +name: "📕 Documentation Issue" +description: Report an issue in the API Reference documentation or Developer Guide +title: "(short issue description)" +labels: [documentation, needs-triage] +assignees: [] +body: + - type: textarea + id: description + attributes: + label: Describe the issue + description: A clear and concise description of the issue. + validations: + required: true + + - type: textarea + id: links + attributes: + label: Links + description: | + Include links to affected documentation page(s). + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000..60d2431 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,59 @@ +--- +name: 🚀 Feature Request +description: Suggest an idea for this project +title: "(short issue description)" +labels: [feature-request, needs-triage] +assignees: [] +body: + - type: textarea + id: description + attributes: + label: Describe the feature + description: A clear and concise description of the feature you are proposing. + validations: + required: true + - type: textarea + id: use-case + attributes: + label: Use Case + description: | + Why do you need this feature? For example: "I'm always frustrated when..." + validations: + required: true + - type: textarea + id: solution + attributes: + label: Proposed Solution + description: | + Suggest how to implement the addition or change. Please include prototype/workaround/sketch/reference implementation. + validations: + required: false + - type: textarea + id: other + attributes: + label: Other Information + description: | + Any alternative solutions or features you considered, a more detailed explanation, stack traces, related issues, links for context, etc. + validations: + required: false + - type: checkboxes + id: ack + attributes: + label: Acknowledgements + options: + - label: I may be able to implement this feature request + required: false + - label: This feature might incur a breaking change + required: false + - type: input + id: sdk-version + attributes: + label: SDK version used + validations: + required: true + - type: input + id: environment + attributes: + label: Environment details (OS name and version, etc.) + validations: + required: true diff --git a/.github/workflows/closed-issue-message.yml b/.github/workflows/closed-issue-message.yml new file mode 100644 index 0000000..3691dea --- /dev/null +++ b/.github/workflows/closed-issue-message.yml @@ -0,0 +1,16 @@ +name: Closed Issue Message +on: + issues: + types: [closed] +jobs: + auto_comment: + runs-on: ubuntu-latest + steps: + - uses: aws-actions/closed-issue-message@v1 + with: + # These inputs are both required + repo-token: "${{ secrets.GITHUB_TOKEN }}" + message: | + 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. diff --git a/.github/workflows/handle-stale-discussions.yml b/.github/workflows/handle-stale-discussions.yml new file mode 100644 index 0000000..ce9a066 --- /dev/null +++ b/.github/workflows/handle-stale-discussions.yml @@ -0,0 +1,19 @@ +name: HandleStaleDiscussions +on: + schedule: + - cron: '0 */4 * * *' + discussion_comment: + types: [created] + +jobs: + handle-stale-discussions: + if: github.repository_owner == 'aws' + name: Handle stale discussions + runs-on: ubuntu-latest + permissions: + discussions: write + steps: + - name: Stale discussions action + uses: aws-github-ops/handle-stale-discussions@v1 + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/issue-regression-labeler.yml b/.github/workflows/issue-regression-labeler.yml new file mode 100644 index 0000000..bd00071 --- /dev/null +++ b/.github/workflows/issue-regression-labeler.yml @@ -0,0 +1,32 @@ +# Apply potential regression label on issues +name: issue-regression-label +on: + issues: + types: [opened, edited] +jobs: + add-regression-label: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - name: Fetch template body + id: check_regression + uses: actions/github-script@v7 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TEMPLATE_BODY: ${{ github.event.issue.body }} + with: + script: | + const regressionPattern = /\[x\] Select this option if this issue appears to be a regression\./i; + const template = `${process.env.TEMPLATE_BODY}` + const match = regressionPattern.test(template); + core.setOutput('is_regression', match); + - name: Manage regression label + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if [ "${{ steps.check_regression.outputs.is_regression }}" == "true" ]; then + gh issue edit ${{ github.event.issue.number }} --add-label "potential-regression" -R ${{ github.repository }} + else + gh issue edit ${{ github.event.issue.number }} --remove-label "potential-regression" -R ${{ github.repository }} + fi diff --git a/.github/workflows/stale_issues.yml b/.github/workflows/stale_issues.yml new file mode 100644 index 0000000..4741bcb --- /dev/null +++ b/.github/workflows/stale_issues.yml @@ -0,0 +1,45 @@ +name: "Close stale issues" + +# Controls when the action will run. +on: + schedule: + - cron: "0 0 * * *" + +jobs: + cleanup: + runs-on: ubuntu-latest + name: Stale issue job + steps: + - uses: aws-actions/stale-issue-cleanup@v3 + with: + # Setting messages to an empty string will cause the automation to skip + # that category + ancient-issue-message: We have noticed this issue has not recieved attention in 3 years. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue. + stale-issue-message: This issue has not recieved a response in 1 week. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled. + + # These labels are required + stale-issue-label: closing-soon + exempt-issue-label: no-autoclose + stale-pr-label: no-pr-activity + exempt-pr-label: awaiting-approval + response-requested-label: response-requested + + # Don't set closed-for-staleness label to skip closing very old issues + # regardless of label + closed-for-staleness-label: closed-for-staleness + + # Issue timing + days-before-stale: 10 + days-before-close: 4 + days-before-ancient: 1095 + + # If you don't want to mark a issue as being ancient based on a + # threshold of "upvotes", you can set this here. An "upvote" is + # the total number of +1, heart, hooray, and rocket reactions + # on an issue. + minimum-upvotes-to-exempt: 10 + + repo-token: ${{ secrets.GITHUB_TOKEN }} + loglevel: DEBUG + # Set dry-run to true to not perform label or close actions. + # dry-run: true \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..aacf1e1 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,108 @@ +name: PHP Composer + +#whenever master has a PR or is pushed to +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + run: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - php-versions: '8.1' + laravel-versions: '^6.0' + - php-versions: '8.2' + laravel-versions: '^6.0' + - php-versions: '8.3' + laravel-versions: '^6.0' + - php-versions: '8.4' + laravel-versions: '^6.0' + - php-versions: '8.1' + laravel-versions: '^7.0' + - php-versions: '8.2' + laravel-versions: '^7.0' + - php-versions: '8.3' + laravel-versions: '^7.0' + - php-versions: '8.4' + laravel-versions: '^7.0' + - php-versions: '8.1' + laravel-versions: '^8.0' + - php-versions: '8.2' + laravel-versions: '^8.0' + - php-versions: '8.3' + laravel-versions: '^8.0' + - php-versions: '8.4' + laravel-versions: '^8.0' + - php-versions: '8.1' + laravel-versions: '^9.0' + - php-versions: '8.2' + laravel-versions: '^9.0' + - php-versions: '8.3' + laravel-versions: '^9.0' + - php-versions: '8.4' + laravel-versions: '^9.0' + - php-versions: '8.1' + laravel-versions: '^10.0' + - php-versions: '8.2' + laravel-versions: '^10.0' + - php-versions: '8.3' + laravel-versions: '^10.0' + - php-versions: '8.4' + laravel-versions: '^10.0' + - php-versions: '8.2' + laravel-versions: '^11.0' + - php-versions: '8.3' + laravel-versions: '^11.0' + - php-versions: '8.4' + laravel-versions: '^11.0' + - php-versions: '8.2' + laravel-versions: '^12.0' + - php-versions: '8.3' + laravel-versions: '^12.0' + - php-versions: '8.4' + laravel-versions: '^12.0' + + #set the name for each job + name: PHP ${{ matrix.php-versions }} with Laravel ${{ matrix.laravel-versions }} + #set up environment variables used by unit tests + env: + AWS_ACCESS_KEY_ID: foo + AWS_SECRET_ACCESS_KEY: bar + AWS_CSM_ENABLED: false + steps: + #sets up the correct version of PHP with necessary config options + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + ini-values: memory_limit=4G, phar.readonly=false + + #checkout the codebase from github + - name: Checkout codebase + uses: actions/checkout@v3 + + #require laravel + - name: Require laravel + run: composer require laravel/framework:${{ matrix.laravel-versions }} --no-interaction --prefer-dist --no-plugins + + #run tests + - name: Run test suite + run: vendor/bin/phpunit + + #remove laravel + - name: Remove laravel + run: | + composer remove laravel/framework --no-plugins + rm composer.lock + + #require lumen + - name: Require lumen + run: composer require laravel/lumen-framework --no-interaction --prefer-dist --no-plugins + + #run tests + - name: Run test suite + run: vendor/bin/phpunit \ No newline at end of file diff --git a/.gitignore b/.gitignore index b0def9a..75f93a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ composer.lock composer.phar vendor +.idea +.DS_Store +.phpunit.result.cache \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..daf1d91 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,118 @@ +# CHANGELOG + +## 3.7.0 - 2022-03-08 + +* Adds support for Laravel 9.0 +* Moves Travis CI tests to GitHub actions + +## 3.6.0 - 2020-09-14 + +* Adds support for Laravel 8.0 + +## 3.5.0 - 2020-03-11 + +* Adds support for Laravel 7.0 +* Travis CI configuration updates + +## 3.4.0 - 2019-09-09 + +* Adds support for Laravel 6.0 +* Travis CI configuration updates + +## 3.3.2 - 2019-03-15 + +* Align with suggested Laravel configuration practices +* Travis CI updated with PHP 7.3 and dependency resolution fixes + +## 3.3.1 - 2018-12-3 + +* Modify service provider to use different config for publishing and default usage + +## 3.3.0 - 2018-11-12 + +* Adds AWS credentials to published service provider configuration by default + +## 3.2.1 - 2018-10-19 + +* Update Travis CI with later PHP versions +* Fix composer dependency resolution issue for Travis & PHP 5.5.9 +* Updated location of aws config file in README.md +* Update README.md + +## 3.2.0 - 2018-09-28 + +* Added --provider option for vendor:publish command +* Added support for Laravel Auto-Discovery + +## 3.1.0 - 2016-01-17 + +* Added support for Lumen. + +## 3.0.3 - 2015-09-18 + +* Added support for configuring credentials with environmental variables, a ini + file at `~/.aws/credentials`, or with Ec2 instance profiles instead of + requiring their inclusion in the `aws.php` config file. + +## 3.0.3 - 2015-08-10 + +* Removed usage of a dev dependency + +## 3.0.1 - 2015-08-05 + +* Provide version information to SDK user agent + +## 3.0.0 - 2015-06-10 + +* Service provider is now compatible with Laravel 5.1 and Version 3 of the AWS + SDK for PHP. + +## 2.0.1 - 2015-06-10 + +* Service provider is now compatible with Lumen + +## 2.0.0 - 2015-03-12 + +* Updated the service provider to work with Laravel 5. + +## 1.1.2 - 2015-02-13 + +* Added alias to support DI from container. + +## 1.1.1 - 2014-05-12 + +* Updated default module config file to make it more compatible with environment + credentials + +## 1.1.0 - 2013-09-03 + +* Added package-level config that can be published with Artisan +* Updated config loading logic to support package-level config +* Updated config loading logic to support AWS SDK for PHP config files via the + `config_file` key +* Updated code, tests, and the README to support the config refactoring +* This module is now following [semver](http://semver.org/) + +## 1.0.4 - 2013-06-20 + +* Added support for the AWS facade +* Updated `composer.json` to require only specific components of Laravel +* Updated `composer.json` to require version 2.2+ of the AWS SDK for PHP + +## 1.0.3 - 2013-04-25 + +* Update Composer dependencies to work with newer version of the AWS SDK for PHP + and Laravel + +## 1.0.2 - 2013-03-11 + +* Fixed an issue with config retrieval + +## 1.0.1 - 2013-03-07 + +* Improved usage instructions in the README +* Fixed logic for retrieving Laravel version + +## 1.0.0 - 2013-02-13 + +* Initial release. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..5dccd4c --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,4 @@ +## Code of Conduct +This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). +For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact +opensource-codeofconduct@amazon.com with any additional questions or comments. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..4322c0c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,120 @@ +# Contributing to the AWS Service Provider for Laravel + +Thank you for your interest in contributing to the AWS Service Provider for Laravel! +We work hard to provide a high-quality and useful SDK for our AWS services, and +we greatly value feedback and contributions from our community. Whether it's a +new feature, correction, or additional documentation, we welcome your pull requests. +Please submit your [issues][] or [pull requests][pull-requests] through GitHub. + +Jump To: + +* [Bug Reports](_#Bug-Reports_) +* [Feature Requests](_#Feature-Requests_) +* [Code Contributions](_#Code-Contributions_) + +## How to contribute + +*Before you send us a pull request, please be sure that:* + +1. You're working from the latest source on the master branch. +2. You check existing open, and recently closed, pull requests to be sure that + someone else hasn't already addressed the problem. +3. You create an issue before working on a contribution that will take a significant + amount of your time. + +*Creating a Pull Request* + +1. Fork the repository. +2. In your fork, make your change in a branch that's based on this repo's master branch. +3. Commit the change to your fork, using a clear and descriptive commit message. +4. Create a pull request, answering any questions in the pull request form. + +For contributions that will take a significant amount of time, open a new issue to pitch +your idea before you get started. Explain the problem and describe the content you want to +see added to the documentation. Let us know if you'll write it yourself or if you'd like us +to help. We'll discuss your proposal with you and let you know whether we're likely to +accept it. + +## Bug Reports + +Bug reports are accepted through the [Issues][] page. + +Before Submitting: + +* Do a search through the existing issues to make sure it has not already been reported. + If it has, comment your experience or +1 so we prioritize it. +* If possible, upgrade to the latest release of the SDK. It's possible the bug has + already been fixed in the latest version. + +Writing the Bug Report: + +Please ensure that your bug report has the following: + +* A short, descriptive title. Ideally, other community members should be able to get a + good idea of the issue just from reading the title. +* A detailed description of the problem you're experiencing. This should include: + * Expected behavior of the SDK and the actual behavior exhibited. + * Any details of your application environment that may be relevant. + * Debug information, stack trace or logs. +* If you are able to create one, include a Minimal Working Example that reproduces the issue. +* Use Markdown to make the report easier to read; i.e. use code blocks when pasting a + code snippet. + +## Feature Requests + +Open an [issue][issues] with the following: + +* A short, descriptive title. Ideally, other community members should be able to get a + good idea of the feature just from reading the title. +* A detailed description of the the proposed feature. + * Why it should be added to the SDK. + * If possible, example code to illustrate how it should work. +* Use Markdown to make the request easier to read; +* If you intend to implement this feature, indicate that you'd like to the issue to be + assigned to you. + + +## Code Contributions + +Code contributions to the SDK are done through [Pull Requests][pull-requests]. The list below are guidelines to use when submitting pull requests. These are the +same set of guidelines that the core contributors use when submitting changes, and +we ask the same of all community contributions as well: + +1. The SDK is released under the [Apache license][license]. Any code you submit + will be released under that license. For substantial contributions, we may + ask you to sign a [Contributor License Agreement (CLA)][cla]. +2. We follow all of the relevant PSR recommendations from the [PHP Framework + Interop Group][php-fig]. Please submit code that follows these standards. + The [PHP CS Fixer][cs-fixer] tool can be helpful for formatting your code. +3. We maintain a high percentage of code coverage in our unit tests. If you make + changes to the code, please add, update, and/or remove tests as appropriate. +4. Static code analysis with [PHPStan][phpstan] is automatically run on the `src` + directory for submitted pull requests. If there is a case that needs to be + ignored by static analysis, please update the `ignoreErrors` section in the + `phpstan.neon` config file in your PR, and point out why this case warrants + ignoring. +5. If your code does not conform to the PSR standards, does not include adequate + tests, or does not contain a changelog document, we may ask you to update + your pull requests before we accept them. We also reserve the right to deny + any pull requests that do not align with our standards or goals. +6. If you would like to implement support for a significant feature that is not + yet available in the SDK, please talk to us beforehand to avoid any + duplication of effort. +7. We greatly appreciate contributions to our User Guide. The docs are written + as a [Sphinx][] website formatted with [reStructuredText][] (very similar to + Markdown). The User Guide is located in another repository. Please go to the + [awsdocs/aws-php-developers-guide](https://github.com/awsdocs/aws-php-developers-guide/). + repository to suggest edits for the User Guide. +8. If you are working on the SDK, make sure to check out the `Makefile` for some + of the common tasks that we have to do. + + +[issues]: https://github.com/aws/aws-sdk-php-laravel/issues +[pull-requests]: https://github.com/aws/aws-sdk-php-laravel/pulls +[license]: http://aws.amazon.com/apache2.0/ +[cla]: https://github.com/aws/aws-cla/blob/master/amazon-single-contribution-license.txt +[php-fig]: http://php-fig.org +[cs-fixer]: http://cs.sensiolabs.org/ +[phpstan]: https://github.com/phpstan/phpstan +[sphinx]: http://sphinx-doc.org/ +[restructuredtext]: http://sphinx-doc.org/rest.html diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f474a25 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +test: remove-deps + make test-laravel + make test-lumen + +test-laravel: + composer require laravel/framework + vendor/bin/phpunit + make uninstall-laravel + +test-lumen: + composer require laravel/lumen-framework + vendor/bin/phpunit + make uninstall-lumen + +remove-deps: + rm -rf vendor + rm composer.lock + +uninstall-laravel: + make remove-deps + composer remove laravel/framework + make remove-deps + +uninstall-lumen: + make remove-deps + composer remove laravel/lumen-framework + make remove-deps + +# Ensures that the TAG variable was passed to the make command +check-tag: + $(if $(TAG),,$(error TAG is not defined. Pass via "make tag TAG=4.2.1")) + +# Creates a release but does not push it. This task updates the changelog +# with the TAG environment variable, replaces the VERSION constant, ensures +# that the source is still valid after updating, commits the changelog and +# updated VERSION constant, creates an annotated git tag using chag, and +# prints out a diff of the last commit. +tag: check-tag + @echo Tagging $(TAG) + chag update $(TAG) + sed -i '' -e "s/VERSION = '.*'/VERSION = '$(TAG)'/" src/AwsServiceProvider.php + php -l src/AwsServiceProvider.php + git commit -a -m '$(TAG) release' + chag tag + @echo "Release has been created. Push using 'make release'" + @echo "Changes made in the release commit" + git diff HEAD~1 HEAD diff --git a/README.md b/README.md index 223addd..ea66dd0 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,37 @@ -# AWS Service Provider for Laravel 4 +# AWS Service Provider for Laravel 6 - 12 -[![Latest Stable Version](https://poser.pugx.org/aws/aws-sdk-php-laravel/v/stable.png)](https://packagist.org/packages/aws/aws-sdk-php-laravel) -[![Total Downloads](https://poser.pugx.org/aws/aws-sdk-php-laravel/downloads.png)](https://packagist.org/packages/aws/aws-sdk-php-laravel) +[![Latest Stable Version](https://img.shields.io/packagist/v/aws/aws-sdk-php-laravel.svg)](https://packagist.org/packages/aws/aws-sdk-php-laravel) +[![Total Downloads](https://img.shields.io/packagist/dt/aws/aws-sdk-php-laravel.svg)](https://packagist.org/packages/aws/aws-sdk-php-laravel) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/aws/aws-sdk-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) -A simple [Laravel 4](http://four.laravel.com/) service provider for including the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php). +This is a simple [Laravel](http://laravel.com/) service provider for making it easy to include the official +[AWS SDK for PHP](https://github.com/aws/aws-sdk-php) in your Laravel and Lumen applications. -## Installation +This README is for version 3.x of the service provider, which is implemented to work with Version 3 of the AWS SDK for +PHP and Laravel 6-12. +**Major Versions:** + +* **3.x** (YOU ARE HERE) - For `laravel/framework:6.0|7.0|8.0|9.0|10.0|11.0|12.0` and `aws/aws-sdk-php:^3.338.0` +* **2.x** ([2.0 branch](https://github.com/aws/aws-sdk-php-laravel/tree/2.0)) - For `laravel/framework:5.0.*` and `aws/aws-sdk-php:~2.4` +* **1.x** ([1.0 branch](https://github.com/aws/aws-sdk-php-laravel/tree/1.0)) - For `laravel/framework:4.*` and `aws/aws-sdk-php:~2.4` + +Jump To: +* [Getting Started](#Getting-Started) +* [Getting Help](#Getting-Help) +* [Contributing](#Contributing) +* [More Resources](#Resources) + +## Getting Started + +### Installation The AWS Service Provider can be installed via [Composer](http://getcomposer.org) by requiring the `aws/aws-sdk-php-laravel` package in your project's `composer.json`. ```json { "require": { - "aws/aws-sdk-php-laravel": "1.*" + "aws/aws-sdk-php-laravel": "~3.0" } } ``` @@ -23,52 +41,82 @@ Then run a composer update php composer.phar update ``` -## Configuration +To use the AWS Service Provider, you must register the provider when bootstrapping your application. -To use the AWS Service Provider, you must register the provider when bootstrapping your Laravel application. -Publish the package configuration using Artisan. - -```sh -php artisan config:publish aws/aws-sdk-php-laravel -``` - -Update your settings in the generated `app/config/packages/aws/aws-sdk-php-laravel` configuration file. +#### Lumen +In Lumen find the `Register Service Providers` in your `bootstrap/app.php` and register the AWS Service Provider. ```php -return array( - 'key' => 'YOUR_AWS_ACCESS_KEY_ID', - 'secret' => 'YOUR_AWS_SECRET_KEY', - 'region' => 'us-east-1', - 'config_file' => null, -); + $app->register(Aws\Laravel\AwsServiceProvider::class); ``` -Find the `providers` key in your `app/config/app.php` and register the AWS Service Provider. +#### Laravel +In Laravel find the `providers` key in your `config/app.php` and register the AWS Service Provider. ```php 'providers' => array( // ... - 'Aws\Laravel\AwsServiceProvider', + Aws\Laravel\AwsServiceProvider::class, ) ``` -Find the `aliases` key in your `app/config/app.php` and add the AWS facade alias. +Find the `aliases` key in your `config/app.php` and add the AWS facade alias. ```php 'aliases' => array( // ... - 'AWS' => 'Aws\Laravel\AwsFacade', + 'AWS' => Aws\Laravel\AwsFacade::class, ) ``` -## Usage +### Configuration + +By default, the package uses the following environment variables to auto-configure the plugin without modification: +``` +AWS_ACCESS_KEY_ID +AWS_SECRET_ACCESS_KEY +AWS_REGION (default = us-east-1) +``` -In order to use the AWS SDK for PHP within your app, you need to retrieve it from the [Laravel IoC -Container](http://four.laravel.com/docs/ioc). The following example uses the Amazon S3 client to upload a file. +To customize the configuration file, publish the package configuration using Artisan. + +```sh +php artisan vendor:publish --provider="Aws\Laravel\AwsServiceProvider" +``` + +The settings can be found in the generated `config/aws.php` configuration file. By default, the credentials and region settings will pull from your `.env` file. ```php -$s3 = App::make('aws')->get('s3'); +return [ + 'credentials' => [ + 'key' => env('AWS_ACCESS_KEY_ID', ''), + 'secret' => env('AWS_SECRET_ACCESS_KEY', ''), + ], + 'region' => env('AWS_REGION', 'us-east-1'), + 'version' => 'latest', + // You can override settings for specific services + 'Ses' => [ + 'region' => 'us-east-1', + ], +]; +``` + +Note that you can always delete the `credentials` line from this file if you'd like to use the [default SDK Configuration Provider chain](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html#default-credential-chain) instead. + +Referring Laravel 5.2.0 [Upgrade guide](https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0), you must using config +file instead of environment variable option if using php artisan `config:cache`. + +Learn more about [configuring the SDK](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html) on +the SDK's User Guide. + +### Usage + +In order to use the AWS SDK for PHP within your app, you need to retrieve it from the [Laravel Service +Container](https://laravel.com/docs/container#binding). The following example uses the Amazon S3 client to upload a file. + +```php +$s3 = App::make('aws')->createClient('s3'); $s3->putObject(array( 'Bucket' => 'YOUR_BUCKET', 'Key' => 'YOUR_OBJECT_KEY', @@ -80,7 +128,18 @@ If the AWS facade is registered within the `aliases` section of the application following technique. ```php -$s3 = AWS::get('s3'); +$s3 = AWS::createClient('s3'); +$s3->putObject(array( + 'Bucket' => 'YOUR_BUCKET', + 'Key' => 'YOUR_OBJECT_KEY', + 'SourceFile' => '/the/path/to/the/file/you/are/uploading.ext', +)); +``` + +To use in Lumen, you need to retrieve it from the service container a bit differently: + +```php +$s3 = app('aws')->createClient('s3'); $s3->putObject(array( 'Bucket' => 'YOUR_BUCKET', 'Key' => 'YOUR_OBJECT_KEY', @@ -88,10 +147,31 @@ $s3->putObject(array( )); ``` -## Links +## Getting Help + +Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests and have limited bandwidth to address them. + +* Ask a question on [StackOverflow](https://stackoverflow.com/) and tag it with [`aws-php-sdk`](http://stackoverflow.com/questions/tagged/aws-php-sdk) +* Come join the AWS SDK for PHP [gitter](https://gitter.im/aws/aws-sdk-php) +* Open a support ticket with [AWS Support](https://console.aws.amazon.com/support/home/) +* If it turns out that you may have found a bug, please [open an issue](https://github.com/aws/aws-sdk-php-laravel/issues/new/choose) + +This SDK implements AWS service APIs. For general issues regarding the AWS services and their limitations, you may also take a look at the [Amazon Web Services Discussion Forums](https://forums.aws.amazon.com/). + +### Opening Issues + +If you encounter a bug with `aws-sdk-php-laravel` we would like to hear about it. Search the existing issues and try to make sure your problem doesn’t already exist before opening a new issue. It’s helpful if you include the version of `aws-sdk-php-laravel`, PHP version and OS you’re using. Please include a stack trace and reduced repro case when appropriate, too. + +The GitHub issues are intended for bug reports and feature requests. For help and questions with using `aws-sdk-php` please make use of the resources listed in the Getting Help section. There are limited resources available for handling issues and by keeping the list of open issues lean we can respond in a timely manner. + +## Contributing + +We work hard to provide a high-quality and useful SDK for our AWS services, and we greatly value feedback and contributions from our community. Please review our [contributing guidelines](./CONTRIBUTING.md) before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your bug report or contribution. + +## Resources -* [AWS SDK for PHP on Github](http://github.com/aws/aws-sdk-php) +* [AWS SDK for PHP on Github](http://github.com/aws/aws-sdk-php/) * [AWS SDK for PHP website](http://aws.amazon.com/sdkforphp/) -* [AWS on Packagist](https://packagist.org/packages/aws) +* [AWS on Packagist](https://packagist.org/packages/aws/) * [License](http://aws.amazon.com/apache2.0/) -* [Laravel website](http://laravel.com) +* [Laravel website](http://laravel.com/) diff --git a/composer.json b/composer.json index c4c8849..6749389 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "aws/aws-sdk-php-laravel", - "homepage": "http://aws.amazon.com/sdkforphp2", - "description": "A simple Laravel 4 service provider for including the AWS SDK for PHP.", - "keywords": ["laravel","laravel 4","aws","amazon","sdk","s3","ec2","dynamodb"], + "homepage": "https://aws.amazon.com/sdk-for-php/", + "description": "A simple Laravel 6/7/8/9/10/11/12 service provider for including the AWS SDK for PHP.", + "keywords": ["laravel", "laravel 6", "laravel 7", "laravel 8", "laravel 9", "laravel 10", "laravel 11", "laravel 12", "aws", "amazon", "sdk", "s3", "ec2", "dynamodb"], "type":"library", "license":"Apache-2.0", "authors":[ @@ -12,15 +12,33 @@ } ], "require": { - "php": ">=5.3.3", - "aws/aws-sdk-php": "~2.2", - "illuminate/foundation": "4.*", - "illuminate/support": "4.*" + "php": ">=8.1", + "aws/aws-sdk-php": "^3.338.0", + "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0" }, "require-dev": { - "phpunit/phpunit": "3.7.*" + "phpunit/phpunit": "^8.0 || ^9.0", + "vlucas/phpdotenv": "^1.0 || ^2.0 || ^3.0 || ^4.0 || ^5.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "suggest": { + "laravel/framework": "To test the Laravel bindings", + "laravel/lumen-framework": "To test the Lumen bindings" }, "autoload": { - "psr-0": { "Aws\\Laravel": "src/" } + "psr-4": { "Aws\\Laravel\\": "src/" } + }, + "autoload-dev": { + "psr-4": { "Aws\\Laravel\\Test\\": "tests/" } + }, + "extra": { + "laravel": { + "providers": [ + "Aws\\Laravel\\AwsServiceProvider" + ], + "aliases": { + "AWS": "Aws\\Laravel\\AwsFacade" + } + } } } diff --git a/config/aws_default.php b/config/aws_default.php new file mode 100644 index 0000000..8d02f8d --- /dev/null +++ b/config/aws_default.php @@ -0,0 +1,25 @@ + env('AWS_REGION', 'us-east-1'), + 'version' => 'latest', + 'ua_append' => [ + 'L5MOD/' . AwsServiceProvider::VERSION, + ], +]; diff --git a/config/aws_publish.php b/config/aws_publish.php new file mode 100644 index 0000000..cae7408 --- /dev/null +++ b/config/aws_publish.php @@ -0,0 +1,28 @@ + [ + 'key' => env('AWS_ACCESS_KEY_ID', ''), + 'secret' => env('AWS_SECRET_ACCESS_KEY', ''), + ], + 'region' => env('AWS_REGION', 'us-east-1'), + 'version' => 'latest', + 'ua_append' => [ + 'L5MOD/' . AwsServiceProvider::VERSION, + ], +]; diff --git a/phpunit.xml b/phpunit.xml index 4ec0310..59a93f6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,14 +1,13 @@ + stopOnFailure="false"> @@ -16,12 +15,19 @@ - - + + + + + + + + src - - vendor - - - + + + vendor + + + diff --git a/src/Aws/Laravel/AwsFacade.php b/src/Aws/Laravel/AwsFacade.php deleted file mode 100644 index cf05f7d..0000000 --- a/src/Aws/Laravel/AwsFacade.php +++ /dev/null @@ -1,35 +0,0 @@ -app['aws'] = $this->app->share(function ($app) { - // Retrieve the config - $config = $app['config']['aws'] ?: $app['config']['aws::config']; - if (isset($config['config_file'])) { - $config = $config['config_file']; - } - - // Instantiate the AWS service builder - $aws = Aws::factory($config); - - // Attach an event listener that will append the Laravel and module version numbers to the user agent string - $aws->getEventDispatcher()->addListener('service_builder.create_client', function (Event $event) { - $clientConfig = $event['client']->getConfig(); - $commandParams = $clientConfig->get(Client::COMMAND_PARAMS) ?: array(); - $userAgentSuffix = 'Laravel/' . Application::VERSION . ' L4MOD/' . AwsServiceProvider::VERSION; - $clientConfig->set(Client::COMMAND_PARAMS, array_merge_recursive($commandParams, array( - UserAgentListener::OPTION => $userAgentSuffix, - ))); - }); - - return $aws; - }); - } - - /** - * Bootstrap the application events. - * - * @return void - */ - public function boot() - { - $this->package('aws/aws-sdk-php-laravel', 'aws'); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array('aws'); - } -} diff --git a/src/AwsFacade.php b/src/AwsFacade.php new file mode 100644 index 0000000..672c2af --- /dev/null +++ b/src/AwsFacade.php @@ -0,0 +1,24 @@ +app instanceof LaravelApplication && $this->app->runningInConsole()) { + $this->publishes( + [__DIR__.'/../config/aws_publish.php' => config_path('aws.php')], + 'aws-config' + ); + } elseif ($this->app instanceof LumenApplication) { + $this->app->configure('aws'); + } + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom( + __DIR__.'/../config/aws_default.php', + 'aws' + ); + + $this->app->singleton('aws', function ($app) { + $config = $app->make('config')->get('aws'); + + return new Sdk($config); + }); + + $this->app->alias('aws', 'Aws\Sdk'); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return ['aws', 'Aws\Sdk']; + } + +} diff --git a/src/config/config.php b/src/config/config.php deleted file mode 100644 index 2d89954..0000000 --- a/src/config/config.php +++ /dev/null @@ -1,67 +0,0 @@ - 'YOUR_AWS_ACCESS_KEY_ID', - 'secret' => 'YOUR_AWS_SECRET_KEY', - - /* - |-------------------------------------------------------------------------- - | AWS Region - |-------------------------------------------------------------------------- - | - | Many AWS services are available in multiple regions. You should specify - | the AWS region you would like to use, but please remember that not every - | service is available in every region. - | - | These are the regions: us-east-1, us-west-1, us-west-2, us-gov-west-1 - | eu-west-1, sa-east-1, ap-northeast-1, ap-southeast-1, ap-southeast-2 - | - */ - 'region' => 'us-east-1', - - /* - |-------------------------------------------------------------------------- - | AWS Config File Location - |-------------------------------------------------------------------------- - | - | Instead of specifying your credentials and region here, you can specify - | the location of an AWS SDK for PHP config file to use. These files provide - | more granular control over what credentials and regions you are using for - | each service. If you specify a filepath for this configuration setting, - | the others in this file will be ignored. See the SDK user guide for more - | information: http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/configuration.html#using-a-custom-configuration-file - | - */ - 'config_file' => null, - -); diff --git a/tests/Aws/Laravel/Test/AwsFacadeTest.php b/tests/Aws/Laravel/Test/AwsFacadeTest.php deleted file mode 100644 index a117151..0000000 --- a/tests/Aws/Laravel/Test/AwsFacadeTest.php +++ /dev/null @@ -1,38 +0,0 @@ -setupApplication(); - $this->setupServiceProvider($app); - - // Mount facades - AWS::setFacadeApplication($app); - - // Get an instance of a client (S3) via its facade - $s3 = AWS::get('s3'); - $this->assertInstanceOf('Aws\S3\S3Client', $s3); - } -} diff --git a/tests/Aws/Laravel/Test/AwsServiceProviderTest.php b/tests/Aws/Laravel/Test/AwsServiceProviderTest.php deleted file mode 100644 index 288325e..0000000 --- a/tests/Aws/Laravel/Test/AwsServiceProviderTest.php +++ /dev/null @@ -1,71 +0,0 @@ -setupApplication(); - $this->setupServiceProvider($app); - - // Simulate global config; specify config file - $app['config']->set('aws', array( - 'config_file' => __DIR__ . '/test_services.json' - )); - - // Get an instance of a client (S3) - /** @var $s3 \Aws\S3\S3Client */ - $s3 = $app['aws']->get('s3'); - $this->assertInstanceOf('Aws\S3\S3Client', $s3); - - // Verify that the client received the credentials from the global config - $this->assertEquals('change_me', $s3->getCredentials()->getAccessKeyId()); - $this->assertEquals('change_me', $s3->getCredentials()->getSecretKey()); - - // Make sure the user agent contains Laravel information - $command = $s3->getCommand('ListBuckets'); - $request = $command->prepare(); - $s3->dispatch('command.before_send', array('command' => $command)); - $this->assertRegExp('/.+Laravel\/.+L4MOD\/.+/', (string) $request->getHeader('User-Agent')); - } - - public function testRegisterAwsServiceProviderWithPackageConfig() - { - $app = $this->setupApplication(); - $this->setupServiceProvider($app); - - // Get an instance of a client (S3) - /** @var $s3 \Aws\S3\S3Client */ - $s3 = $app['aws']->get('s3'); - $this->assertInstanceOf('Aws\S3\S3Client', $s3); - - // Verify that the client received the credentials from the package config - $this->assertEquals('YOUR_AWS_ACCESS_KEY_ID', $s3->getCredentials()->getAccessKeyId()); - $this->assertEquals('YOUR_AWS_SECRET_KEY', $s3->getCredentials()->getSecretKey()); - } - - public function testServiceNameIsProvided() - { - $app = $this->setupApplication(); - $provider = $this->setupServiceProvider($app); - $this->assertContains('aws', $provider->provides()); - } -} diff --git a/tests/Aws/Laravel/Test/AwsServiceProviderTestCase.php b/tests/Aws/Laravel/Test/AwsServiceProviderTestCase.php deleted file mode 100644 index 0467b8e..0000000 --- a/tests/Aws/Laravel/Test/AwsServiceProviderTestCase.php +++ /dev/null @@ -1,57 +0,0 @@ -instance('path', 'foobar'); - $app->instance('files', new Filesystem); - $app->instance('config', new Repository($app->getConfigLoader(), 'foobar')); - - return $app; - } - - /** - * @param Application $app - * - * @return AwsServiceProvider - */ - protected function setupServiceProvider(Application $app) - { - // Create and register the provider - $provider = new AwsServiceProvider($app); - $app->register($provider); - $provider->boot(); - - return $provider; - } -} diff --git a/tests/Aws/Laravel/Test/test_services.json b/tests/Aws/Laravel/Test/test_services.json deleted file mode 100644 index 5a2778d..0000000 --- a/tests/Aws/Laravel/Test/test_services.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "includes": ["_aws"], - "services": { - "default_settings": { - "params": { - "key": "change_me", - "secret": "change_me", - "region": "us-east-1", - "ssl.certificate_authority": true - } - }, - "cloudfront": { - "extends": "cloudfront", - "params": { - "private_key": "change_me", - "key_pair_id": "change_me" - } - } - } -} diff --git a/tests/AwsServiceProviderTest.php b/tests/AwsServiceProviderTest.php new file mode 100644 index 0000000..69dd42f --- /dev/null +++ b/tests/AwsServiceProviderTest.php @@ -0,0 +1,82 @@ +setupApplication(); + $this->setupServiceProvider($app); + + // Mount facades + AWS::setFacadeApplication($app); + + // Get an instance of a client (S3) via the facade. + $s3 = AWS::createClient('S3'); + $this->assertInstanceOf('Aws\S3\S3Client', $s3); + } + + public function testRegisterAwsServiceProviderWithPackageConfigAndEnv() + { + $app = $this->setupApplication(); + $this->setupServiceProvider($app); + + // Get an instance of a client (S3). + /** @var $s3 \Aws\S3\S3Client */ + $s3 = $app['aws']->createClient('S3'); + $this->assertInstanceOf('Aws\S3\S3Client', $s3); + + // Verify that the client received the credentials from the package config. + /** @var \Aws\Credentials\CredentialsInterface $credentials */ + $credentials = $s3->getCredentials()->wait(); + $this->assertEquals('foo', $credentials->getAccessKeyId()); + $this->assertEquals('bar', $credentials->getSecretKey()); + $this->assertEquals('baz', $s3->getRegion()); + } + + public function testServiceNameIsProvided() + { + $app = $this->setupApplication(); + $provider = $this->setupServiceProvider($app); + $this->assertContains('aws', $provider->provides()); + } + + public function testVersionInformationIsProvidedToSdkUserAgent() + { + $app = $this->setupApplication(); + $this->setupServiceProvider($app); + $config = $app['config']->get('aws'); + + $this->assertArrayHasKey('ua_append', $config); + $this->assertIsArray($config['ua_append']); + $this->assertNotEmpty($config['ua_append']); + $this->assertNotEmpty(array_filter($config['ua_append'], function ($ua) { + return false !== strpos($ua, AwsServiceProvider::VERSION); + })); + } + + /** + * @return Container + */ + abstract protected function setupApplication(); + + /** + * @param Container $app + * + * @return AwsServiceProvider + */ + private function setupServiceProvider(Container $app) + { + // Create and register the provider. + $provider = new AwsServiceProvider($app); + $app->register($provider); + $provider->boot(); + + return $provider; + } +} diff --git a/tests/LaravelAwsServiceProviderTest.php b/tests/LaravelAwsServiceProviderTest.php new file mode 100644 index 0000000..dc20c09 --- /dev/null +++ b/tests/LaravelAwsServiceProviderTest.php @@ -0,0 +1,20 @@ +markTestSkipped(); + } + // Create the application such that the config is loaded. + $app = new Application(); + $app->setBasePath(sys_get_temp_dir()); + $app->instance('config', new Repository()); + + return $app; + } +} diff --git a/tests/LumenAwsServiceProviderTest.php b/tests/LumenAwsServiceProviderTest.php new file mode 100644 index 0000000..e623346 --- /dev/null +++ b/tests/LumenAwsServiceProviderTest.php @@ -0,0 +1,20 @@ +markTestSkipped(); + } + // Create the application such that the config is loaded. + $app = new Application(sys_get_temp_dir()); + $app->instance('config', new Repository()); + + return $app; + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index e9bc16e..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,12 +0,0 @@ - pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy