Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Added logger. |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
6cf00614094c0b4839dae60eb7cf2633 |
User & Date: | Spravce 2012-11-17 14:17:16.796 |
Context
2012-11-17
| ||
20:35 | Added first version of roll implementation. check-in: 38001529be user: Spravce tags: trunk | |
14:17 | Added logger. check-in: 6cf0061409 user: Spravce tags: trunk | |
12:44 | Some minor changes. Added view. check-in: fc60da8312 user: Spravce tags: trunk | |
Changes
Changes to brickyard.html.
︙ | ︙ | |||
159 160 161 162 163 164 165 166 167 168 169 170 171 | <p>If framework is in develMode, we will show debug message.</p> <pre id="exception handling" title="exception handling"> if ($this->inDevelMode){ $this->bluescreen($e); } else { <<detect type of exception>> <<show error message>> } </pre> | > > > > > > > > > | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | <p>If framework is in develMode, we will show debug message.</p> <pre id="exception handling" title="exception handling"> if ($this->inDevelMode){ $this->bluescreen($e); } else { <<log exception>> <<detect type of exception>> <<show error message>> } </pre> <p>Firstly we log this exception.</p> <pre id="log exception" title="log exception"> $this->logger->logException($e); </pre> <p>Than we detect type of exception.</p> <pre id="detect type of exception" title="detect type of exception"> if ($e instanceof brickyard_exception_404){ $err = 404; } elseif ($e instanceof brickyard_exception_403){ $err = 403; |
︙ | ︙ | |||
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | <p>Here follows some setting of framework.</p> <pre id="defaults" title="defaults"> public $inDevelMode = false; public $router = null; public $libPath = '.'; public $indexPath = '.'; </pre> <p>Some default instances are created in constructor.</p> <pre id="defaults" title="defaults"> public function __construct(){ $this->router = new brickyard_router_default; $this->libPath = dirname(__FILE__); $this->view = new brickyard_view_default(dirname(__FILE__) . DIRECTORY_SEPARATOR . "tpl"); } </pre> <h3>Setters and getters</h3> | > > > | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | <p>Here follows some setting of framework.</p> <pre id="defaults" title="defaults"> public $inDevelMode = false; public $router = null; public $view = null; public $logger = null; public $libPath = '.'; public $indexPath = '.'; </pre> <p>Some default instances are created in constructor.</p> <pre id="defaults" title="defaults"> public function __construct(){ $this->router = new brickyard_router_default; $this->logger = new brickyard_logger_null; $this->libPath = dirname(__FILE__); $this->view = new brickyard_view_default(dirname(__FILE__) . DIRECTORY_SEPARATOR . "tpl"); } </pre> <h3>Setters and getters</h3> |
︙ | ︙ | |||
319 320 321 322 323 324 325 326 327 328 329 330 331 332 | <pre id="setters" title="setters"> public function setView(brickyard_view_interface $view) { $this->view = $view; } </pre> <p>And for indexPath.</p> <pre id="getters" title="getters"> public function getIndexPath() | > > > > > > > > > > > > > > > > > > > > | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | <pre id="setters" title="setters"> public function setView(brickyard_view_interface $view) { $this->view = $view; } </pre> <p>For loggers.</p> <pre id="getters" title="getters"> public function getLogger() { return $this->logger; } </pre> <pre id="setters" title="setters"> public function setLogger(brickyard_logger_interface $logger) { $this->logger = $logger; } </pre> <p>And for indexPath.</p> <pre id="getters" title="getters"> public function getIndexPath() |
︙ | ︙ | |||
509 510 511 512 513 514 515 | <h2>Implementation</h2> <p>(Unexplained yet)</p> <pre id="brickyard default view" title="brickyard default view"> | | | 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | <h2>Implementation</h2> <p>(Unexplained yet)</p> <pre id="brickyard default view" title="brickyard default view"> class brickyard_view_default implements brickyard_view_interface { private $tplPath="tpl"; function __construct($tplPath) { $this->tplPath = $tplPath; } |
︙ | ︙ | |||
533 534 535 536 537 538 539 540 541 542 543 544 545 546 | $output = ob_get_contents(); ob_end_clean(); return $output; } else { throw new Exception('Template '.$tplName.' not found in file '.$tplFile); } } } </pre> <h1>Appendix</h1> <h2>exceptions</h2> | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | $output = ob_get_contents(); ob_end_clean(); return $output; } else { throw new Exception('Template '.$tplName.' not found in file '.$tplFile); } } } </pre> <h2>Brickyard logger</h2> <h3>Interface</h3> <p>Provides method to log exceptions.</p> <pre id="brickyard logger interface" title="brickyard logger interface"> interface brickyard_logger_interface { public function logException(Exception $e); } </pre> <h3>Null implementation</h3> <p>Default logger instance is empty.</p> <pre id="brickyard logger null" title="brickyard logger null"> class brickyard_logger_null implements brickyard_logger_interface { function logException(Exception $e) {} } </pre> <h3>File implementation</h3> <p>This is the first usable one.</p> <pre id="brickyard logger file" title="brickyard logger file"> class brickyard_logger_file implements brickyard_logger_interface { private $logFileName="log.txt"; function __construct($logFileName) { $this->logFileName = $logFileName; } function logException(Exception $e) { $logged = '== ' . date('Y-m-d H:i:s') . PHP_EOL . $e->getMessage() . PHP_EOL . $e->getFile() . ':' . $e->getLine() . PHP_EOL . $e->getTraceAsString() . PHP_EOL; file_put_contents($this->logFileName, $logged, FILE_APPEND); } } </pre> <h1>Appendix</h1> <h2>exceptions</h2> |
︙ | ︙ | |||
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | <<brickyard router interface>> <<brickyard default router>> <<brickyard view interface>> <<brickyard default view>> </pre> <h2>License</h2> <pre id="license" title="license"> //I am not yet decided about license. But I prefer WTFPL. </pre> </body></html> | > > > > > > | 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | <<brickyard router interface>> <<brickyard default router>> <<brickyard view interface>> <<brickyard default view>> <<brickyard logger interface>> <<brickyard logger null>> <<brickyard logger file>> </pre> <h2>License</h2> <pre id="license" title="license"> //I am not yet decided about license. But I prefer WTFPL. </pre> </body></html> |
Changes to brickyard.nw.
︙ | ︙ | |||
121 122 123 124 125 126 127 128 129 130 131 132 | If framework is in develMode, we will show debug message. <<exception handling>>== if ($this->inDevelMode){ $this->bluescreen($e); } else { <<detect type of exception>> <<show error message>> } @ | > > > > > > > | | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | If framework is in develMode, we will show debug message. <<exception handling>>== if ($this->inDevelMode){ $this->bluescreen($e); } else { <<log exception>> <<detect type of exception>> <<show error message>> } @ Firstly we log this exception. <<log exception>>== $this->logger->logException($e); @ Than we detect type of exception. <<detect type of exception>>== if ($e instanceof brickyard_exception_404){ $err = 404; } elseif ($e instanceof brickyard_exception_403){ $err = 403; } else { |
︙ | ︙ | |||
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | ###Default values Here follows some setting of framework. <<defaults>>== public $inDevelMode = false; public $router = null; public $libPath = '.'; public $indexPath = '.'; @ Some default instances are created in constructor. <<defaults>>== public function __construct(){ $this->router = new brickyard_router_default; $this->libPath = dirname(__FILE__); $this->view = new brickyard_view_default(dirname(__FILE__) . DIRECTORY_SEPARATOR . "tpl"); } @ ###Setters and getters | > > > | 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | ###Default values Here follows some setting of framework. <<defaults>>== public $inDevelMode = false; public $router = null; public $view = null; public $logger = null; public $libPath = '.'; public $indexPath = '.'; @ Some default instances are created in constructor. <<defaults>>== public function __construct(){ $this->router = new brickyard_router_default; $this->logger = new brickyard_logger_null; $this->libPath = dirname(__FILE__); $this->view = new brickyard_view_default(dirname(__FILE__) . DIRECTORY_SEPARATOR . "tpl"); } @ ###Setters and getters |
︙ | ︙ | |||
252 253 254 255 256 257 258 259 260 261 262 263 264 265 | <<setters>>== public function setView(brickyard_view_interface $view) { $this->view = $view; } @ And for indexPath. <<getters>>== public function getIndexPath() { | > > > > > > > > > > > > > > > > | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | <<setters>>== public function setView(brickyard_view_interface $view) { $this->view = $view; } @ For loggers. <<getters>>== public function getLogger() { return $this->logger; } @ <<setters>>== public function setLogger(brickyard_logger_interface $logger) { $this->logger = $logger; } @ And for indexPath. <<getters>>== public function getIndexPath() { |
︙ | ︙ | |||
421 422 423 424 425 426 427 | Interface of view is very simple. It offers only one function called `show` which accepts template name as first parameter and associative array as second parameter. This function returns filled template. ##Implementation (Unexplained yet) <<brickyard default view>>== | | | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | Interface of view is very simple. It offers only one function called `show` which accepts template name as first parameter and associative array as second parameter. This function returns filled template. ##Implementation (Unexplained yet) <<brickyard default view>>== class brickyard_view_default implements brickyard_view_interface { private $tplPath="tpl"; function __construct($tplPath) { $this->tplPath = $tplPath; } |
︙ | ︙ | |||
447 448 449 450 451 452 453 454 455 456 457 458 459 460 | return $output; } else { throw new Exception('Template '.$tplName.' not found in file '.$tplFile); } } } @ #Appendix ##exceptions Brickyard provides some useful exceptions. | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | return $output; } else { throw new Exception('Template '.$tplName.' not found in file '.$tplFile); } } } @ ##Brickyard logger ###Interface Provides method to log exceptions. <<brickyard logger interface>>== interface brickyard_logger_interface { public function logException(Exception $e); } @ ###Null implementation Default logger instance is empty. <<brickyard logger null>>== class brickyard_logger_null implements brickyard_logger_interface { function logException(Exception $e) {} } @ ###File implementation This is the first usable one. <<brickyard logger file>>== class brickyard_logger_file implements brickyard_logger_interface { private $logFileName="log.txt"; function __construct($logFileName) { $this->logFileName = $logFileName; } function logException(Exception $e) { $logged = '== ' . date('Y-m-d H:i:s') . PHP_EOL . $e->getMessage() . PHP_EOL . $e->getFile() . ':' . $e->getLine() . PHP_EOL . $e->getTraceAsString() . PHP_EOL; file_put_contents($this->logFileName, $logged, FILE_APPEND); } } @ #Appendix ##exceptions Brickyard provides some useful exceptions. |
︙ | ︙ | |||
495 496 497 498 499 500 501 502 503 504 505 506 507 | <<brickyard router interface>> <<brickyard default router>> <<brickyard view interface>> <<brickyard default view>> @ ##License <<license>>== //I am not yet decided about license. But I prefer WTFPL. @ | > > > > > > | 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | <<brickyard router interface>> <<brickyard default router>> <<brickyard view interface>> <<brickyard default view>> <<brickyard logger interface>> <<brickyard logger null>> <<brickyard logger file>> @ ##License <<license>>== //I am not yet decided about license. But I prefer WTFPL. @ |
Changes to brickyard.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 | <?php // // Brickyard framework by Severak // //I am not yet decided about license. But I prefer WTFPL. class brickyard { public $inDevelMode = false; public $router = null; public $libPath = '.'; public $indexPath = '.'; public function __construct(){ $this->router = new brickyard_router_default; $this->libPath = dirname(__FILE__); $this->view = new brickyard_view_default(dirname(__FILE__) . DIRECTORY_SEPARATOR . "tpl"); } public function getRouter() { return $this->router; } public function getView() { return $this->view; } public function getIndexPath() { return $this->indexPath; } public function setRouter(brickyard_router_interface $router) { $this->router = $router; } public function setView(brickyard_view_interface $view) { $this->view = $view; } public function setIndexPath($indexFilePath) { $this->indexPath = dirname($indexFilePath); } | > > > > > > > > > > > | 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 | <?php // // Brickyard framework by Severak // //I am not yet decided about license. But I prefer WTFPL. class brickyard { public $inDevelMode = false; public $router = null; public $view = null; public $logger = null; public $libPath = '.'; public $indexPath = '.'; public function __construct(){ $this->router = new brickyard_router_default; $this->logger = new brickyard_logger_null; $this->libPath = dirname(__FILE__); $this->view = new brickyard_view_default(dirname(__FILE__) . DIRECTORY_SEPARATOR . "tpl"); } public function getRouter() { return $this->router; } public function getView() { return $this->view; } public function getLogger() { return $this->logger; } public function getIndexPath() { return $this->indexPath; } public function setRouter(brickyard_router_interface $router) { $this->router = $router; } public function setView(brickyard_view_interface $view) { $this->view = $view; } public function setLogger(brickyard_logger_interface $logger) { $this->logger = $logger; } public function setIndexPath($indexFilePath) { $this->indexPath = dirname($indexFilePath); } |
︙ | ︙ | |||
64 65 66 67 68 69 70 71 72 73 74 75 76 77 | } public function exception_handler($e) { if ($this->inDevelMode){ $this->bluescreen($e); } else { if ($e instanceof brickyard_exception_404){ $err = 404; } elseif ($e instanceof brickyard_exception_403){ $err = 403; } else { $err = 'error'; } | > > | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | } public function exception_handler($e) { if ($this->inDevelMode){ $this->bluescreen($e); } else { $this->logger->logException($e); if ($e instanceof brickyard_exception_404){ $err = 404; } elseif ($e instanceof brickyard_exception_403){ $err = 403; } else { $err = 'error'; } |
︙ | ︙ | |||
248 249 250 251 252 253 254 | { public function show($templateName, array $data); } | | | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | { public function show($templateName, array $data); } class brickyard_view_default implements brickyard_view_interface { private $tplPath="tpl"; |
︙ | ︙ | |||
294 295 296 297 298 299 300 301 302 303 | } else { throw new Exception('Template '.$tplName.' not found in file '.$tplFile); } } } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | } else { throw new Exception('Template '.$tplName.' not found in file '.$tplFile); } } } interface brickyard_logger_interface { public function logException(Exception $e); } class brickyard_logger_null implements brickyard_logger_interface { function logException(Exception $e) {} } class brickyard_logger_file implements brickyard_logger_interface { private $logFileName="log.txt"; function __construct($logFileName) { $this->logFileName = $logFileName; } function logException(Exception $e) { $logged = '== ' . date('Y-m-d H:i:s') . PHP_EOL . $e->getMessage() . PHP_EOL . $e->getFile() . ':' . $e->getLine() . PHP_EOL . $e->getTraceAsString() . PHP_EOL; file_put_contents($this->logFileName, $logged, FILE_APPEND); } } |