Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ServiceStarter.php
Go to the documentation of this file.
1<?php
3
5
15
17
19
20 private function loadServices() {
21 $file = $this->getServicesFilename();
22 if (\file_exists($file)) {
23 $this->servicesContent = UFileSystem::load($file);
24 }
25 }
26
27 private function getServicesFilename() {
28 return \ROOT . \DS . 'config' . \DS . $this->servicesName . '.php';
29 }
30
31 public function __construct(?string $servicesName = 'services') {
32 $this->servicesName = $servicesName;
33 $this->loadServices();
34 }
35
36 public function getTemplateDir() {
37 return \dirname(__DIR__) . "/templates/services/";
38 }
39
40 public function addService($serviceName) {
41 $file = $this->getTemplateDir() . $serviceName . '.tpl';
42 if (\file_exists($file)) {
43 $serviceContent = UFileSystem::load($file);
44 if (\strpos($this->servicesContent, $serviceContent) === false) {
45 $this->servicesContent = rtrim($this->servicesContent) . "\n" . $serviceContent;
46 }
47 }
48 }
49
50 public function addServices(array $services) {
51 foreach ($services as $service) {
52 $this->addService($service);
53 }
54 }
55
56 public function save() {
57 return UFileSystem::save($this->getServicesFilename(), $this->servicesContent);
58 }
59}
60
Ubiquity\scaffolding\starter$ServiceStarter This class is part of Ubiquity.
__construct(?string $servicesName='services')
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.