Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP support with foundation for PHP libraries to load third parties #40

Merged
merged 18 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

# PHP PSR-2 Coding Standards
# http://www.php-fig.org/psr/psr-2/
[*.php]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
64 changes: 64 additions & 0 deletions .github/workflows/php-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: PHP Code Linting

on:
push:
branches:
- main
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-lint.yml'
- '**.php'
- 'phpcs.xml.dist'
- 'phpmd.xml'
- 'phpstan.neon.dist'
- 'composer.json'
- 'composer.lock'
pull_request:
branches:
- main
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-lint.yml'
- '**.php'
- 'phpcs.xml.dist'
- 'phpmd.xml'
- 'phpstan.neon.dist'
- 'composer.json'
- 'composer.lock'
types:
- opened
- reopened
- synchronize

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
php-lint:
name: PHP
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Validate Composer configuration
run: composer validate

- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist --no-progress --no-interaction'

- name: PHP Lint
run: composer lint

- name: PHPStan
run: composer phpstan

- name: PHPMD
run: composer phpmd
54 changes: 54 additions & 0 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PHP Unit Testing

on:
push:
branches:
- main
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test.yml'
- '**.php'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
pull_request:
branches:
- main
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test.yml'
- '**.php'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
types:
- opened
- reopened
- synchronize

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
php-test:
name: PHP
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Validate Composer configuration
run: composer validate

- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist --no-progress --no-interaction'

- name: PHPUnit Test
run: composer test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
.DS_Store
lib/
lib/
vendor/
*.cache
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Third Party Capital is a resource that consolidates best practices for loading popular third-parties in a single place.

The project provides implementations that can be used in the following languages:
* JavaScript (see [`src` directory](./src))
* PHP (see [`inc` directory](./inc))

## Rationale

There is a large, cross-functional Chrome initiative that aims to improve third-party resource loading on the web. One part of this effort is to provide a default set of recommendations, or "components," to developers. These components will help developers sequence and fetch popular third-party resources at the right time to minimize their overall impact to page performance.
Expand Down
45 changes: 45 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "googlechromelabs/third-party-capital",
"description": "This package is a collection of classes and utilities that can be used to efficiently load third-party libraries into your PHP application.",
"type": "library",
"license": "Apache-2.0",
"require": {
"php": ">=7"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0",
"phpcompatibility/php-compatibility": "^9.3",
"phpmd/phpmd": "^2.9",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9",
"slevomat/coding-standard": "^8.9"
},
"scripts": {
"lint": "phpcs --standard=phpcs.xml.dist",
"format": "phpcbf --standard=phpcs.xml.dist",
"test": "phpunit -c phpunit.xml.dist --verbose",
"phpmd": "phpmd . text phpmd.xml",
"phpstan": "phpstan analyse --memory-limit=2048M"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"archive": {
"exclude": ["/.husky", "/config", "/src", "!/*.json"]
},
"autoload": {
"psr-4": {
"GoogleChromeLabs\\ThirdPartyCapital\\": "inc/"
}
},
"autoload-dev": {
"psr-4": {
"GoogleChromeLabs\\ThirdPartyCapital\\TestData\\": "tests/phpunit/testdata",
"GoogleChromeLabs\\ThirdPartyCapital\\TestUtils\\": "tests/phpunit/utils"
}
}
}

Loading
Loading