Skip to content

Commit 9c8e884

Browse files
committed
Releasing 1.0.26
2 parents cad6408 + e39f504 commit 9c8e884

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

src/WebApp/Application.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Application {
1414
public $vault;
1515
public $database;
1616
public $dataModel;
17+
public $serviceFactory;
1718
public $authentication;
1819
public $authorization;
1920
public $sessionHandler;
@@ -39,6 +40,7 @@ public function init() {
3940
$this->initVault();
4041
$this->initDatabase();
4142
$this->initDataModel();
43+
$this->initServices();
4244
$this->initAuthentication();
4345
$this->initAuthorization();
4446
$this->initSession();
@@ -72,6 +74,14 @@ protected function initDataModel() {
7274
}
7375
}
7476

77+
protected function initServices() {
78+
if ($this->config->has('serviceFactory')) {
79+
$config = $this->config->get('serviceFactory');
80+
$className = $config->class;
81+
$this->serviceFactory = new $className($this);
82+
}
83+
}
84+
7585
protected function initAuthentication() {
7686
if ($this->config->has('authentication')) {
7787
$authConfig = $this->config->get('authentication');
@@ -350,6 +360,13 @@ public function afterRequest() {
350360
}
351361
}
352362

363+
public function svc($name) {
364+
if ($this->serviceFactory != NULL) {
365+
return $this->serviceFactory->get($name);
366+
}
367+
return NULL;
368+
}
369+
353370
public function dao($name) {
354371
if ($this->dataModel != NULL) {
355372
return $this->dataModel->get($name);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace WebApp\Service;
4+
5+
class AbstractService implements Service {
6+
7+
protected $app;
8+
9+
public function __construct($app) {
10+
$this->app = $app;
11+
}
12+
13+
}
14+

src/WebApp/Service/Service.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace WebApp\Service;
4+
5+
interface Service {
6+
7+
}
8+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace WebApp\Service;
4+
5+
class ServiceFactory {
6+
7+
protected $app;
8+
protected $services;
9+
10+
public function __construct($app) {
11+
$this->app = $app;
12+
$this->services = array();
13+
}
14+
15+
public function get($name) {
16+
if (!isset($this->services[$name])) {
17+
$this->services[$name] = $this->create($name);
18+
}
19+
return $this->services[$name];
20+
}
21+
22+
protected function create($name) {
23+
return NULL;
24+
}
25+
}
26+

0 commit comments

Comments
 (0)