1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
6
|
|
|
* @package laravel |
7
|
|
|
* @subpackage Controller |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Controller; |
12
|
|
|
|
13
|
|
|
use Aimeos\Shop\Facades\Shop; |
14
|
|
|
use Illuminate\Routing\Controller; |
15
|
|
|
use Illuminate\Support\Facades\Response; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Aimeos controller for account related functionality. |
20
|
|
|
* |
21
|
|
|
* @package laravel |
22
|
|
|
* @subpackage Controller |
23
|
|
|
*/ |
24
|
|
|
class AccountController extends Controller |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Returns the html for the "My account" page. |
28
|
|
|
* |
29
|
|
|
* @return \Illuminate\Http\Response Response object with output and headers |
30
|
|
|
*/ |
31
|
|
|
public function indexAction() |
32
|
|
|
{ |
33
|
|
|
$default = ['account/profile','account/subscription','account/history','account/favorite','account/watch','basket/mini','catalog/session']; |
34
|
|
|
|
35
|
|
|
foreach( app( 'config' )->get( 'shop.page.account-index', $default ) as $name ) |
36
|
|
|
{ |
37
|
|
|
$params['aiheader'][$name] = Shop::get( $name )->getHeader(); |
|
|
|
|
38
|
|
|
$params['aibody'][$name] = Shop::get( $name )->getBody(); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return Response::view('shop::account.index', $params); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns the html for the "My account" download page. |
47
|
|
|
* |
48
|
|
|
* @return \Illuminate\Contracts\View\View View for rendering the output |
49
|
|
|
*/ |
50
|
|
|
public function downloadAction() |
51
|
|
|
{ |
52
|
|
|
$response = Shop::get( 'account/download' )->getView()->response(); |
|
|
|
|
53
|
|
|
return Response::make( (string) $response->getBody(), $response->getStatusCode(), $response->getHeaders() ); |
54
|
|
|
} |
55
|
|
|
} |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.