Skip to content

Commit 9e8e923

Browse files
committed
Releasing 1.0.27
2 parents 9c8e884 + 708b0f9 commit 9e8e923

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace WebApp\Service;
4+
5+
/** Descendants only need to declare methods like getViewLink(), getEditLink() etc. */
6+
class AbstractLinkBuilder implements \TgUtils\LinkBuilder {
7+
8+
public function __construct($app) {
9+
$this->app = $app;
10+
}
11+
12+
public function getLink($subject, $action = \TgUtils\LinkBuilder::VIEW, $params = NULL) {
13+
if ($action == '') return '#'; // To break unwanted loops
14+
$methodName = 'get'.ucfirst($action).'Link';
15+
if (method_exists($this, $methodName)) {
16+
return call_user_func(array($this, $methodName), $subject, $params);
17+
}
18+
return '#';
19+
}
20+
}
21+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace WebApp\Service;
4+
5+
class LinkBuilderService extends AbstractService {
6+
7+
public function __construct($app) {
8+
parent::__construct($app);
9+
$this->builders = array();
10+
}
11+
12+
public function getLink($subject, $action = LinkBuilder::VIEW, $params = NULL) {
13+
$builder = $this->getBuilder($subject);
14+
if ($builder != NULL) {
15+
return $builder->getLink($subject, $action, $params);
16+
}
17+
return '#';
18+
}
19+
20+
public function getBuilder($subject) {
21+
$name = $this->getBuilderName($subject);
22+
if (!isset($this->builders[$name])) {
23+
$this->builders[$name] = $this->createBuilder($name);
24+
}
25+
return $this->builders[$name];
26+
}
27+
28+
protected function createBuilder($name) {
29+
return NULL;
30+
}
31+
32+
protected function getBuilderName($subject) {
33+
$name = NULL;
34+
if (is_string($subject)) {
35+
$name = $subject;
36+
} else if (is_object($subject)) {
37+
$name = strtolower(get_class($subject));
38+
}
39+
return $name;
40+
}
41+
42+
}

0 commit comments

Comments
 (0)