Skip to content

Commit

Permalink
(feat): add Laravel 7.0 support (#45)
Browse files Browse the repository at this point in the history
* (feat): add Laravel 7 support

* (ci): migrate to GitHub Actions

* (feat): update dependencies
  • Loading branch information
Elhebert authored Feb 28, 2020
1 parent 631def8 commit c8e25c1
Show file tree
Hide file tree
Showing 8 changed files with 659 additions and 531 deletions.
9 changes: 2 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# 4 space indentation
[*.{html,php,json}]
indent_style = space
indent_size = 4

# 2 space indentation
[*.{js,css,scss,vue}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
38 changes: 38 additions & 0 deletions .github/workflow/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Run PHPUnit tests

on: [push]

jobs:
tests:
runs-on: ${{ matrix.os }}

strategy:
matrix:
php: [7.4, 7.3, 7.2]
laravel: [7.*, 6.*]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest, windows-latest]
include:
- laravel: 7.*
- laravel: 6.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
extension-csv: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:4.*" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Please read and understand the contribution guide before creating an issue or pu
## Pull Requests

Before submitting a pull request:

- Make sure to write tests!
- Document any change in behaviour. Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- One pull request per feature. If you want to do more than one thing, send multiple pull requests.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License
# MIT License

Copyright (c) 2017 Elhebert

Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![StyleCI](https://styleci.io/repos/119791861/shield?branch=master)](https://styleci.io/repos/119791861)
[![TravisCI](https://travis-ci.org/Elhebert/laravel-sri.svg?branch=master)](https://travis-ci.org/Elhebert/laravel-sri)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/elhebert/laravel-sri/phpunit?label=Tests&style=flat-square)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/elhebert/laravel-sri.svg?style=flat-square)](https://packagist.org/packages/elhebert/laravel-sri)
[![Total Downloads](https://img.shields.io/packagist/dt/elhebert/laravel-sri.svg?style=flat-square)](https://packagist.org/packages/elhebert/laravel-sri)

Small Laravel 6+ package that'll generate the integrity hashes for your style and script files.

Expand All @@ -11,14 +13,15 @@ For Laravel 5.5+ support, use the [v1 branch](https://github.com/Elhebert/larave
## About Subresources Integrity

From [MDN](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity):

> Subresource Integrity (SRI) is a security feature that enables browsers to verify that files they fetch (for example, from a CDN) are delivered without unexpected manipulation. It works by allowing you to provide a cryptographic hash that a fetched file must match.
Troy Hunt wrote an article speaking on the subject, you can read it [here](https://www.troyhunt.com/protecting-your-embedded-content-with-subresource-integrity-sri/)

## Installation

```sh
$ composer require elhebert/laravel-sri
composer require elhebert/laravel-sri
```

This package uses [auto-discovery](https://laravel.com/docs/5.5/packages#package-discovery), so you don't have to do anything. It works out of the box.
Expand All @@ -28,16 +31,16 @@ This package uses [auto-discovery](https://laravel.com/docs/5.5/packages#package
If you want ot make changes in the configuration you can publish the config file using

```sh
$ php artisan vendor:publish --provider="Elhebert\SubresourceIntegrity\SriServiceProvider"
php artisan vendor:publish --provider="Elhebert\SubresourceIntegrity\SriServiceProvider"
```

### Content of the configuration

| key | default value | possible values |
| - | - | - |
| base_path | `base_path('/public')` | |
| algorithm | sha256 | sha256, sha384 and sha512 |
| hashes | `[]` | (see "[How to get a hash](#how-to-get-a-hash)) |
| key | default value | possible values |
| ------------ | ----------------------------- | ---------------------------------------------- |
| base_path | `base_path('/public')` | |
| algorithm | sha256 | sha256, sha384 and sha512 |
| hashes | `[]` | (see "[How to get a hash](#how-to-get-a-hash)) |
| mix_sri_path | `public_path('mix-sri.json')` | (see "[How to get a hash](#how-to-get-a-hash)) |

## Usage
Expand All @@ -50,10 +53,11 @@ To only get a hash, use `Sri::hash`:
rel="stylesheet"
integrity="{{ Sri::hash('css/app.css') }}"
crossorigin="anonymous"
>
/>
```

To generate the HTML for the `integrity` and the `crossorigin` attributes, use `Sri::html`. It accepts two parameters:

- first one is the path;
- second one (default is `false`) tells if you want to pass the credentials when fetching the resource.

Expand All @@ -65,17 +69,18 @@ To generate the HTML for the `integrity` and the `crossorigin` attributes, use `
>
```


### Blade directive

Two blade directive are available to make your views cleaner:

Use `@mixSri` to generate the `<link>` or `<script>` tag with the proper attributes and using the `mix()` helper to generate the asset path:

```php
@mixSri(string $path, bool $useCredentials = 'false')
```

Use `@assetSri` to generate the `<link>` or `<script>` tag with the proper attributes and using the `asset()` helper to generate the asset path:

```php
@assetSri(string $path, bool $useCredentials = 'false')
```
Expand All @@ -102,10 +107,11 @@ This means, you have to calculate the hashes yourself. To do this, you can use [
### Using a webpack (or Mix) plugin to generate hashes on build

It expect a `mix-sri.json` file with a similar structure to the `mix-manifest.json`:

```json
{
"/css/app.css": "my_super_hash",
"/js/app.js": "my_super_hash",
"/js/app.js": "my_super_hash"
}
```

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
}
],
"require": {
"php": "^7.2",
"illuminate/support": "^6.0"
"php": "^7.2.5",
"illuminate/support": "^6.0 || ^7.0"
},
"require-dev": {
"orchestra/testbench": "^4.0",
Expand Down
Loading

0 comments on commit c8e25c1

Please sign in to comment.