@@ -7,85 +7,85 @@ |
||
7 | 7 | class MysqlTagRepository implements TagRepository |
8 | 8 | { |
9 | 9 | |
10 | - /** @var Aura\Sql\ConnectionLocator */ |
|
11 | - protected $connections; |
|
10 | + /** @var Aura\Sql\ConnectionLocator */ |
|
11 | + protected $connections; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @param Aura\Sql\ConnectionLocator |
|
15 | - */ |
|
16 | - public function __construct(ConnectionLocator $connections) |
|
17 | - { |
|
18 | - $this->connections = $connections; |
|
19 | - } |
|
13 | + /** |
|
14 | + * @param Aura\Sql\ConnectionLocator |
|
15 | + */ |
|
16 | + public function __construct(ConnectionLocator $connections) |
|
17 | + { |
|
18 | + $this->connections = $connections; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $title |
|
23 | - * |
|
24 | - * @return array|false |
|
25 | - */ |
|
26 | - public function findTagByTitle($title) |
|
27 | - { |
|
28 | - $query = " |
|
21 | + /** |
|
22 | + * @param string $title |
|
23 | + * |
|
24 | + * @return array|false |
|
25 | + */ |
|
26 | + public function findTagByTitle($title) |
|
27 | + { |
|
28 | + $query = " |
|
29 | 29 | SELECT * |
30 | 30 | FROM `jpemeric_blog`.`tag` |
31 | 31 | WHERE `tag` = :title |
32 | 32 | LIMIT 1"; |
33 | - $bindings = [ |
|
34 | - 'title' => $title, |
|
35 | - ]; |
|
33 | + $bindings = [ |
|
34 | + 'title' => $title, |
|
35 | + ]; |
|
36 | 36 | |
37 | - return $this |
|
38 | - ->connections |
|
39 | - ->getRead() |
|
40 | - ->fetchOne($query, $bindings); |
|
41 | - } |
|
37 | + return $this |
|
38 | + ->connections |
|
39 | + ->getRead() |
|
40 | + ->fetchOne($query, $bindings); |
|
41 | + } |
|
42 | 42 | |
43 | - public function getAllTags() |
|
44 | - { |
|
45 | - $query = " |
|
43 | + public function getAllTags() |
|
44 | + { |
|
45 | + $query = " |
|
46 | 46 | SELECT * |
47 | 47 | FROM `jpemeric_blog`.`tag` |
48 | 48 | ORDER BY `tag`"; |
49 | 49 | |
50 | - return $this |
|
51 | - ->connections |
|
52 | - ->getRead() |
|
53 | - ->fetchAll($query); |
|
54 | - } |
|
50 | + return $this |
|
51 | + ->connections |
|
52 | + ->getRead() |
|
53 | + ->fetchAll($query); |
|
54 | + } |
|
55 | 55 | |
56 | - public function getTagCloud() |
|
57 | - { |
|
58 | - $query = " |
|
56 | + public function getTagCloud() |
|
57 | + { |
|
58 | + $query = " |
|
59 | 59 | SELECT COUNT(1) AS `count`, `tag` |
60 | 60 | FROM `jpemeric_blog`.`tag` |
61 | 61 | INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`tag_id` = `tag`.`id` |
62 | 62 | INNER JOIN `jpemeric_blog`.`post` ON `post`.`id` = `ptlink`.`post_id` AND |
63 | 63 | `post`.`display` = :is_active |
64 | 64 | GROUP BY `tag`"; |
65 | - $bindings = [ |
|
66 | - 'is_active' => 1, |
|
67 | - ]; |
|
65 | + $bindings = [ |
|
66 | + 'is_active' => 1, |
|
67 | + ]; |
|
68 | 68 | |
69 | - return $this |
|
70 | - ->connections |
|
71 | - ->getRead() |
|
72 | - ->fetchAll($query, $bindings); |
|
73 | - } |
|
69 | + return $this |
|
70 | + ->connections |
|
71 | + ->getRead() |
|
72 | + ->fetchAll($query, $bindings); |
|
73 | + } |
|
74 | 74 | |
75 | - public function getTagsForPost($post) |
|
76 | - { |
|
77 | - $query = " |
|
75 | + public function getTagsForPost($post) |
|
76 | + { |
|
77 | + $query = " |
|
78 | 78 | SELECT `tag`.* |
79 | 79 | FROM `jpemeric_blog`.`tag` |
80 | 80 | INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`tag_id` AND `post_id` = :post |
81 | 81 | ORDER BY `tag`"; |
82 | - $bindings = [ |
|
83 | - 'post' => $post, |
|
84 | - ]; |
|
82 | + $bindings = [ |
|
83 | + 'post' => $post, |
|
84 | + ]; |
|
85 | 85 | |
86 | - return $this |
|
87 | - ->connections |
|
88 | - ->getRead() |
|
89 | - ->fetchAll($query, $bindings); |
|
90 | - } |
|
86 | + return $this |
|
87 | + ->connections |
|
88 | + ->getRead() |
|
89 | + ->fetchAll($query, $bindings); |
|
90 | + } |
|
91 | 91 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | interface TagRepository |
6 | 6 | { |
7 | - public function findTagByTitle($title); |
|
8 | - public function getAllTags(); |
|
9 | - public function getTagCloud(); |
|
10 | - public function getTagsForPost($post); |
|
7 | + public function findTagByTitle($title); |
|
8 | + public function getAllTags(); |
|
9 | + public function getTagCloud(); |
|
10 | + public function getTagsForPost($post); |
|
11 | 11 | } |
@@ -4,5 +4,5 @@ |
||
4 | 4 | |
5 | 5 | interface IntroductionRepository |
6 | 6 | { |
7 | - public function findByType($type, $value = ''); |
|
7 | + public function findByType($type, $value = ''); |
|
8 | 8 | } |
@@ -7,38 +7,38 @@ |
||
7 | 7 | class MysqlIntroductionRepository implements IntroductionRepository |
8 | 8 | { |
9 | 9 | |
10 | - /** @var Aura\Sql\ConnectionLocator */ |
|
11 | - protected $connections; |
|
10 | + /** @var Aura\Sql\ConnectionLocator */ |
|
11 | + protected $connections; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @param Aura\Sql\ConnectionLocator |
|
15 | - */ |
|
16 | - public function __construct(ConnectionLocator $connections) |
|
17 | - { |
|
18 | - $this->connections = $connections; |
|
19 | - } |
|
13 | + /** |
|
14 | + * @param Aura\Sql\ConnectionLocator |
|
15 | + */ |
|
16 | + public function __construct(ConnectionLocator $connections) |
|
17 | + { |
|
18 | + $this->connections = $connections; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $type |
|
23 | - * @param string $value |
|
24 | - * |
|
25 | - * @return array|false |
|
26 | - */ |
|
27 | - public function findByType($type, $value = '') |
|
28 | - { |
|
29 | - $query = " |
|
21 | + /** |
|
22 | + * @param string $type |
|
23 | + * @param string $value |
|
24 | + * |
|
25 | + * @return array|false |
|
26 | + */ |
|
27 | + public function findByType($type, $value = '') |
|
28 | + { |
|
29 | + $query = " |
|
30 | 30 | SELECT `title`, `content`, `image` |
31 | 31 | FROM `jpemeric_blog`.`introduction` |
32 | 32 | WHERE `type` = :type AND `value` = :value |
33 | 33 | LIMIT 1"; |
34 | - $bindings = [ |
|
35 | - 'type' => $type, |
|
36 | - 'value' => $value, |
|
37 | - ]; |
|
34 | + $bindings = [ |
|
35 | + 'type' => $type, |
|
36 | + 'value' => $value, |
|
37 | + ]; |
|
38 | 38 | |
39 | - return $this |
|
40 | - ->connections |
|
41 | - ->getRead() |
|
42 | - ->fetchOne($query, $bindings); |
|
43 | - } |
|
39 | + return $this |
|
40 | + ->connections |
|
41 | + ->getRead() |
|
42 | + ->fetchOne($query, $bindings); |
|
43 | + } |
|
44 | 44 | } |
@@ -7,21 +7,21 @@ discard block |
||
7 | 7 | class MysqlPostRepositoryTest extends PHPUnit_Framework_TestCase |
8 | 8 | { |
9 | 9 | |
10 | - protected $connections; |
|
11 | - |
|
12 | - public function __construct() |
|
13 | - { |
|
14 | - $extendedPdo = $this->newExtendedPdo(); |
|
15 | - $this->connections = new ConnectionLocator(function () use ($extendedPdo) { |
|
16 | - return $extendedPdo; |
|
17 | - }); |
|
18 | - } |
|
19 | - |
|
20 | - protected function newExtendedPdo() |
|
21 | - { |
|
22 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
23 | - $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
24 | - $extendedPdo->exec(" |
|
10 | + protected $connections; |
|
11 | + |
|
12 | + public function __construct() |
|
13 | + { |
|
14 | + $extendedPdo = $this->newExtendedPdo(); |
|
15 | + $this->connections = new ConnectionLocator(function () use ($extendedPdo) { |
|
16 | + return $extendedPdo; |
|
17 | + }); |
|
18 | + } |
|
19 | + |
|
20 | + protected function newExtendedPdo() |
|
21 | + { |
|
22 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
23 | + $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
24 | + $extendedPdo->exec(" |
|
25 | 25 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` ( |
26 | 26 | `id` integer PRIMARY KEY AUTOINCREMENT, |
27 | 27 | `title` varchar(60) NOT NULL, |
@@ -31,88 +31,88 @@ discard block |
||
31 | 31 | `body` text NOT NULL, |
32 | 32 | `display` integer NOT NULL |
33 | 33 | )" |
34 | - ); |
|
35 | - return $extendedPdo; |
|
36 | - } |
|
37 | - |
|
38 | - public function newMysqlPostRepository() |
|
39 | - { |
|
40 | - return new MysqlPostRepository($this->connections); |
|
41 | - } |
|
42 | - |
|
43 | - public function testConstructSetsConnections() |
|
44 | - { |
|
45 | - $this->assertAttributeEquals( |
|
46 | - $this->connections, |
|
47 | - 'connections', |
|
48 | - $this->newMysqlPostRepository() |
|
49 | - ); |
|
50 | - } |
|
51 | - |
|
52 | - public function testFindPostByPath() |
|
53 | - { |
|
54 | - $test_active_post = array( |
|
55 | - 'title' => 'test findByPath active', |
|
56 | - 'path' => 'test-findbypath-active', |
|
57 | - 'category' => 'test-category', |
|
58 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
59 | - 'body' => 'test content', |
|
60 | - 'display' => 1 |
|
61 | - ); |
|
62 | - |
|
63 | - $this->connections->getDefault()->perform(" |
|
34 | + ); |
|
35 | + return $extendedPdo; |
|
36 | + } |
|
37 | + |
|
38 | + public function newMysqlPostRepository() |
|
39 | + { |
|
40 | + return new MysqlPostRepository($this->connections); |
|
41 | + } |
|
42 | + |
|
43 | + public function testConstructSetsConnections() |
|
44 | + { |
|
45 | + $this->assertAttributeEquals( |
|
46 | + $this->connections, |
|
47 | + 'connections', |
|
48 | + $this->newMysqlPostRepository() |
|
49 | + ); |
|
50 | + } |
|
51 | + |
|
52 | + public function testFindPostByPath() |
|
53 | + { |
|
54 | + $test_active_post = array( |
|
55 | + 'title' => 'test findByPath active', |
|
56 | + 'path' => 'test-findbypath-active', |
|
57 | + 'category' => 'test-category', |
|
58 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
59 | + 'body' => 'test content', |
|
60 | + 'display' => 1 |
|
61 | + ); |
|
62 | + |
|
63 | + $this->connections->getDefault()->perform(" |
|
64 | 64 | INSERT INTO jpemeric_blog.post |
65 | 65 | (title, path, category, date, body, display) |
66 | 66 | VALUES |
67 | 67 | (:title, :path, :category, :date, :body, :display)", |
68 | - $test_active_post); |
|
69 | - |
|
70 | - $active_post = $this->newMysqlPostRepository()->findPostByPath( |
|
71 | - $test_active_post['category'], |
|
72 | - $test_active_post['path'] |
|
73 | - ); |
|
74 | - $this->assertSame($test_active_post['title'], $active_post['title']); |
|
75 | - |
|
76 | - $test_inactive_post = array( |
|
77 | - 'title' => 'test findByPath inactive', |
|
78 | - 'path' => 'test-findbypath-inactive', |
|
79 | - 'category' => 'test-category', |
|
80 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
81 | - 'body' => 'test content', |
|
82 | - 'display' => 0 |
|
83 | - ); |
|
84 | - |
|
85 | - $this->connections->getDefault()->perform(" |
|
68 | + $test_active_post); |
|
69 | + |
|
70 | + $active_post = $this->newMysqlPostRepository()->findPostByPath( |
|
71 | + $test_active_post['category'], |
|
72 | + $test_active_post['path'] |
|
73 | + ); |
|
74 | + $this->assertSame($test_active_post['title'], $active_post['title']); |
|
75 | + |
|
76 | + $test_inactive_post = array( |
|
77 | + 'title' => 'test findByPath inactive', |
|
78 | + 'path' => 'test-findbypath-inactive', |
|
79 | + 'category' => 'test-category', |
|
80 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
81 | + 'body' => 'test content', |
|
82 | + 'display' => 0 |
|
83 | + ); |
|
84 | + |
|
85 | + $this->connections->getDefault()->perform(" |
|
86 | 86 | INSERT INTO jpemeric_blog.post |
87 | 87 | (title, path, category, date, body, display) |
88 | 88 | VALUES |
89 | 89 | (:title, :path, :category, :date, :body, :display)", |
90 | - $test_inactive_post); |
|
91 | - |
|
92 | - $inactive_post = $this->newMysqlPostRepository()->findPostByPath( |
|
93 | - $test_inactive_post['category'], |
|
94 | - $test_inactive_post['path'] |
|
95 | - ); |
|
96 | - $this->assertFalse($inactive_post); |
|
97 | - |
|
98 | - $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath( |
|
99 | - 'test-category', |
|
100 | - 'test-findbypath-nonexistant' |
|
101 | - ); |
|
102 | - $this->assertFalse($nonexistant_post); |
|
90 | + $test_inactive_post); |
|
91 | + |
|
92 | + $inactive_post = $this->newMysqlPostRepository()->findPostByPath( |
|
93 | + $test_inactive_post['category'], |
|
94 | + $test_inactive_post['path'] |
|
95 | + ); |
|
96 | + $this->assertFalse($inactive_post); |
|
97 | + |
|
98 | + $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath( |
|
99 | + 'test-category', |
|
100 | + 'test-findbypath-nonexistant' |
|
101 | + ); |
|
102 | + $this->assertFalse($nonexistant_post); |
|
103 | 103 | } |
104 | 104 | |
105 | - public function testIsInstanceOfPostRepository() |
|
106 | - { |
|
107 | - $this->assertInstanceOf( |
|
108 | - 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
109 | - $this->newMysqlPostRepository() |
|
110 | - ); |
|
111 | - } |
|
105 | + public function testIsInstanceOfPostRepository() |
|
106 | + { |
|
107 | + $this->assertInstanceOf( |
|
108 | + 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
109 | + $this->newMysqlPostRepository() |
|
110 | + ); |
|
111 | + } |
|
112 | 112 | |
113 | - public static function tearDownAfterClass() |
|
114 | - { |
|
113 | + public static function tearDownAfterClass() |
|
114 | + { |
|
115 | 115 | // $this->connections->getDefault()->disconnect(); |
116 | - unlink('jpemeric_blog.db'); |
|
117 | - } |
|
116 | + unlink('jpemeric_blog.db'); |
|
117 | + } |
|
118 | 118 | } |
@@ -179,16 +179,16 @@ |
||
179 | 179 | return self::instance()->is_live; |
180 | 180 | } |
181 | 181 | |
182 | - public static function getRootURL($site = '') |
|
183 | - { |
|
184 | - if (strlen($site) > 0) { |
|
185 | - if ($site == 'waterfalls' && self::instance()->is_live) { |
|
186 | - return 'http://www.waterfallsofthekeweenaw.com/'; |
|
187 | - } else { |
|
188 | - return 'http://' . (self::instance()->is_live ? '' : 'dev.') . $site . '.jacobemerick.com/'; |
|
189 | - } |
|
190 | - } |
|
191 | - return '/'; |
|
192 | - } |
|
182 | + public static function getRootURL($site = '') |
|
183 | + { |
|
184 | + if (strlen($site) > 0) { |
|
185 | + if ($site == 'waterfalls' && self::instance()->is_live) { |
|
186 | + return 'http://www.waterfallsofthekeweenaw.com/'; |
|
187 | + } else { |
|
188 | + return 'http://' . (self::instance()->is_live ? '' : 'dev.') . $site . '.jacobemerick.com/'; |
|
189 | + } |
|
190 | + } |
|
191 | + return '/'; |
|
192 | + } |
|
193 | 193 | |
194 | 194 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | $handle = @fopen($configuration_path, 'r'); |
9 | 9 | if ($handle === false) { |
10 | - throw new RuntimeException("Could not load configuration"); |
|
10 | + throw new RuntimeException("Could not load configuration"); |
|
11 | 11 | } |
12 | 12 | $configuration = fread($handle, filesize($configuration_path)); |
13 | 13 | fclose($handle); |
@@ -15,40 +15,40 @@ discard block |
||
15 | 15 | $configuration = json_decode($configuration); |
16 | 16 | $last_json_error = json_last_error(); |
17 | 17 | if ($last_json_error !== JSON_ERROR_NONE) { |
18 | - throw new RuntimeException("Could not parse configuration - JSON error detected"); |
|
18 | + throw new RuntimeException("Could not parse configuration - JSON error detected"); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | // configure the db connections holder |
22 | 22 | $db_connections = new Aura\Sql\ConnectionLocator(); |
23 | 23 | $db_connections->setDefault(function () use ($configuration) { |
24 | - $connection = $configuration->database->slave; |
|
25 | - return new Aura\Sql\ExtendedPdo( |
|
26 | - "mysql:host={$connection->host}", |
|
27 | - $connection->user, |
|
28 | - $connection->password |
|
29 | - ); |
|
24 | + $connection = $configuration->database->slave; |
|
25 | + return new Aura\Sql\ExtendedPdo( |
|
26 | + "mysql:host={$connection->host}", |
|
27 | + $connection->user, |
|
28 | + $connection->password |
|
29 | + ); |
|
30 | 30 | }); |
31 | 31 | $db_connections->setWrite('master', function () use ($configuration) { |
32 | - $connection = $configuration->database->master; |
|
33 | - return new Aura\Sql\ExtendedPdo( |
|
34 | - "mysql:host={$connection->host}", |
|
35 | - $connection->user, |
|
36 | - $connection->password |
|
37 | - ); |
|
32 | + $connection = $configuration->database->master; |
|
33 | + return new Aura\Sql\ExtendedPdo( |
|
34 | + "mysql:host={$connection->host}", |
|
35 | + $connection->user, |
|
36 | + $connection->password |
|
37 | + ); |
|
38 | 38 | }); |
39 | 39 | $db_connections->setRead('slave', function () use ($configuration) { |
40 | - $connection = $configuration->database->slave; |
|
41 | - $pdo = new Aura\Sql\ExtendedPdo( |
|
42 | - "mysql:host={$connection->host}", |
|
43 | - $connection->user, |
|
44 | - $connection->password |
|
45 | - ); |
|
46 | - |
|
47 | - $profiler = new Aura\Sql\Profiler(); |
|
48 | - $profiler->setActive(true); |
|
49 | - $pdo->setProfiler($profiler); |
|
50 | - |
|
51 | - return $pdo; |
|
40 | + $connection = $configuration->database->slave; |
|
41 | + $pdo = new Aura\Sql\ExtendedPdo( |
|
42 | + "mysql:host={$connection->host}", |
|
43 | + $connection->user, |
|
44 | + $connection->password |
|
45 | + ); |
|
46 | + |
|
47 | + $profiler = new Aura\Sql\Profiler(); |
|
48 | + $profiler->setActive(true); |
|
49 | + $pdo->setProfiler($profiler); |
|
50 | + |
|
51 | + return $pdo; |
|
52 | 52 | }); |
53 | 53 | |
54 | 54 | // setup the service locator |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | private function __construct() |
19 | 19 | { |
20 | 20 | $this->console = new Console(); |
21 | - $this->profiler = new PhpQuickProfiler(); |
|
22 | - $this->profiler->setConsole($this->console); |
|
21 | + $this->profiler = new PhpQuickProfiler(); |
|
22 | + $this->profiler->setConsole($this->console); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public static function instance() |
@@ -82,25 +82,25 @@ discard block |
||
82 | 82 | |
83 | 83 | public static function display() |
84 | 84 | { |
85 | - if ($_COOKIE['debugger'] == 'display' && self::instance()->display) { |
|
86 | - $pdo = ''; |
|
87 | - if (!empty($pdo)) { |
|
88 | - $profiles = $pdo->getProfiler()->getProfiles(); |
|
89 | - $profiles = array_filter($profiles, function ($profile) { |
|
90 | - return $profile['function'] == 'perform'; |
|
91 | - }); |
|
92 | - $profiles = array_map(function ($profile) { |
|
93 | - return array( |
|
94 | - 'sql' => $profile['statement'], |
|
95 | - 'parameters' => $profile['bind_values'], |
|
96 | - 'time' => $profile['duration'] |
|
97 | - ); |
|
98 | - }, $profiles); |
|
99 | - self::instance()->profiler->setProfiledQueries($profiles); |
|
100 | - } |
|
101 | - self::instance()->profiler->setDisplay(new Particletree\Pqp\Display()); |
|
102 | - self::instance()->profiler->display($pdo); |
|
103 | - } |
|
85 | + if ($_COOKIE['debugger'] == 'display' && self::instance()->display) { |
|
86 | + $pdo = ''; |
|
87 | + if (!empty($pdo)) { |
|
88 | + $profiles = $pdo->getProfiler()->getProfiles(); |
|
89 | + $profiles = array_filter($profiles, function ($profile) { |
|
90 | + return $profile['function'] == 'perform'; |
|
91 | + }); |
|
92 | + $profiles = array_map(function ($profile) { |
|
93 | + return array( |
|
94 | + 'sql' => $profile['statement'], |
|
95 | + 'parameters' => $profile['bind_values'], |
|
96 | + 'time' => $profile['duration'] |
|
97 | + ); |
|
98 | + }, $profiles); |
|
99 | + self::instance()->profiler->setProfiledQueries($profiles); |
|
100 | + } |
|
101 | + self::instance()->profiler->setDisplay(new Particletree\Pqp\Display()); |
|
102 | + self::instance()->profiler->display($pdo); |
|
103 | + } |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | } |