-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.php
93 lines (81 loc) · 2.64 KB
/
controller.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Concrete\Package\Concrete5GraphqlWebsocketSample;
use Concrete\Core\Asset\Asset;
use Concrete\Core\Asset\AssetList;
use Concrete\Core\Database\EntityManager\Provider\StandardPackageProvider;
use Concrete\Core\Package\Package;
use Doctrine\ORM\EntityManagerInterface;
use Entity\Person;
use GraphQl\TestGraphQl;
class Controller extends Package
{
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::$packageDependencies
*/
protected $packageDependencies = [
'concrete5_graphql_websocket' => '1.2.9',
];
protected $appVersionRequired = '8.5.1';
protected $pkgVersion = '1.1.6';
protected $pkgHandle = 'concrete5_graphql_websocket_sample';
protected $pkgName = 'GraphQL with Websocket Sample';
protected $pkgDescription = 'Shows how to use GraphQL and Websocket in Concrete5';
protected $pkg;
protected $pkgAutoloaderRegistries = [
'src/GraphQl' => '\GraphQl',
'src/Entity' => '\Entity',
];
public function getEntityManagerProvider()
{
$provider = new StandardPackageProvider($this->app, $this, [
'src/Entity' => 'Entity',
]);
return $provider;
}
public function on_start()
{
$al = AssetList::getInstance();
$al->register('javascript', 'person', 'js/dist/person.js', ['position' => Asset::ASSET_POSITION_FOOTER, 'minify' => false, 'combine' => true], $this);
$this->app->make(TestGraphQl::class)->start();
}
public function install()
{
parent::install();
$this->installXML();
$this->addSampleData();
}
public function upgrade()
{
parent::upgrade();
$this->installXML();
$this->addSampleData();
}
private function installXML()
{
$this->installContentFile('config/install.xml');
}
private function addSampleData()
{
$entityManager = $this->app->make(EntityManagerInterface::class);
$personRepository = $entityManager->getRepository(Person::class);
if ($personRepository->findOneBy(['first_name' => 'Fritz']) === null) {
$item = new Person();
$item->setData([
'first_name' => 'Fritz',
'second_name' => 'Muster',
]);
$entityManager->persist($item);
}
if ($personRepository->findOneBy(['first_name' => 'Franz']) === null) {
$item = new Person();
$item->setData([
'first_name' => 'Franz',
'second_name' => 'Kanns',
]);
$entityManager->persist($item);
}
$entityManager->flush();
}
}