Completed
Branch EDTR/master (83b47e)
by
unknown
25:37 queued 16:41
created

Api::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\entities\routing\data_nodes\core;
4
5
use DomainException;
6
use EED_Core_Rest_Api;
7
use EventEspresso\core\services\json\JsonDataNode;
8
use EventEspresso\core\services\json\JsonDataNodeValidator;
9
use WPGraphQL\Router;
10
11
/**
12
 * Class Config
13
 * Description
14
 *
15
 * @package EventEspresso\core\domain\entities\routing\data_nodes
16
 * @author  Brent Christensen
17
 * @since   $VID:$
18
 */
19
class Api extends JsonDataNode
20
{
21
22
    const NODE_NAME = 'api';
23
24
25
    /**
26
     * JsonDataNodeHandler constructor.
27
     *
28
     * @param JsonDataNodeValidator $validator
29
     */
30
    public function __construct(JsonDataNodeValidator $validator)
31
    {
32
        parent::__construct($validator);
33
        $this->setNodeName(Api::NODE_NAME);
34
    }
35
36
37
    /**
38
     * @throws DomainException
39
     * @since $VID:$
40
     */
41
    public function initialize()
42
    {
43
        $this->addData('restApiNonce', wp_create_nonce('wp_rest'));
44
        $this->addData('restApiBaseUrl', rest_url());
45
        $this->addData('restApiRouteUrl', rest_url('ee/v4.8.36/'));
46
        $this->addData('restApiCollectionEndpoints', EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName());
47
        $this->addData('restApiPrimaryKeys', EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName());
48
        $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
49
        $this->addData('graphqlEndpoint', esc_url($graphqlEndpoint));
50
        $this->setInitialized(true);
51
    }
52
}
53