This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcore.php
75 lines (65 loc) · 1.89 KB
/
core.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
* This file is part of the Ekino Wordpress package.
*
* (c) 2013 Ekino
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Boot symfony and register the container
*/
function symfony_boot()
{
$sfContainer = symfony_get_container();
if (!$sfContainer) {
require_once sprintf('%s/app/bootstrap.php.cache', WP_SYMFONY_PATH);
require_once sprintf('%s/app/AppKernel.php', WP_SYMFONY_PATH);
$kernel = new AppKernel(WP_SYMFONY_ENVIRONMENT, WP_SYMFONY_DEBUG);
$kernel->loadClassCache();
$kernel->boot();
$sfContainer = $kernel->getContainer();
$sfContainer->enterScope('request');
$sfContainer->set('request', new \Symfony\Component\HttpFoundation\Request(), 'request');
symfony_get_container($sfContainer);
}
}
/**
* Returns a Symfony service from its name
*
* @param string $name
*
* @return object
*/
function symfony_service($name)
{
return symfony_get_container()->get($name);
}
/**
* Returns Symfony container from Symfony EkinoWordpressBundle if installed else from static loaded here
*
* @param ContainerInterface|null $sfContainer
*
* @return ContainerInterface
*/
function symfony_get_container($sfContainer = null)
{
static $container;
if (function_exists('symfony_container')) {
$container = symfony_container();
}
return $container = $sfContainer ?: $container;
}
/**
* Dispatch an event using Symfony EventDispatcher service
*
* @param string $name Name of the event to dispatch
* @param \Ekino\WordpressBundle\Event\WordpressEvent $event A Wordpress event
*
* @return mixed
*/
function symfony_event_dispatch($name, \Ekino\WordpressBundle\Event\WordpressEvent $event)
{
return symfony_service('event_dispatcher')->dispatch($name, $event);
}