Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Support for Web & Api Routes (any definition)
Browse files Browse the repository at this point in the history
  • Loading branch information
TiBianMod committed Nov 17, 2016
1 parent 3606c66 commit 8a484ad
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 143 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.idea/
*.txt
/.idea
/vendor
*.lock
*.DS_Store
.Spotlight-V100
.Trashes
.Trashes
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
}
],
"require": {
"tibian/resources": "0.1.*"
"php": ">=5.5.9",
"symfony/finder": "^v3.1"
},
"autoload": {
"psr-4": {
Expand Down
35 changes: 0 additions & 35 deletions config/route-organizer.php

This file was deleted.

56 changes: 32 additions & 24 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
## Route Organizer for Laravel
Route Organizer is simple route solution for Laravel.
Route Organizer for Laravel is simple route solution to organize your Routes.

### Install

Require this package with composer using the following command
```
composer require tibian/route-organizer
```
After updating composer, add the service provider to the providers array in config/app.php

### Usage

Open `App\Providers\RouteServiceProvider` on method `mapWebRoutes` / `mapApiRoutes` define new Routes for the Application.

```php
new RouteOrganizer('routes/web');
new RouteOrganizer('routes/api');
```
TiBian\RouteOrganizer\RouteOrganizerServiceProvider::class,

### Example for web routes
> ##### Note: The same you can do of course and for the api Routes
```php
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
new RouteOrganizer('routes/web'); // new Web Routes for the Application
require base_path('routes/web.php');
});
}
```

### Usage
The default Route path is `app/Http/Routes`,
now under this entry point you can organize your Routes like you wish.
> Now you can Organize your Routes as you wish.
> * The following example is the best if you use PHPStorm and Laravel Plugin
### Example
```
Routes (app/Http/Routes)
/path/to/laravel/routes/web
│ routes.php
└───Pages
└───Auth
│ routes.php
└───Auth
└───Blog
│ routes.php
└───Dashboard
Expand All @@ -32,24 +52,12 @@ Routes (app/Http/Routes)
│ └───Admin
│ routes.php
└───Blog
└───Pages
│ routes.php
└───etc...
```

### Config
You can also publish the config file to change it as you wish.
```
php artisan vendor:publish --provider="TiBian\RouteOrganizer\RouteOrganizerServiceProvider" --tag=config
```

### I'm looking for:
- Individuals who can contribute to the Documentation.
- Participation in other Open Source Projects.

> Visit my Web Site and learn more [about me](https://tibian.me)
##### Any idea for new projects, feel free to Contact me.

##### Thank you for visiting my Repository.
##### Thank you for visiting my Repository.
87 changes: 70 additions & 17 deletions src/RouteOrganizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace TiBian\RouteOrganizer;

use TiBian\Resources\Path;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

/**
* Class RouteOrganizer
Expand All @@ -17,39 +18,91 @@ class RouteOrganizer
protected $routePath;

/**
* RecursiveIteratorIterator
*
* @var object Path
* @var \Symfony\Component\Finder\Finder
*/
protected $path;
protected $finder;

/**
* Routes constructor.
* @var \Symfony\Component\Finder\SplFileInfo
*/
protected $file;

/**
* RouteOrganizer constructor.
*
* @param string $path
*/
public function __construct()
public function __construct($path)
{
$this->routePath = config('route-organizer.routePath');
$this->routePath = base_path($path);

$this->createRoutePath();
$this->finder = new Finder();

$this->path = new Path($this->routePath);
$this->createRoutePath();

$this->process();
}

private function createRoutePath()
/**
* Create Route Path
*/
protected function createRoutePath()
{
if (! file_exists($this->routePath)) {
mkdir($this->routePath, 0755);
mkdir($this->routePath, 0755, true);
}
}

private function process()
/**
* Process the Request
*/
protected function process()
{
collect($this->getResources())->each(function (SplFileInfo $file) {
$this->file = $file;

$this->requireRoute();
});
}

/**
* Require Route Files
*/
protected function requireRoute()
{
if ($this->isExtension('php')) {
$this->isRequired();
}
}

/**
* Get File Resources
*
* @return \Symfony\Component\Finder\Finder|\Symfony\Component\Finder\SplFileInfo[]
*/
protected function getResources()
{
return $this->finder->files()->in($this->routePath);
}

/**
* Checks if the file is a specific extension.
*
* @param string $extension
* @return bool
*/
protected function isExtension($extension)
{
return strtolower($this->file->getExtension()) == strtolower($extension);
}

/**
* Require/Include the specific File.
*/
protected function isRequired()
{
foreach ($this->path->getResources() as $r) {
if ($this->path->isExtension('php')) {
$this->path->isRequired();
}
if ($this->file->isFile()) {
require $this->file->getRealPath();
}
}
}
63 changes: 0 additions & 63 deletions src/RouteOrganizerServiceProvider.php

This file was deleted.

0 comments on commit 8a484ad

Please sign in to comment.