Skip to content

Commit

Permalink
use selenium environment closer to production
Browse files Browse the repository at this point in the history
  • Loading branch information
l3pp4rd committed Feb 23, 2013
1 parent 780e5a2 commit 3109b97
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
15 changes: 7 additions & 8 deletions README.md
Expand Up @@ -3,11 +3,10 @@
This repository source code is deployed on [gediminasm.org](http://gediminasm.org) my blog page. I have used **Symfony2**
before. But since it was too heavy for such a simple task, it was changed to use a most lightweight version possible. Why
I'm not using **Wordpress**? Well I'm a software engineer and I see fit to make things as light as they can be, I also
share [UNIX philosophy](http://en.wikipedia.org/wiki/Unix_philosophy) and for an engineer it is useful and necessary
to understand language, database, HTTP and many other internals, though always innovate.
share [UNIX philosophy](http://en.wikipedia.org/wiki/Unix_philosophy) and for an engineer it is important to always innovate.

Sadly it is also true, that to code a "framework" from scratch is even faster than to use any, which you are unfamiliar
with. Like a concept of [vanilla js](http://vanilla-js.com/)
This application is so simple that it cannot fail you, it gives complete control over everything without introducing
huge abstraction layer. I do not encourage folks to reuse any source code if you do not understand it.

## Requirements

Expand All @@ -19,14 +18,14 @@ with. Like a concept of [vanilla js](http://vanilla-js.com/)

Here is the whole "framework" structure:

- **framework.php** defines a dispacher and service container.
- **framework.php** defines a dispacher and service container. (~200 lines of code)
- **routing** is using standard regular expressions - maybe its time to get more friendly with it ha?
- **error_handler.php** all ways errors are handled.
- **error_handler.php** all ways errors may be handled.
- **controllers/** a directory where all controllers are registered.
- **services/** a directory where all services are registered, note: **config.php** is visible only in service
initialization scope.
- **commands/** a directory where all console commands are registered.
- **assets/** a directory where all assets are located, before they are being compiled to a production version.
- **assets/** a directory where all assets are located, before they are being compiled to production version.
- **models** there are none, but if needed, they can be registered as services.

There is no cache, because there is nothing to cache, except third party stuff like twig or whatever, which is used
Expand Down Expand Up @@ -115,7 +114,7 @@ Third, clone behat config for customization:

cp behat.yml.dist behat.yml

**Note:** you should create a separate virtual host for tests, so that it could use **testing** environment
**Note:** you should create a separate virtual host for tests, so that it could use **selenium_testing** environment

Edit **behat.yml** and update **base_url**. Finally, you can run all tests:

Expand Down
16 changes: 7 additions & 9 deletions config.php.dist
@@ -1,13 +1,13 @@
<?php

// default configurations for services used
// default configurations for services used (better keep production as default)
$conf = array(
'db' => array(
'name' => 'blog',
'dbname' => 'blog',
'host' => 'localhost',
'port' => 3306,
'user' => 'root',
'pass' => '',
'port' => 5432,
'user' => 'postgres',
'password' => 'postgres',
),
'twig' => array(
'debug' => false,
Expand All @@ -17,20 +17,18 @@ $conf = array(

// environment specific changes, can be moved to localized dist file
switch (APP_ENV) {

case 'production':
$conf['db']['pass'] = 'secret';
// should be default
break;

case 'testing':
$conf['db']['name'] = 'blog_test';
$conf['db']['dbname'] = 'blog_test';
$conf['twig']['debug'] = 'true';
break;

case 'development':
default:
$conf['twig']['debug'] = 'true';
$conf['db']['pass'] = 'nimda';
break;
}

Expand Down
2 changes: 1 addition & 1 deletion error_handling.php
Expand Up @@ -42,7 +42,7 @@ function get_exception_trace(Exception $e) {
// expects exception code to be HTTP code
http_response_code($code = $e->getCode() ?: 500); // create status code header
service('logger')->push("Caught [{$code}] exception: ".$e->getMessage()."\n --> ".implode("\n --> ", get_exception_trace($e)))->flush();
if (in_array(APP_ENV, array('production', 'testing'))) {
if (in_array(APP_ENV, array('production', 'selenium_testing'))) {
// first check for error file by code
if (file_exists($efile = APP_DIR.'/public/'.$code.'.html')) {
echo file_get_contents($efile);
Expand Down
9 changes: 5 additions & 4 deletions services/db.php
Expand Up @@ -2,6 +2,7 @@

service('db', function($config) {
class _DB {
/* connection link resource */
public $link;

function __construct($connection_string) {
Expand Down Expand Up @@ -55,22 +56,22 @@ function update($table, array $data, array $where = array()) {
return $this->query($sql, $params);
}

function mapsql($sql, array $args, Closure $mapper = null) {
function mapsql($sql, array $args) {
$formatter = function($v) {
return is_string($v) ? pg_escape_literal($this->link, $v) : $v;
};
if (is_int($i = key($args)) && $i === 0) {
$sql = preg_replace_callback('#\?#sm', function($m) use($args, &$i, &$mapper, &$formatter) {
$sql = preg_replace_callback('#\?#sm', function($m) use($args, &$i, &$formatter) {
if (!isset($args[$i])) {
throw new InvalidArgumentException("Psql: Missing an argument in query for ? mark");
}
return $mapper ? $mapper($i, $args[$i++], $formatter) : $formatter($args[$i++]);
return $formatter($args[$i++]);
}, $sql);
} else {
$search = $replace = array();
foreach ($args as $k => $v) {
$search[] = ':'.$k;
$replace[] = $mapper ? $mapper($k, $v, $formatter) : $formatter($v);
$replace[] = $formatter($v);
}
$sql = str_replace($search, $replace, $sql);
}
Expand Down
6 changes: 3 additions & 3 deletions services/logger.php
Expand Up @@ -8,10 +8,10 @@ class _Logger {
private $path;

private function open() {
if (!is_dir($dir = dirname($path)) && !mkdir($dir, 775, true)) {
if (!is_dir($dir = dirname($this->path)) && !mkdir($dir, 775, true)) {
die("Failed to create log directory [{$dir}] check permissions.");
} elseif (!$this->handle = fopen($path, 'a+')) {
die("Failed to open log file [{$path}] for writting.");
} elseif (!is_resource($this->handle = fopen($this->path, 'a+'))) {
die("Failed to open log file [{$this->path}] for writting.");
}
return true;
}
Expand Down

0 comments on commit 3109b97

Please sign in to comment.