-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
=refactoring, tests improved, psr2 support
- Loading branch information
Showing
33 changed files
with
1,599 additions
and
1,816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/doc | ||
/build | ||
/.idea | ||
/tests1 | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 61 additions & 61 deletions
122
src/LaravelCommode/Common/CommodeCommonServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,76 @@ | ||
<?php namespace LaravelCommode\Common; | ||
<?php | ||
|
||
use Illuminate\Foundation\AliasLoader; | ||
use LaravelCommode\Common\Constants\ServiceShortCuts; | ||
use LaravelCommode\Common\GhostService\GhostService; | ||
use LaravelCommode\Common\GhostService\GhostServices; | ||
use LaravelCommode\Common\Resolver\Resolver; | ||
use Illuminate\Support\ServiceProvider; | ||
namespace LaravelCommode\Common; | ||
|
||
use Illuminate\Foundation\AliasLoader; | ||
use LaravelCommode\Common\Constants\ServiceShortCuts; | ||
use LaravelCommode\Common\GhostService\GhostService; | ||
use LaravelCommode\Common\GhostService\GhostServices; | ||
use LaravelCommode\Common\Resolver\Resolver; | ||
|
||
/** | ||
* Class CommodeCommonServiceProvider | ||
* | ||
* Is a common service for all laravel-commode packages. | ||
* It binds Resolver and GhostService manager. | ||
* | ||
* @author Volynov Andrew | ||
* @package LaravelCommode\Common | ||
*/ | ||
class CommodeCommonServiceProvider extends GhostService | ||
{ | ||
protected $aliases = [ | ||
'CommodeResolver' => 'LaravelCommode\Common\Facades\Resolver' | ||
]; | ||
/** | ||
* Class CommodeCommonServiceProvider | ||
* Get the services provided by the provider. | ||
* | ||
* Is a common service for all laravel-commode packages. | ||
* It binds Resolver and GhostService manager. | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return [ServiceShortCuts::GHOST_SERVICE, ServiceShortCuts::RESOLVER_SERVICE]; | ||
} | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @author Volynov Andrew | ||
* @package LaravelCommode\Common | ||
* @return void | ||
*/ | ||
class CommodeCommonServiceProvider extends GhostService | ||
public function boot() | ||
{ | ||
protected $aliases = [ | ||
'CommodeResolver' => 'LaravelCommode\Common\Facades\Resolver' | ||
]; | ||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return [ServiceShortCuts::GHOST_SERVICE, ServiceShortCuts::RESOLVER_SERVICE]; | ||
} | ||
$this->package('laravel-commode/common', 'commode-common', __DIR__.'/../../'); | ||
} | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->package('laravel-commode/common', 'commode-common', __DIR__.'/../../'); | ||
} | ||
/** | ||
* Will be triggered when the app's 'booting' event is triggered | ||
*/ | ||
protected function launching() | ||
{ | ||
|
||
/** | ||
* Will be triggered when the app's 'booting' event is triggered | ||
*/ | ||
public function launching() { } | ||
} | ||
|
||
/** | ||
* Triggered when service is being registered | ||
*/ | ||
public function registering() | ||
{ | ||
$this->app->bindShared(ServiceShortCuts::RESOLVER_SERVICE, function() | ||
{ | ||
return new Resolver($this->app); | ||
}); | ||
/** | ||
* Triggered when service is being registered | ||
*/ | ||
protected function registering() | ||
{ | ||
$this->app->bindShared(ServiceShortCuts::RESOLVER_SERVICE, function () { | ||
return new Resolver($this->app); | ||
}); | ||
|
||
$this->app->bindShared(ServiceShortCuts::GHOST_SERVICE, function() | ||
{ | ||
return new GhostServices($this->app); | ||
}); | ||
$this->app->bindShared(ServiceShortCuts::GHOST_SERVICE, function () { | ||
return new GhostServices($this->app); | ||
}); | ||
|
||
$this->app->bind(ServiceShortCuts::CORE_INITIALIZED, true); | ||
$this->app->bind(ServiceShortCuts::CORE_INITIALIZED, true); | ||
|
||
$this->app->booting(function () | ||
{ | ||
$loader = AliasLoader::getInstance(); | ||
$this->app->booting(function () { | ||
$loader = AliasLoader::getInstance(); | ||
|
||
foreach($this->aliases as $facade => $facadeClass) | ||
{ | ||
$loader->alias($facade, $facadeClass); | ||
} | ||
}); | ||
} | ||
foreach ($this->aliases as $facade => $facadeClass) { | ||
$loader->alias($facade, $facadeClass); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
<?php | ||
namespace LaravelCommode\Common\Constants; | ||
namespace LaravelCommode\Common\Constants; | ||
|
||
/** | ||
* Class ServiceShortCuts | ||
* | ||
* Constant for IoC bindings. Very handy for further refactoring. | ||
* | ||
* @author Volynov Andrey | ||
* @package LaravelCommode\Common\Constants | ||
*/ | ||
class ServiceShortCuts | ||
{ | ||
const GHOST_SERVICE = 'commode.common.ghostservice'; | ||
const RESOLVER_SERVICE = 'commode.common.resolver'; | ||
const CORE_INITIALIZED = 'commode.common.loaded'; | ||
} | ||
/** | ||
* Class ServiceShortCuts | ||
* | ||
* Constant for IoC bindings. Very handy for further refactoring. | ||
* | ||
* @author Volynov Andrey | ||
* @package LaravelCommode\Common\Constants | ||
*/ | ||
class ServiceShortCuts | ||
{ | ||
const GHOST_SERVICE = 'commode.common.ghostservice'; | ||
const RESOLVER_SERVICE = 'commode.common.resolver'; | ||
const CORE_INITIALIZED = 'commode.common.loaded'; | ||
} |
146 changes: 70 additions & 76 deletions
146
src/LaravelCommode/Common/Controllers/CommodeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,84 @@ | ||
<?php | ||
namespace LaravelCommode\Common\Controllers; | ||
namespace LaravelCommode\Common\Controllers; | ||
|
||
use Illuminate\Routing\Controller; | ||
use LaravelCommode\Common\Constants\ServiceShortCuts; | ||
use LaravelCommode\Common\Resolver\Resolver; | ||
use Illuminate\Routing\Controller; | ||
use LaravelCommode\Common\Constants\ServiceShortCuts; | ||
|
||
/** | ||
* Class CommodeController | ||
* | ||
* CommodeController is a laravel controller wrapper with some extended possibilities. | ||
* It can resolve methods if protected $resolveMethods = true (true is the default value) | ||
* and separate ajax calls like calling ajaxgetIndex() if method | ||
* getIndex() exists, request is ajax and protected $separateRequests = true (false is the default value) | ||
* | ||
* @author Volynov Andrey | ||
* @package LaravelCommode\Common\Controllers | ||
*/ | ||
class CommodeController extends Controller | ||
{ | ||
/** | ||
* Class CommodeController | ||
* | ||
* CommodeController is a laravel controller wrapper with some extended possibilities. | ||
* It can resolve methods if protected $resolveMethods = true (true is the default value) | ||
* and separate ajax calls like calling ajax_getIndex() if method | ||
* getIndex() exists, request is ajax and protected $separateRequests = true (false is the default value) | ||
* | ||
* @author Volynov Andrey | ||
* @package LaravelCommode\Common\Controllers | ||
* Determines if called methods need to be resolved. | ||
* @var bool | ||
*/ | ||
class CommodeController extends Controller | ||
{ | ||
/** | ||
* Determines if called methods need to be resolved. | ||
* @var bool | ||
*/ | ||
protected $resolveMethods = true; | ||
protected $resolveMethods = true; | ||
|
||
/** | ||
* Determines if all ajax methods are prefixed with 'ajax_' | ||
* @var bool | ||
*/ | ||
protected $separateRequests = false; | ||
|
||
/** | ||
* Determines resolving is enabled. If it's enabled then | ||
* it returns method resolved parameters, otherwise it | ||
* returns parameters as they are. | ||
* | ||
* @param string $method Method name. | ||
* @param array $params Array of known parameters. | ||
* @return mixed | ||
*/ | ||
private function checkParametersResolving($method, $params = array()) | ||
{ | ||
if (!$this->resolveMethods) | ||
{ | ||
return $params; | ||
} | ||
/** | ||
* Determines if all ajax methods are prefixed with 'ajax' | ||
* @var bool | ||
*/ | ||
protected $separateRequests = false; | ||
|
||
$resolver = app(ServiceShortCuts::RESOLVER_SERVICE); | ||
return $resolver->resolveMethodParameters($this, $method, $params); | ||
/** | ||
* Determines resolving is enabled. If it's enabled then | ||
* it returns method resolved parameters, otherwise it | ||
* returns parameters as they are. | ||
* | ||
* @param string $method Method name. | ||
* @param array $params Array of known parameters. | ||
* @return mixed | ||
*/ | ||
private function checkParametersResolving($method, array $params = []) | ||
{ | ||
if (!$this->resolveMethods) { | ||
return $params; | ||
} | ||
|
||
/** | ||
* Determines ajax separation is enabled. If it's enabled then | ||
* it returns method's name prefixed with 'ajax', otherwise it | ||
* returns method's name as it is. | ||
* | ||
* @param string $method Method name. | ||
* @param bool|null $isAjax Determines if request is ajax. | ||
* @return string | ||
*/ | ||
private function checkAjaxMethod($method, $isAjax = null) | ||
{ | ||
$isAjax = is_null($isAjax) ? app('request')->ajax() : $isAjax; | ||
|
||
if ($this->separateRequests && $isAjax) | ||
{ | ||
return 'ajax_'.$method; | ||
} | ||
return app()->make(ServiceShortCuts::RESOLVER_SERVICE)->resolveMethodParameters($this, $method, $params); | ||
} | ||
|
||
return $method; | ||
/** | ||
* Determines ajax separation is enabled. If it's enabled then | ||
* it returns method's name prefixed with 'ajax', otherwise it | ||
* returns method's name as it is. | ||
* | ||
* @param string $method Method name. | ||
* @param bool|null $isAjax Determines if request is ajax. | ||
* @return string | ||
*/ | ||
private function checkAjaxMethod($method, $isAjax = null) | ||
{ | ||
if ($this->separateRequests && $isAjax) { | ||
return 'ajax'.$method; | ||
} | ||
|
||
/** | ||
* Calls controller action. | ||
* | ||
* @param string $method | ||
* @param array $params | ||
* @return mixed | ||
*/ | ||
public function callAction($method, $params = array()) | ||
{ | ||
$isAjax = app('request')->ajax(); | ||
return $method; | ||
} | ||
|
||
/** | ||
* Calls controller action. | ||
* | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
*/ | ||
public function callAction($method, array $parameters = []) | ||
{ | ||
$isAjax = app()->make('request')->ajax(); | ||
|
||
$method = $this->checkAjaxMethod($method, $isAjax); | ||
$params = $this->checkParametersResolving($method, $params); | ||
$method = $this->checkAjaxMethod($method, $isAjax); | ||
$parameters = $this->checkParametersResolving($method, $parameters); | ||
|
||
return parent::callAction($method, $params); | ||
} | ||
} | ||
return parent::callAction($method, $parameters); | ||
} | ||
} |
Oops, something went wrong.