Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
71.05% covered (warning)
71.05%
27 / 38
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
LoginSelect
71.05% covered (warning)
71.05%
27 / 38
0.00% covered (danger)
0.00%
0 / 1
8.19
0.00% covered (danger)
0.00%
0 / 1
 __construct
71.05% covered (warning)
71.05%
27 / 38
0.00% covered (danger)
0.00%
0 / 1
8.19
1<?php
2namespace Apie\HtmlBuilders\Components\Layout;
3
4use Apie\Core\ContextConstants;
5use Apie\HtmlBuilders\Components\BaseComponent;
6use Apie\HtmlBuilders\Components\Dashboard\RawContents;
7use Apie\HtmlBuilders\Configuration\CurrentConfiguration;
8use Apie\HtmlBuilders\Lists\ComponentHashmap;
9
10class LoginSelect extends BaseComponent
11{
12    public function __construct(
13        CurrentConfiguration $currentConfiguration
14    ) {
15        $loginOptions = [];
16        $boundedContext = $currentConfiguration->getSelectedBoundedContext();
17        if ($boundedContext) {
18            foreach ($boundedContext->actions->filterOnApieContext($currentConfiguration->getApieContext()) as $method) {
19                if ($method->name==='verifyAuthentication' || $method->name==='login') {
20                    $loginOptions[] = [
21                        'name' => $method->getDeclaringClass()->getShortName(),
22                        'value' => $currentConfiguration->getContextUrl(
23                            '/action/' . $method->getDeclaringClass()->getShortName() . '/' . $method->name
24                        ),
25                    ];
26                }
27            }
28        }
29        $profile = new RawContents('');
30        $profileDetails =  new RawContents('');
31        $authenticated = false;
32        if ($currentConfiguration->getApieContext()->hasContext(ContextConstants::AUTHENTICATED_USER)) {
33            $profile = new ShowProfile(
34                $currentConfiguration,
35                $currentConfiguration->getApieContext()->getContext(ContextConstants::AUTHENTICATED_USER),
36                true
37            );
38            $profileDetails = new ShowProfile(
39                $currentConfiguration,
40                $currentConfiguration->getApieContext()->getContext(ContextConstants::AUTHENTICATED_USER),
41                false
42            );
43            $authenticated = true;
44        }
45        parent::__construct(
46            [
47                'loginOptions'  => $loginOptions,
48                'profileUrl'    => $profile->getAttribute('profileUrl'),
49                'logoutUrl'     => $authenticated ? $currentConfiguration->getLogoutUrl() : null,
50                'authenticated' => $authenticated,
51            ],
52            new ComponentHashmap([
53                'profile' => $profile,
54                'profileDetails' => $profileDetails,
55            ])
56        );
57    }
58}