Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

localization

  • Loading branch information...
commit ebd1ae473bd16cf1af2e5be2df84e9d349103f90 1 parent 82f8538
@jarnix authored
View
6 library/php/classes/Nf/Bootstrap.php
@@ -403,6 +403,9 @@ function go(){
$labelManager=LabelManager::getInstance();
$labelManager->loadLabels(Registry::get('locale'));
+ $localization=Localization::getInstance();
+ $localization->setLocale(Registry::get('locale'));
+
$testDispatch=$front->dispatch();
if($testDispatch) {
@@ -444,6 +447,9 @@ function go(){
$labelManager=LabelManager::getInstance();
$labelManager->loadLabels(Registry::get('locale'));
+ $localization=Localization::getInstance();
+ Localization::setLocale(Registry::get('locale'));
+
$testDispatch=$front->dispatch();
$requestIsClean=$request->sanitizeUri();
View
22 library/php/classes/Nf/Db/Adapter/Mysqli.php
@@ -2,6 +2,8 @@
namespace Nf\Db\Adapter;
+use Nf\Localization;
+
class Mysqli extends AbstractAdapter
{
@@ -96,7 +98,7 @@ public function lastInsertId($tableName = null, $primaryKey = null)
$mysqli = $this->_connection;
return (string) $mysqli->insert_id;
}
-
+
public function insert($tableName, array $bind) {
$sql="INSERT INTO " . $this->quoteIdentifier($tableName, true) . " SET ";
@@ -138,15 +140,15 @@ public function update($tableName, array $bind, $where = '') {
$res=$this->query($sql);
return $this->getConnection()->affected_rows;
}
-
+
public function delete($tableName, $where = '') {
-
+
if($where!='') {
$sql="DELETE FROM " . $this->quoteIdentifier($tableName, true) . " WHERE " . $where;
} else {
$sql="TRUNCATE TABLE" . $this->quoteIdentifier($tableName, true);
}
-
+
$res=$this->query($sql);
return $this->getConnection()->affected_rows;
}
@@ -174,7 +176,7 @@ public function multiQuery($queries) {
if(is_array($queries)) {
$queries = implode(';', $queries);
}
-
+
$ret=$mysqli->multi_query($queries);
if($ret===false) {
@@ -182,6 +184,16 @@ public function multiQuery($queries) {
}
}
+ public static function formatDate($inShortFormatDateOrTimestamp, $hasMinutes=false) {
+ $tstp=Localization::dateToTimestamp($inShortFormatDateOrTimestamp, Localization::SHORT, ($hasMinutes ? Localization::SHORT : Localization::NONE));
+ if($hasMinutes) {
+ return date('Y-m-d', $tstp);
+ }
+ else {
+ return date('Y-m-d H:i:s', $tstp);
+ }
+ }
+
/**
* Begin a transaction.
*
View
6 library/php/classes/Nf/Front/Request/Http.php
@@ -86,11 +86,7 @@ public function getParams() {
public function setPutFromRequest() {
if($this->_put===null) {
if($_SERVER['REQUEST_METHOD'] == 'PUT') {
- parse_str(file_get_contents("php://input"), $putVars);
- foreach($putVars as $key=>$val) {
- $this->_put = $key;
- return;
- }
+ $this->_put=file_get_contents("php://input");
}
}
else {
View
1  library/php/classes/Nf/Ini.php
@@ -40,6 +40,7 @@ class Ini
*/
public static function parse($filename, $process_sections = false, $section_name = null, $fallback_section_name=null)
{
+
// load the raw ini file
$ini = parse_ini_string(file_get_contents($filename), $process_sections);
View
66 library/php/classes/Nf/Localization.php
@@ -2,17 +2,20 @@
namespace Nf;
+use \IntlDateFormatter, \NumberFormatter;
+
class Localization extends Singleton
{
- /*
- démarrage bootstrap : locale définie
-
- */
-
protected static $_instance;
- protected static $_currentLocale='fr_FR';
+ protected $_currentLocale='fr_FR';
+
+ const NONE=IntlDateFormatter::NONE;
+ const SHORT=IntlDateFormatter::SHORT;
+ const MEDIUM=IntlDateFormatter::MEDIUM;
+ const LONG=IntlDateFormatter::LONG;
+ const FULL=IntlDateFormatter::FULL;
public static function normalizeLocale($str) {
$str=str_replace('-', '_', $str);
@@ -21,5 +24,56 @@ public static function normalizeLocale($str) {
return $out;
}
+ public static function setLocale($locale) {
+ $instance=self::$_instance;
+ $instance->_currentLocale=$locale;
+ }
+
+ public static function getLocale() {
+ $instance=self::$_instance;
+ return $instance->_currentLocale;
+ }
+
+ public static function formatDate($timestamp, $formatDate=self::SHORT, $formatTime=self::SHORT) {
+ $instance=self::$_instance;
+ $fmt=new IntlDateFormatter($instance->_currentLocale, $formatDate, $formatTime);
+ return $fmt->format($timestamp);
+ }
+
+ public static function formatCurrency($amount, $currency) {
+ $instance=self::$_instance;
+ $fmt = new NumberFormatter($instance->_currentLocale(), NumberFormatter::CURRENCY);
+ return $fmt->formatCurrency($amount, $currency);
+ }
+
+ public static function formatNumber($value) {
+ $instance=self::$_instance;
+ $fmt = new NumberFormatter($instance->_currentLocale(), NumberFormatter::DECIMAL);
+ return $fmt->format($value);
+ }
+
+ public static function dateToTimestamp($date, $formatDate=self::SHORT, $formatTime=self::SHORT) {
+ if(self::isTimestamp($date)) {
+ return $date;
+ }
+ else {
+ $instance=self::$_instance;
+ $fmt=new IntlDateFormatter($instance->_currentLocale, $formatDate, $formatTime);
+ $timestamp=$fmt->parse($date);
+ if($timestamp) {
+ return $timestamp;
+ }
+ else {
+ throw new \Exception('input date is in another format and is not recognized:' . $date);
+ }
+ }
+
+ }
+
+ public static function isTimestamp($timestamp) {
+ return ((string) (int) $timestamp === $timestamp)
+ && ($timestamp <= PHP_INT_MAX)
+ && ($timestamp >= ~PHP_INT_MAX);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.