├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── Teepluss │ └── Api │ │ ├── Api.php │ │ ├── ApiServiceProvider.php │ │ ├── Commands │ │ └── ApiCallCommand.php │ │ └── Facades │ │ └── API.php └── config │ └── config.php └── tests ├── .gitkeep └── ApiTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | .svn -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | 7 | before_script: 8 | - curl -s http://getcomposer.org/installer | php 9 | - php composer.phar install --dev 10 | 11 | script: phpunit -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2013 Pattanai Kawinvasin (Teepluss) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Laravel HMVC. 2 | 3 | > This package is no longer updated anymore, Now I've splited this package into 2. 4 | - [HMVC](https://github.com/teepluss/laravel4-hmvc) 5 | - [RESTful format](https://github.com/teepluss/laravel4-restable) 6 | 7 | API is a tool for making internal request (HMVC). 8 | 9 | ### Installation 10 | 11 | - [API on Packagist](https://packagist.org/packages/teepluss/api) 12 | - [API on GitHub](https://github.com/teepluss/laravel4-api) 13 | 14 | To get the lastest version of Theme simply require it in your `composer.json` file. 15 | 16 | ~~~ 17 | "teepluss/api": "dev-master" 18 | ~~~ 19 | 20 | You'll then need to run `composer install` to download it and have the autoloader updated. 21 | 22 | Once Theme is installed you need to register the service provider with the application. Open up `app/config/app.php` and find the `providers` key. 23 | 24 | ~~~ 25 | 'providers' => array( 26 | 27 | 'Teepluss\Api\ApiServiceProvider' 28 | 29 | ) 30 | ~~~ 31 | 32 | API also ships with a facade which provides the static syntax for creating collections. You can register the facade in the `aliases` key of your `app/config/app.php` file. 33 | 34 | ~~~ 35 | 'aliases' => array( 36 | 37 | 'API' => 'Teepluss\Api\Facades\API' 38 | 39 | ) 40 | ~~~ 41 | 42 | Publish config using artisan CLI. 43 | 44 | ~~~ 45 | php artisan config:publish teepluss/api 46 | ~~~ 47 | 48 | ## Usage 49 | 50 | API helping you to work with internal request. 51 | 52 | - [Internal testing request](#internal-testing-request) 53 | - [Calling via artisan CLI](#calling-via-artisan-cli) 54 | - [Create reponses format for RESTful](#create-reponses-format-for-restful) 55 | 56 | ### Internal testing request. 57 | 58 | ~~~php 59 | // GET Request. 60 | API::get('user/1'); 61 | 62 | // POST Request. 63 | API::post('user', array('title' => 'Demo')); 64 | 65 | // PUT Request. 66 | API::put('user/1', array('title' => 'Changed')); 67 | 68 | // DELETE Request. 69 | API::delete('user/1'); 70 | 71 | // Internal request with domain route. 72 | API::invoke('http://api.domain.com', 'post', array('param' => 1)) 73 | 74 | // You can make remote request without changing code also. 75 | API::post('http://api.github.com', array('username' => 'teepluss')); 76 | 77 | // Request remote with invokeRemote. 78 | API::invokeRemote('http://api.github.com', 'post', array('username' => 'teepluss')); 79 | 80 | // Get Guzzle to use other features. 81 | $guzzle = API::getRemoteClient(); 82 | ~~~ 83 | >> Remote request using [Guzzle](http://guzzlephp.org/) as an adapter. 84 | 85 | ### Calling via artisan CLI. 86 | 87 | ~~~lisp 88 | // Internal GET. 89 | $ php artisan api:call --request GET /some/route?param=value 90 | 91 | // Internal POST. 92 | $ php artisan api:call --request POST /some/form --data "name=Tee" 93 | 94 | // Remote request. 95 | $ php artisan api:call --request GET http://google.com 96 | ~~~ 97 | >> also work with DELETE, PATCH, HEAD 98 | 99 | ### Create reponses format for RESTful. 100 | 101 | ~~~php 102 | // Response entries. 103 | $users = User::all(); 104 | API::createResponse($users); 105 | 106 | // Response entry. 107 | $user = User::find($id); 108 | return API::createResponse($user); 109 | 110 | // Response Laravel error. 111 | $errors = $validation->messages()->all(':message'); 112 | return API::createResponse(compact('errors'), 400); 113 | 114 | // Response created data. 115 | $user = Url::create($data); 116 | return API::createResponse($user, 201); 117 | 118 | // Response 404. 119 | API::createResponse("User [$id] was not found.", 404); 120 | 121 | //Response deleted. 122 | API::createResponse(null, 204); 123 | ~~~ 124 | >> For RESTful response recommended to use [Restable](https://github.com/teepluss/laravel4-restable) instead. 125 | 126 | ## Changes 127 | 128 | #### v1.0.1 129 | - Add artisan CLI. 130 | 131 | #### v1.0.0 132 | - Release first master version. 133 | 134 | ## Support or Contact 135 | 136 | If you have some problem, Contact teepluss@gmail.com 137 | 138 | [![Support via PayPal](https://rawgithub.com/chris---/Donation-Badges/master/paypal.jpeg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9GEC8J7FAG6JA) -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "teepluss/api", 3 | "description": "Laravel 4 Internal Request (HMVC)", 4 | "keywords": ["laravel", "laravel4", "restful", "api", "hmvc"], 5 | "homepage": "https://github.com/teepluss/laravel4-api", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Teepluss", 11 | "email": "admin@laravel.in.th", 12 | "homepage": "https://github.com/teepluss", 13 | "role": "Developer" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.3.0", 18 | "illuminate/support": "4.x", 19 | "guzzle/guzzle": "3.9.x" 20 | }, 21 | "require-dev": { 22 | "mockery/mockery": "0.7.2" 23 | }, 24 | "autoload": { 25 | "psr-0": { 26 | "Teepluss\\Api": "src/" 27 | } 28 | }, 29 | "extra": { 30 | "branch-alias": { 31 | "dev-master": "1.0.0-dev" 32 | } 33 | }, 34 | "minimum-stability": "dev" 35 | } 36 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Teepluss/Api/Api.php: -------------------------------------------------------------------------------- 1 | '100 Continue', 48 | 101 => '101 Switching Protocols', 49 | //Successful 2xx 50 | 200 => '200 OK', 51 | 201 => '201 Created', 52 | 202 => '202 Accepted', 53 | 203 => '203 Non-Authoritative Information', 54 | 204 => '204 No Content', 55 | 205 => '205 Reset Content', 56 | 206 => '206 Partial Content', 57 | //Redirection 3xx 58 | 300 => '300 Multiple Choices', 59 | 301 => '301 Moved Permanently', 60 | 302 => '302 Found', 61 | 303 => '303 See Other', 62 | 304 => '304 Not Modified', 63 | 305 => '305 Use Proxy', 64 | 306 => '306 (Unused)', 65 | 307 => '307 Temporary Redirect', 66 | //Client Error 4xx 67 | 400 => '400 Bad Request', 68 | 401 => '401 Unauthorized', 69 | 402 => '402 Payment Required', 70 | 403 => '403 Forbidden', 71 | 404 => '404 Not Found', 72 | 405 => '405 Method Not Allowed', 73 | 406 => '406 Not Acceptable', 74 | 407 => '407 Proxy Authentication Required', 75 | 408 => '408 Request Timeout', 76 | 409 => '409 Conflict', 77 | 410 => '410 Gone', 78 | 411 => '411 Length Required', 79 | 412 => '412 Precondition Failed', 80 | 413 => '413 Request Entity Too Large', 81 | 414 => '414 Request-URI Too Long', 82 | 415 => '415 Unsupported Media Type', 83 | 416 => '416 Requested Range Not Satisfiable', 84 | 417 => '417 Expectation Failed', 85 | 422 => '422 Unprocessable Entity', 86 | 423 => '423 Locked', 87 | //Server Error 5xx 88 | 500 => '500 Internal Server Error', 89 | 501 => '501 Not Implemented', 90 | 502 => '502 Bad Gateway', 91 | 503 => '503 Service Unavailable', 92 | 504 => '504 Gateway Timeout', 93 | 505 => '505 HTTP Version Not Supported' 94 | ); 95 | 96 | /** 97 | * Instance API. 98 | * 99 | * @param Repository $config $router 100 | * @param Router $router 101 | * @param Request $request 102 | * @param Client $remote 103 | */ 104 | public function __construct(Repository $config, Router $router, Request $request, Client $remoteClient) 105 | { 106 | $this->config = $config->get('api::config'); 107 | 108 | $this->router = $router; 109 | 110 | $this->request = $request; 111 | 112 | $this->remoteClient = $remoteClient; 113 | } 114 | 115 | /** 116 | * Create API response. 117 | * 118 | * @param mixed $messages 119 | * @param integer $code 120 | * @return string 121 | */ 122 | public function createResponse($messages, $code = 200) 123 | { 124 | return $this->make($messages, $code); 125 | } 126 | 127 | /** 128 | * Custom API response. 129 | * 130 | * @param mixed $messages 131 | * @param integer $code 132 | * @return string 133 | */ 134 | public function deviseResponse($messages, $code = 200) 135 | { 136 | return $this->make($messages, $code, true); 137 | } 138 | 139 | /** 140 | * Make json data format. 141 | * 142 | * @param mixed $data 143 | * @param integer $code 144 | * @param boolean $overwrite 145 | * @return string 146 | */ 147 | public function make($data, $code, $overwrite = false) 148 | { 149 | // Status returned. 150 | $status = (preg_match('/^(1|2|3)/', $code)) ? 'success' : 'error'; 151 | 152 | // Change object to array. 153 | if (is_object($data)) 154 | { 155 | $data = $data->toArray(); 156 | } 157 | 158 | // Data as a string. 159 | if (is_string($data)) 160 | { 161 | $data = array('message' => $data); 162 | } 163 | 164 | // Overwrite response format. 165 | if ($overwrite === true) 166 | { 167 | $response = $data; 168 | } 169 | else 170 | { 171 | $message = $this->statuses[$code]; 172 | 173 | // Custom return message. 174 | if (isset($data['message'])) 175 | { 176 | $message = $data['message']; 177 | 178 | unset($data['message']); 179 | } 180 | 181 | // Available data response. 182 | $response = array( 183 | 'status' => $status, 184 | 'code' => $code, 185 | 'message' => $message, 186 | 'data' => $data, 187 | 'pagination' => null 188 | ); 189 | 190 | // Merge if data has anything else. 191 | if (isset($data['data'])) 192 | { 193 | $response = array_merge($response, $data); 194 | } 195 | 196 | // Remove empty array. 197 | $response = array_filter($response, function($value) 198 | { 199 | return ! is_null($value); 200 | }); 201 | 202 | // Remove empty data. 203 | if ($this->config['removeEmptyData'] && empty($response['data'])) 204 | { 205 | unset($response['data']); 206 | } 207 | } 208 | 209 | // Header response. 210 | $header = ($this->config['httpResponse']) ? $code : 200; 211 | 212 | return Response::make($response, $header); 213 | } 214 | 215 | /** 216 | * Remote client for http request. 217 | * 218 | * @return Client 219 | */ 220 | public function getRemoteClient() 221 | { 222 | return $this->remoteClient; 223 | } 224 | 225 | /** 226 | * Configure remote client for http request. 227 | * 228 | * @param array $configuration 229 | * 230 | * array 231 | *( 232 | * 'verify' => false, //allows self signed certificates 233 | * 'verify', '/path/to/cacert.pem', //custom certificate 234 | * 'headers/X-Foo', 'Bar', //custom header 235 | * 'auth', array('username', 'password', 'Digest'), //custom authentication 236 | *) 237 | */ 238 | public function configureRemoteClient($configurations) 239 | { 240 | foreach ($configurations as $option => $value) 241 | { 242 | call_user_func_array(array($this->remoteClient, 'setDefaultOption'), array($option, $value)); 243 | } 244 | } 245 | 246 | /** 247 | * Call internal URI with parameters. 248 | * 249 | * @param string $uri 250 | * @param string $method 251 | * @param array $parameters 252 | * @return mixed 253 | */ 254 | public function invoke($uri, $method, $parameters = array()) 255 | { 256 | // Request URI. 257 | if ( ! preg_match('/^http(s)?:/', $uri)) 258 | { 259 | $uri = '/'.ltrim($uri, '/'); 260 | } 261 | 262 | try 263 | { 264 | // Store the original request data and route. 265 | $originalInput = $this->request->input(); 266 | $originalRoute = $this->router->getCurrentRoute(); 267 | 268 | // Masking route to allow testing with PHPUnit. 269 | if ( ! $originalRoute instanceof Route) 270 | { 271 | $originalRoute = new Route(new \Symfony\Component\HttpFoundation\Request()); 272 | } 273 | 274 | // Create a new request to the API resource 275 | $request = $this->request->create($uri, strtoupper($method), $parameters); 276 | 277 | // Replace the request input... 278 | $this->request->replace($request->input()); 279 | 280 | // Dispatch request. 281 | $dispatch = $this->router->dispatch($request); 282 | 283 | if (method_exists($dispatch, 'getOriginalContent')) 284 | { 285 | $response = $dispatch->getOriginalContent(); 286 | } 287 | else 288 | { 289 | $response = $dispatch->getContent(); 290 | } 291 | 292 | // Decode json content. 293 | if ($dispatch->headers->get('content-type') == 'application/json') 294 | { 295 | if (function_exists('json_decode') and is_string($response)) 296 | { 297 | $response = json_decode($response, true); 298 | } 299 | } 300 | 301 | // Restore the request input and route back to the original state. 302 | $this->request->replace($originalInput); 303 | 304 | 305 | // This method have been removed from Laravel. 306 | //$this->router->setCurrentRoute($originalRoute); 307 | 308 | return $response; 309 | } 310 | catch (NotFoundHttpException $e) 311 | { 312 | //trigger_error('Not found'); 313 | var_dump($e->getMessage()); 314 | } 315 | catch (FatalErrorException $e) 316 | { 317 | var_dump($e->getMessage()); 318 | } 319 | } 320 | 321 | /** 322 | * Invoke with remote uri. 323 | * 324 | * @param string $uri 325 | * @param string $method 326 | * @param array $parameters 327 | * @return mixed 328 | */ 329 | public function invokeRemote($uri, $method, $parameters = array()) 330 | { 331 | $remoteClient = $this->getRemoteClient(); 332 | 333 | // Make request. 334 | $request = call_user_func_array(array($remoteClient, $method), array($uri, null, $parameters)); 335 | 336 | // Send request. 337 | $response = $request->send(); 338 | 339 | // Body responsed. 340 | $body = (string) $response->getBody(); 341 | 342 | // Decode json content. 343 | if ($response->getContentType() == 'application/json') 344 | { 345 | if (function_exists('json_decode') and is_string($body)) 346 | { 347 | $body = json_decode($body, true); 348 | } 349 | } 350 | 351 | return $body; 352 | } 353 | 354 | /** 355 | * Alias call method. 356 | * 357 | * @return mixed 358 | */ 359 | public function __call($method, $parameters = array()) 360 | { 361 | if (in_array($method, array('get', 'post', 'put', 'delete'))) 362 | { 363 | $uri = array_shift($parameters); 364 | 365 | $parameters = current($parameters); 366 | $parameters = is_array($parameters) ? $parameters : array(); 367 | 368 | if (preg_match('/^http(s)?/', $uri)) 369 | { 370 | return $this->invokeRemote($uri, $method, $parameters); 371 | } 372 | 373 | return $this->invoke($uri, $method, $parameters); 374 | } 375 | } 376 | 377 | } 378 | -------------------------------------------------------------------------------- /src/Teepluss/Api/ApiServiceProvider.php: -------------------------------------------------------------------------------- 1 | package('teepluss/api'); 24 | 25 | // Auto create app alias with boot method. 26 | $loader = AliasLoader::getInstance()->alias('API', 'Teepluss\Api\Facades\API'); 27 | } 28 | 29 | /** 30 | * Register the service provider. 31 | * 32 | * @return void 33 | */ 34 | public function register() 35 | { 36 | // Register providers. 37 | $this->registerApi(); 38 | 39 | // Register commands. 40 | $this->registerApiCallCommand(); 41 | 42 | // Assign commands. 43 | $this->commands( 44 | 'api.call' 45 | ); 46 | } 47 | 48 | /** 49 | * Register Api. 50 | * 51 | * @return void 52 | */ 53 | public function registerApi() 54 | { 55 | $this->app['api.request'] = $this->app->share(function($app) 56 | { 57 | $remoteClient = new Client(); 58 | 59 | return new Api($app['config'], $app['router'], $app['request'], $remoteClient); 60 | }); 61 | } 62 | 63 | /** 64 | * Register Api Call command. 65 | * 66 | * @return void 67 | */ 68 | public function registerApiCallCommand() 69 | { 70 | $this->app['api.call'] = $this->app->share(function($app) 71 | { 72 | return new Commands\ApiCallCommand($app['api.request']); 73 | }); 74 | } 75 | 76 | /** 77 | * Get the services provided by the provider. 78 | * 79 | * @return array 80 | */ 81 | public function provides() 82 | { 83 | return array('api.request', 'api.call'); 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /src/Teepluss/Api/Commands/ApiCallCommand.php: -------------------------------------------------------------------------------- 1 | api = $api; 41 | } 42 | 43 | /** 44 | * Execute the console command. 45 | * 46 | * @return mixed 47 | */ 48 | public function fire() 49 | { 50 | $url = $this->argument('url'); 51 | 52 | // Remote request. 53 | $invoke = (preg_match('/^http(s)?:/', $url)) ? 'invokeRemote' : 'invoke'; 54 | 55 | // Method to call. 56 | $method = $this->option('request'); 57 | $method = strtolower($method); 58 | $method = (in_array($method, array('get', 'post', 'put', 'delete', 'patch', 'head'))) ? $method : 'get'; 59 | 60 | // Parameters. 61 | $parameters = $this->option('data'); 62 | 63 | if ($parameters) 64 | { 65 | parse_str($parameters, $parameters); 66 | } 67 | 68 | $response = $this->api->$invoke($url, $method, $parameters); 69 | 70 | if ($response instanceof View) 71 | { 72 | return $this->info($response->render()); 73 | } 74 | 75 | if (is_array($response) or is_object($response)) 76 | { 77 | return $this->info(var_export($response, true)); 78 | } 79 | 80 | return $this->info($response); 81 | } 82 | 83 | /** 84 | * Get the console command arguments. 85 | * 86 | * @return array 87 | */ 88 | protected function getArguments() 89 | { 90 | return array( 91 | array('url', InputArgument::REQUIRED, 'URL to call'), 92 | ); 93 | } 94 | 95 | /** 96 | * Get the console command options. 97 | * 98 | * @return array 99 | */ 100 | protected function getOptions() 101 | { 102 | return array( 103 | array('request', 'X', InputOption::VALUE_OPTIONAL, 'Specifies a custom request method.', 'GET'), 104 | array('data', 'd', InputOption::VALUE_OPTIONAL, 'Sends the specified data in a POST request to the HTTP server.', array()) 105 | ); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/Teepluss/Api/Facades/API.php: -------------------------------------------------------------------------------- 1 | false, 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | Remove empty data. 20 | |-------------------------------------------------------------------------- 21 | | 22 | | Unset the node when data is empty. 23 | | 24 | */ 25 | 26 | 'removeEmptyData' => true 27 | 28 | ); -------------------------------------------------------------------------------- /tests/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teepluss/laravel4-api/e34b169dac5e0a9c56f2904387deb9187525fde3/tests/.gitkeep -------------------------------------------------------------------------------- /tests/ApiTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 15 | } 16 | 17 | // public function testApiCan() 18 | // { 19 | // $user = m::mock('User'); 20 | // } 21 | 22 | // public function testEntrustCan() 23 | // { 24 | // // Current user 25 | // $user = m::mock( 'User' ); 26 | 27 | // // Permission manage a as true 28 | // $user->shouldReceive('can') 29 | // ->with( 'manage_a' ) 30 | // ->once() 31 | // ->andReturn( true ); 32 | 33 | // // Permission manage b as false 34 | // $user->shouldReceive('can') 35 | // ->with( 'manage_b' ) 36 | // ->once() 37 | // ->andReturn( false ); 38 | 39 | // $entrust = new Entrust( $this->mockAppWithCurrentUser( $user ) ); 40 | 41 | // // Check if user 'can' 42 | // $this->assertTrue( $entrust->can('manage_a') ); 43 | // $this->assertFalse( $entrust->can('manage_b') ); 44 | // } 45 | 46 | // public function testEntrustHasRole() 47 | // { 48 | // // Current user 49 | // $user = m::mock( 'User' ); 50 | 51 | // // Permission manage a as true 52 | // $user->shouldReceive('hasRole') 53 | // ->with( 'AdminA' ) 54 | // ->once() 55 | // ->andReturn( true ); 56 | 57 | // // Permission manage b as false 58 | // $user->shouldReceive('hasRole') 59 | // ->with( 'AdminB' ) 60 | // ->once() 61 | // ->andReturn( false ); 62 | 63 | // $entrust = new Entrust( $this->mockAppWithCurrentUser( $user ) ); 64 | 65 | // // Check if user 'can' 66 | // $this->assertTrue( $entrust->hasRole('AdminA') ); 67 | // $this->assertFalse( $entrust->hasRole('AdminB') ); 68 | // } 69 | 70 | // public function testGetUser() 71 | // { 72 | // // Current user 73 | // $user = m::mock( 'User' ); 74 | 75 | // $entrust = new Entrust( $this->mockAppWithCurrentUser( $user ) ); 76 | 77 | // // Check the returned user 78 | // $this->assertEquals( $entrust->user(), $user ); 79 | // } 80 | 81 | // public function testFilterRoutesNeedRole() 82 | // { 83 | // $router = m::mock( 'Router' ); 84 | // $router->shouldReceive('filter') 85 | // ->once(); 86 | // $router->shouldReceive('when') 87 | // ->once(); 88 | 89 | // $app = array('router'=>$router); 90 | 91 | // $entrust = new Entrust( $app ); 92 | 93 | // $entrust->routeNeedsRole('admin','Admin'); 94 | // } 95 | 96 | // public function testFilterRoutesNeedPermission() 97 | // { 98 | // $router = m::mock( 'Router' ); 99 | // $router->shouldReceive('filter') 100 | // ->once(); 101 | // $router->shouldReceive('when') 102 | // ->once(); 103 | 104 | // $app = array('router'=>$router); 105 | 106 | // $entrust = new Entrust( $app ); 107 | 108 | // $entrust->routeNeedsPermission('admin','manage_users'); 109 | // } 110 | 111 | // private function mockAppWithCurrentUser( $user ) 112 | // { 113 | // // Mock app 114 | // $app = array( 'auth' => m::mock( 'Auth' ) ); 115 | 116 | // // Return current user within Auth mock 117 | // $app['auth']->shouldReceive('user') 118 | // ->andReturn( $user ); 119 | 120 | // return $app; 121 | // } 122 | 123 | } --------------------------------------------------------------------------------