Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony BOTALLA committed Dec 2, 2019
0 parents commit 45c0eaa
Show file tree
Hide file tree
Showing 16 changed files with 608 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.idea
/vendor
/node_modules
package-lock.json
composer.phar
composer.lock
phpunit.xml
.phpunit.result.cache
.DS_Store
Thumbs.db
87 changes: 87 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

// Inspired from Laravel php_cs, converted to php-cs-fixer 2, and simplified.
// - https://github.com/laravel/framework/blob/5.4/.php_cs
// - http://cs.sensiolabs.org/
// - https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md
// Removed: phpdoc_no_package, phpdoc_summary

$excludes = [
'dist',
'node_modules',
'resources',
'vendor',
];

$rules = [
'@PSR2' => true,
'blank_line_after_opening_tag' => true,
'concat_space' => ['spacing' => 'none'],
'no_multiline_whitespace_around_double_arrow' => true,
'no_empty_statement' => true,
'simplified_null_return' => false,
'encoding' => true,
'single_blank_line_at_eof' => true,
'no_extra_consecutive_blank_lines' => true,
'no_spaces_after_function_name' => true,
'function_declaration' => true,
'include' => true,
'indentation_type' => true,
'no_alias_functions' => true,
'blank_line_after_namespace' => true,
'line_ending' => true,
'no_trailing_comma_in_list_call' => true,
'not_operator_with_successor_space' => false,
'lowercase_constants' => true,
'lowercase_keywords' => true,
'method_argument_space' => true,
'trailing_comma_in_multiline_array' => true,
'no_multiline_whitespace_before_semicolons' => true,
'single_import_per_statement' => true,
'no_leading_namespace_whitespace' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'object_operator_without_whitespace' => true,
'no_spaces_inside_parenthesis' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'phpdoc_no_access' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => false,
'phpdoc_trim' => true,
'phpdoc_no_alias_tag' => true,
'phpdoc_var_without_name' => true,
'no_leading_import_slash' => true,
'braces' => false,
'blank_line_before_return' => true,
'self_accessor' => true,
'array_syntax' => ['syntax' => 'short'],
'no_short_echo_tag' => true,
'full_opening_tag' => true,
'no_trailing_comma_in_singleline_array' => true,
'single_blank_line_before_namespace' => true,
'single_line_after_imports' => true,
'single_quote' => true,
'no_singleline_whitespace_before_semicolons' => true,
'cast_spaces' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'no_trailing_whitespace' => true,
'trim_array_spaces' => true,
'binary_operator_spaces' => ['align_equals' => false],
'unary_operator_spaces' => true,
'no_unused_imports' => true,
'visibility_required' => true,
'no_whitespace_in_blank_line' => true,
];

$finder = PhpCsFixer\Finder::create()
->name('*.php')
->exclude($excludes)
->ignoreDotFiles(true)
->in(__DIR__);

return PhpCsFixer\Config::create()
->setRules($rules)
->setFinder($finder)
->setUsingCache(true);
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Nova Redirect Manager

[![Travis](https://img.shields.io/travis/novius/laravel-nova-redirect-manager.svg?maxAge=1800&style=flat-square)](https://travis-ci.org/novius/laravel-nova-redirect-manager)
[![Packagist Release](https://img.shields.io/packagist/v/novius/laravel-nova-redirect-manager.svg?maxAge=1800&style=flat-square)](https://packagist.org/packages/novius/laravel-nova-redirect-manager)
[![Licence](https://img.shields.io/packagist/l/novius/laravel-nova-redirect-manager.svg?maxAge=1800&style=flat-square)](https://github.com/novius/laravel-nova-redirect-manager#licence)

This package provides a Nova Tool to manage redirects with [spatie/laravel-missing-page-redirector](https://github.com/spatie/laravel-missing-page-redirector).

## Installation

You can install the package via composer:

```sh
composer require novius/laravel-nova-redirects-manager
```

The package will automatically register itself.

Next, launch migrations :

```ssh
php artisan migrate
```

Next, you must register the `Spatie\MissingPageRedirector\RedirectsMissingPages` middleware :

```php
//app/Http/Kernel.php

protected $middleware = [
...
\Spatie\MissingPageRedirector\RedirectsMissingPages::class,
],
```

Next, register the Tool in `NovaServiceProvider` class :

```php
//app/Providers/NovaServiceProvider.php

public function tools()
{
return [
...,
new LaravelNovaRedirectManager(),
];
}
```

## Configuration

This package provides a configuration file whose values overwrite the configuration of `spatie/laravel-missing-page-redirector`.

You can publish the configuration file if you want to change these values :
```
php artisan vendor:publish --provider="Novius\LaravelNovaRedirectManager\RedirectManagerServiceProvider" --tag=config
```

You can also publish the migrations, lang and views :
```
php artisan vendor:publish --provider="Novius\LaravelNovaRedirectManager\RedirectManagerServiceProvider" --tag=migrations
php artisan vendor:publish --provider="Novius\LaravelNovaRedirectManager\RedirectManagerServiceProvider" --tag=lang
php artisan vendor:publish --provider="Novius\LaravelNovaRedirectManager\RedirectManagerServiceProvider" --tag=views
```

## Lint

Run php-cs with:

```sh
composer run-script lint
```

## Contributing

Contributions are welcome!
Leave an issue on Github, or create a Pull Request.


## Licence

This package is under [GNU Affero General Public License v3](http://www.gnu.org/licenses/agpl-3.0.html) or (at your option) any later version.
47 changes: 47 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "novius/laravel-nova-redirect-manager",
"description": "This package provides an interface to manage redirects with Nova",
"keywords": [
"laravel",
"nova",
"redirects"
],
"license": "AGPL-3.0-or-later",
"authors": [
{
"name": "Novius Agency",
"email": "[email protected]",
"homepage": "https://www.novius.com"
}
],
"require": {
"php": ">=7.2.0",
"spatie/laravel-missing-page-redirector": "^2.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.16.1"
},
"autoload": {
"psr-4": {
"Novius\\LaravelNovaRedirectManager\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Spatie\\MissingPageRedirector\\MissingPageRedirectorServiceProvider",
"Novius\\LaravelNovaRedirectManager\\RedirectManagerServiceProvider"
]
}
},
"scripts": {
"lint": [
"php-cs-fixer fix --config .php_cs -vv --diff --allow-risky=yes --dry-run"
]
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
26 changes: 26 additions & 0 deletions config/laravel-nova-redirects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

return [

/*
* This is the model used by the database redirector
*/
'redirector_model' => \Novius\LaravelNovaRedirectManager\Models\Redirect::class,

/*
* This is the nova resource used to manage Redirect items
*/
'redirect_nova_resource' => \Novius\LaravelNovaRedirectManager\Resources\Redirect::class,

/*
* This max length rule for Redirect item
*/
'redirect_url_max_length' => 1000,

/*
* This is the class responsible for providing the URLs which must be redirected.
* The only requirement for the redirector is that it needs to implement the
* `Spatie\MissingPageRedirector\Redirector\Redirector`-interface
*/
'redirector' => \Novius\LaravelNovaRedirectManager\Redirector\DatabaseRedirector::class,
];
33 changes: 33 additions & 0 deletions database/migrations/2019_12_02_093127_create_redirects_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRedirectsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('redirects', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('from');
$table->text('to');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('redirects');
}
}
11 changes: 11 additions & 0 deletions resources/lang/en/redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'redirect' => 'Redirect',
'redirects' => 'Redirects',
'from' => 'Original URL',
'to' => 'Redirection URL',
'relative_url_help' => 'Relative URL. Example : /your-url',
'url_help' => 'Absolute or relative URL. Examples : http(s)://www.website/your-url ou /your-url ',
'invalid_url' => 'The :attribute format is invalid.',
];
11 changes: 11 additions & 0 deletions resources/lang/fr/redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'redirect' => 'Redirection',
'redirects' => 'Redirections',
'from' => 'URL originale',
'to' => 'URL de redirection',
'relative_url_help' => 'URL relative. Exemple : /votre-url',
'url_help' => 'URL absolue ou relative. Exemples : http(s)://www.votresite/votre-url ou /votre-url ',
'invalid_url' => 'Le champ :attribute doit être une URL valide',
];
13 changes: 13 additions & 0 deletions resources/views/navigation.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<router-link tag="h3"
:to="{
name: 'index',
params: {
resourceName: 'redirects'
}
}"
class="cursor-pointer flex items-center font-normal dim text-white mb-6 text-base no-underline">
<svg class="sidebar-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20"><path fill="var(--sidebar-icon)" d="M5.41 16H18a2 2 0 0 0 2-2 1 1 0 0 1 2 0 4 4 0 0 1-4 4H5.41l2.3 2.3a1 1 0 0 1-1.42 1.4l-4-4a1 1 0 0 1 0-1.4l4-4a1 1 0 1 1 1.42 1.4L5.4 16zM6 8a2 2 0 0 0-2 2 1 1 0 0 1-2 0 4 4 0 0 1 4-4h12.59l-2.3-2.3a1 1 0 1 1 1.42-1.4l4 4a1 1 0 0 1 0 1.4l-4 4a1 1 0 0 1-1.42-1.4L18.6 8H6z"/></svg>
<span class="sidebar-label">
{{ trans('laravel-nova-redirect-manager::redirect.redirects') }}
</span>
</router-link>
18 changes: 18 additions & 0 deletions src/LaravelNovaRedirectManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Novius\LaravelNovaRedirectManager;

use Laravel\Nova\Tool;

class LaravelNovaRedirectManager extends Tool
{
/**
* Build the view that renders the navigation links for the tool.
*
* @return \Illuminate\View\View
*/
public function renderNavigation()
{
return view('laravel-nova-redirect-manager::navigation');
}
}
24 changes: 24 additions & 0 deletions src/Models/Redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Novius\LaravelNovaRedirectManager\Models;

use Illuminate\Database\Eloquent\Model;

/**
* Class Redirect
* @package Novius\LaravelNovaRedirectManager\Models
*
* @property string from
* @property string to
*/
class Redirect extends Model
{
protected $table = 'redirects';

protected $primaryKey = 'id';

protected $fillable = [
'from',
'to',
];
}
Loading

0 comments on commit 45c0eaa

Please sign in to comment.