Skip to content

Commit

Permalink
Merge pull request #16 from vrkansagara/develop
Browse files Browse the repository at this point in the history
Code merge.
  • Loading branch information
vrkansagara authored Jan 8, 2019
2 parents 037126a + aa55c6e commit fcd605b
Show file tree
Hide file tree
Showing 12 changed files with 1,097 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/vendor/
.idea/*
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,41 @@ This is simply compress your final out of Larvel Application and serve to the br

### How to activate this compression middleware in your application

Update your `app/Http/Kernel.php` file with below line

~~~php
protected $middleware = [
...
\Vrkansagara\Http\Middleware\AfterMiddleware::class,
...
];
Add the ServiceProvider to the providers array in `config/app.php`

```php
Vrkansagara\LaraOutPress\ServiceProvider::class,
```

Copy the package config to your local config with the publish command:

```shell
php artisan vendor:publish --provider="Vrkansagara\LaraOutPress\ServiceProvider"
```

Enable on single environment `.env`

~~~bash
VRKANSAGARA_COMPRESS_ENVIRONMENT='${APP_ENV}'
~~~

Add your target environment into `.env`
Enable on multiple environment `.env`

~~~bash
VRKANSAGARA_COMPRESS_ENVIRONMENT='prod,testing,dev,local'

OR

VRKANSAGARA_COMPRESS_ENVIRONMENT='${APP_ENV}'
VRKANSAGARA_COMPRESS_ENVIRONMENT='prod,testing,dev,local'
~~~


If you want to see how much you compress on each page, set bellow line in `.env`
Enable this compressor by placing bellow code in `.env` file.

~~~bash
VRKANSAGARA_COMPRESS_DEBUG = 0
VRKANSAGARA_COMPRESS_ENABLED = true
~~~


### Display usage on each page.

Set ` $debug = 1; ` in ` AfterMiddleware.php `


### TO Do List

- [x] Compress browser output.
Expand All @@ -53,8 +56,9 @@ Set ` $debug = 1; ` in ` AfterMiddleware.php `
### Task

- [x] Add analytics before compress and after compress.
- [x] Migrate code to laravel package format.

### Code Assumption
This code is developed with the mind set of each request is filtered by this middleware. So most of the code will not be flexi.

Improvement and suggestion are always welcome.
Improvement and suggestion are always welcome.
37 changes: 34 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,41 @@
},
"autoload": {
"psr-4": {
"Vrkansagara\\": "src/"
}
"Vrkansagara\\LaraOutPress\\": "src/"
},
"files": [
"src/helper.php"
]
},
"support": {
"email": "[email protected]"
"email": "[email protected]",
"issues": "https://github.com/vrkansagara/LaraOutPress/issues",
"source": "https://github.com/vrkansagara/LaraOutPress"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"laravel": {
"branch-alias": {
"dev-master": "develop"
},
"providers": [
"Vrkansagara\\LaraOutPress\\ServiceProvider"
],
"aliases": {
"LaraOutPress": "Vrkansagara\\LaraOutPress\\Facade"
}
}
},
"require": {
"php": ">=7.0"
},
"require-dev": {
"laravel/framework": "5.5.x"
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
]
}
}
18 changes: 18 additions & 0 deletions config/laraoutpress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| LaraOutPress Settings
|--------------------------------------------------------------------------
|
| LaraOutPress is disabled by default, when enabled is set to true in app.php.
| You can override the value by setting enable to true or false instead of null.
|
*/
'enabled' => env('VRKANSAGARA_COMPRESS_ENABLED', false),

'debug' => env('VRKANSAGARA_COMPRESS_DEBUG', false),

'target_environment' => env('VRKANSAGARA_COMPRESS_ENVIRONMENT', '')

];
18 changes: 18 additions & 0 deletions src/Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace Vrkansagara\LaraOutPress;

/**
* @copyright Copyright (c) 2015-2019 Vallabh Kansagara <[email protected]>
* @license https://opensource.org/licenses/BSD-3-Clause New BSD License
*/

class Facade extends \Illuminate\Support\Facades\Facade
{
/**
* {@inheritDoc}
*/
protected static function getFacadeAccessor()
{
return LaraOutPress::class;
}
}
127 changes: 127 additions & 0 deletions src/LraOutPress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace Vrkansagara\LaraOutPress;

use Illuminate\Contracts\Foundation\Application;

/**
* @copyright Copyright (c) 2015-2019 Vallabh Kansagara <[email protected]>
* @license https://opensource.org/licenses/BSD-3-Clause New BSD License
*/
class LaraOutPress
{

/**
* The Laravel application instance.
*
* @var \Illuminate\Foundation\Application
*/
protected $app;

/**
* Normalized Laravel Version
*
* @var string
*/
protected $version;

/**
* True when enabled, false disabled an null for still unknown
*
* @var bool
*/
protected $enabled;


/**
* @var null
*/
protected $config;

/**
* @return string
*/
public function getVersion()
{
return $this->version;
}

/**
* @param string $version
*/
public function setVersion($version)
{
$this->version = $version;
}

/**
* @return \Illuminate\Foundation\Application
*/
public function getApp()
{
return $this->app;
}

/**
* @param \Illuminate\Foundation\Application $app
*/
public function setApp($app)
{
$this->app = $app;
}


/**
* @param Application $app
*/
public function __construct($app = null)
{
if (!$app) {
$app = app(); //Fallback when $app is not given
}
$this->setApp($app);
$this->setConfig();
$this->setEnabled();
$this->setVersion($app->version());
}

/**
* @return null
*/
public function getConfig()
{
return $this->config;
}

/**
* @param null $config
*/
public function setConfig()
{
$applicationConfig = $this->app['config'];
$this->config = $applicationConfig->get('laraoutpress');
}

/**
* @return bool
*/
public function isEnabled()
{
return $this->enabled;
}

/**
* @return bool
*/
public function setEnabled()
{
if ($this->enabled === null) {
$config = $this->config;
$configEnabled = value($config['enabled']);
$this->enabled = ($configEnabled && !$this->app->runningInConsole()) ? $configEnabled : false;
}
return $this->enabled;
}


}
Loading

0 comments on commit fcd605b

Please sign in to comment.