summaryrefslogtreecommitdiff
path: root/lib/Minz
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-07-30 16:04:11 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-07-30 16:04:11 +0200
commit5fbbfdea8afdb399175abf18f1dcf1b6cabc2714 (patch)
tree6506dafeb093f78169feee0df648c48d3e97ebc6 /lib/Minz
parent214a5cc9a4c2b821961bc21f22b4b08e34b5be68 (diff)
parent3d4a75aa3d37a239a34e1fa35def261a2c988665 (diff)
Merge branch 'dev' into beta
Diffstat (limited to 'lib/Minz')
-rw-r--r--lib/Minz/Configuration.php28
-rw-r--r--lib/Minz/Extension.php2
-rw-r--r--lib/Minz/ModelPdo.php10
-rw-r--r--lib/Minz/Request.php45
-rw-r--r--lib/Minz/Url.php7
-rw-r--r--lib/Minz/View.php1
6 files changed, 51 insertions, 42 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index ab5bb4fc2..d695d4a53 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -39,7 +39,7 @@ class Minz_Configuration {
throw new Minz_FileNotExistException($filename);
}
- $data = @include($filename);
+ $data = include($filename);
if (is_array($data)) {
return $data;
} else {
@@ -85,11 +85,6 @@ class Minz_Configuration {
private $data = array();
/**
- * The default values, an empty array by default.
- */
- private $data_default = array();
-
- /**
* An object which help to set good values in configuration.
*/
private $configuration_setter = null;
@@ -119,21 +114,22 @@ class Minz_Configuration {
$configuration_setter = null) {
$this->namespace = $namespace;
$this->config_filename = $config_filename;
+ $this->default_filename = $default_filename;
+ $this->_configurationSetter($configuration_setter);
+
+ if (!is_null($this->default_filename)) {
+ $this->data = self::load($this->default_filename);
+ }
try {
- $this->data = self::load($this->config_filename);
+ $this->data = array_replace_recursive(
+ $this->data, self::load($this->config_filename)
+ );
} catch (Minz_FileNotExistException $e) {
- if (is_null($default_filename)) {
+ if (is_null($this->default_filename)) {
throw $e;
}
}
-
- $this->default_filename = $default_filename;
- if (!is_null($this->default_filename)) {
- $this->data_default = self::load($this->default_filename);
- }
-
- $this->_configurationSetter($configuration_setter);
}
/**
@@ -160,8 +156,6 @@ class Minz_Configuration {
return $this->data[$key];
} elseif (!is_null($default)) {
return $default;
- } elseif (isset($this->data_default[$key])) {
- return $this->data_default[$key];
} else {
Minz_Log::warning($key . ' does not exist in configuration');
return null;
diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php
index d7ee8fe81..78b8a2725 100644
--- a/lib/Minz/Extension.php
+++ b/lib/Minz/Extension.php
@@ -168,7 +168,7 @@ class Minz_Extension {
$url = '/ext.php?f=' . $file_name_url .
'&amp;t=' . $type .
'&amp;' . $mtime;
- return Minz_Url::display($url);
+ return Minz_Url::display($url, 'php');
}
/**
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php
index 3e8ec1f43..25999f02b 100644
--- a/lib/Minz/ModelPdo.php
+++ b/lib/Minz/ModelPdo.php
@@ -53,21 +53,19 @@ class Minz_ModelPdo {
$this->current_user = $currentUser;
self::$sharedCurrentUser = $currentUser;
+ $driver_options = isset($conf->db['pdo_options']) && is_array($conf->db['pdo_options']) ? $conf->db['pdo_options'] : array();
+
try {
$type = $db['type'];
if ($type === 'mysql') {
$string = 'mysql:host=' . $db['host']
. ';dbname=' . $db['base']
. ';charset=utf8';
- $driver_options = array(
- PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
- );
+ $driver_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8';
$this->prefix = $db['prefix'] . $currentUser . '_';
} elseif ($type === 'sqlite') {
$string = 'sqlite:' . join_path(DATA_PATH, 'users', $currentUser, 'db.sqlite');
- $driver_options = array(
- //PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- );
+ //$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$this->prefix = '';
} else {
throw new Minz_PDOConnectionException(
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index b9eda82a5..bf01bc26f 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -85,26 +85,37 @@ class Minz_Request {
}
/**
- * Détermine la base de l'url
- * @return la base de l'url
+ * Try to guess the base URL from $_SERVER information
+ *
+ * @return the base url (e.g. http://example.com/)
*/
- public static function getBaseUrl($baseUrlSuffix = '') {
- $conf = Minz_Configuration::get('system');
- $url = $conf->base_url;
- if ($url == '' || !preg_match('%^https?://%i', $url)) {
- $url = 'http';
- $host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'];
- $port = empty($_SERVER['SERVER_PORT']) ? 80 : $_SERVER['SERVER_PORT'];
- if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
- $url .= 's://' . $host . ($port == 443 ? '' : ':' . $port);
- } else {
- $url .= '://' . $host . ($port == 80 ? '' : ':' . $port);
- }
- $url .= isset($_SERVER['REQUEST_URI']) ? dirname($_SERVER['REQUEST_URI']) : '';
+ public static function guessBaseUrl() {
+ $url = 'http';
+ $host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'];
+ $port = empty($_SERVER['SERVER_PORT']) ? 80 : $_SERVER['SERVER_PORT'];
+ if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
+ $url .= 's://' . $host . ($port == 443 ? '' : ':' . $port);
} else {
- $url = rtrim($url, '/\\') . $baseUrlSuffix;
+ $url .= '://' . $host . ($port == 80 ? '' : ':' . $port);
}
- return filter_var($url . '/', FILTER_SANITIZE_URL);
+ if (isset($_SERVER['REQUEST_URI'])) {
+ $path = $_SERVER['REQUEST_URI'];
+ $url .= substr($path, -1) === '/' ? substr($path, 0, -1) : dirname($path);
+ }
+
+ return filter_var($url, FILTER_SANITIZE_URL);
+ }
+
+ /**
+ * Return the base_url from configuration and add a suffix if given.
+ *
+ * @param $base_url_suffix a string to add at base_url (default: empty string)
+ * @return the base_url with a suffix.
+ */
+ public static function getBaseUrl($base_url_suffix = '') {
+ $conf = Minz_Configuration::get('system');
+ $url = rtrim($conf->base_url, '/\\') . $base_url_suffix;
+ return filter_var($url, FILTER_SANITIZE_URL);
}
/**
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php
index 879077d0f..4279b045b 100644
--- a/lib/Minz/Url.php
+++ b/lib/Minz/Url.php
@@ -25,14 +25,19 @@ class Minz_Url {
if ($absolute) {
$url_string = Minz_Request::getBaseUrl(PUBLIC_TO_INDEX_PATH);
+ if ($url_string === PUBLIC_TO_INDEX_PATH) {
+ $url_string = Minz_Request::guessBaseUrl();
+ }
} else {
$url_string = $isArray ? '.' : PUBLIC_RELATIVE;
}
if ($isArray) {
$url_string .= self::printUri($url, $encodage);
- } else {
+ } elseif ($encodage === 'html') {
$url_string = Minz_Helper::htmlspecialchars_utf8($url_string . $url);
+ } else {
+ $url_string .= $url;
}
return $url_string;
diff --git a/lib/Minz/View.php b/lib/Minz/View.php
index ff5cce4a5..8c5230ab6 100644
--- a/lib/Minz/View.php
+++ b/lib/Minz/View.php
@@ -91,6 +91,7 @@ class Minz_View {
* Construit le layout
*/
public function buildLayout () {
+ header('Content-Type: text/html; charset=UTF-8');
$this->includeFile(self::LAYOUT_PATH_NAME . self::LAYOUT_FILENAME);
}