-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from phemellc/master
Merging delta from phemelic
- Loading branch information
Showing
26 changed files
with
926 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
imports: | ||
- php | ||
|
||
tools: | ||
external_code_coverage: | ||
timeout: 1800 # Timeout in seconds. | ||
# disable copy paste detector and similarity analyzer as they have no real value | ||
# and a huge bunch of false-positives | ||
php_sim: false | ||
php_cpd: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
preset: psr2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
language: php | ||
|
||
matrix: | ||
fast_finish: true | ||
|
||
php: | ||
- 5.6 | ||
#- 7.1 | ||
|
||
# cache vendor dirs | ||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
- vendor | ||
|
||
services: | ||
- mysql | ||
|
||
install: | ||
- travis_retry composer self-update | ||
- composer config -g github-oauth.github.com dcb6b0049723eb6f56039b2d6389ac76eb29e352 | ||
- travis_retry composer install --prefer-dist --no-interaction | ||
- travis_retry mysql -e 'CREATE DATABASE test;' | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --no-interaction --prefer-source --dev | ||
|
||
script: | ||
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover | ||
|
||
after_script: | ||
- wget https://scrutinizer-ci.com/ocular.phar | ||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
use yii\base\Component; | ||
use yii\caching\Cache; | ||
use Yii; | ||
use yii\helpers\Json; | ||
|
||
/** | ||
* @author Aris Karageorgos <[email protected]> | ||
|
@@ -55,6 +56,12 @@ class Settings extends Component | |
*/ | ||
public $cacheKey = 'pheme/settings'; | ||
|
||
/** | ||
* @var bool Whether to convert objects stored as JSON into an PHP array | ||
* @since 0.6 | ||
*/ | ||
public $autoDecodeJson = false; | ||
|
||
/** | ||
* Holds a cached copy of the data for the current request | ||
* | ||
|
@@ -90,8 +97,8 @@ public function init() | |
* are equivalent | ||
* | ||
* @param $key | ||
* @param null $section | ||
* @param null $default | ||
* @param string|null $section | ||
* @param string|null $default | ||
* @return mixed | ||
*/ | ||
public function get($key, $section = null, $default = null) | ||
|
@@ -109,11 +116,36 @@ public function get($key, $section = null, $default = null) | |
$data = $this->getRawConfig(); | ||
|
||
if (isset($data[$section][$key][0])) { | ||
settype($data[$section][$key][0], $data[$section][$key][1]); | ||
if (in_array($data[$section][$key][1], ['object', 'boolean', 'bool', 'integer', 'int', 'float', 'string', 'array'])) { | ||
if ($this->autoDecodeJson && $data[$section][$key][1] === 'object') { | ||
$value = Json::decode($data[$section][$key][0]); | ||
} else { | ||
$value = $data[$section][$key][0]; | ||
settype($value, $data[$section][$key][1]); | ||
} | ||
} | ||
} else { | ||
$value = $default; | ||
} | ||
return $value; | ||
} | ||
|
||
/** | ||
* Checks to see if a setting exists. | ||
* If $searchDisabled is set to true, calling this function will result in an additional query. | ||
* @param $key | ||
* @param string|null $section | ||
* @param boolean $searchDisabled | ||
* @return boolean | ||
*/ | ||
public function has($key, $section = null, $searchDisabled = false) | ||
{ | ||
if ($searchDisabled) { | ||
$setting = $this->model->findSetting($key, $section); | ||
} else { | ||
$data[$section][$key][0] = $default; | ||
$setting = $this->get($key, $section); | ||
} | ||
return $data[$section][$key][0]; | ||
return is_null($setting) ? false : true; | ||
} | ||
|
||
/** | ||
|
@@ -132,13 +164,30 @@ public function set($key, $value, $section = null, $type = null) | |
} | ||
|
||
if ($this->model->setSetting($section, $key, $value, $type)) { | ||
if ($this->clearCache()) { | ||
return true; | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the specified key or sets the key with the supplied (default) value | ||
* | ||
* @param $key | ||
* @param $value | ||
* @param null $section | ||
* @param null $type | ||
* | ||
* @return bool|mixed | ||
*/ | ||
public function getOrSet($key, $value, $section = null, $type = null) | ||
{ | ||
if ($this->has($key, $section, true)) { | ||
return $this->get($key, $section); | ||
} else { | ||
return $this->set($key, $value, $section, $type); | ||
} | ||
} | ||
|
||
/** | ||
* Deletes a setting | ||
* | ||
|
@@ -227,9 +276,7 @@ public function getRawConfig() | |
{ | ||
if ($this->_data === null) { | ||
if ($this->cache instanceof Cache) { | ||
|
||
$data = $this->cache->get($this->cacheKey); | ||
|
||
if ($data === false) { | ||
$data = $this->model->getSettings(); | ||
$this->cache->set($this->cacheKey, $data); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Message translations. | ||
* | ||
* This file is automatically generated by 'yii message' command. | ||
* It contains the localizable messages extracted from source code. | ||
* You may modify this file by translating the extracted messages. | ||
* | ||
* Each array element represents the translation (value) of a message (key). | ||
* If the value is empty, the message is considered as not translated. | ||
* Messages that no longer need translation will have their translations | ||
* enclosed between a pair of '@@' marks. | ||
* | ||
* Message string can be used with plural forms format. Check i18n section | ||
* of the guide for details. | ||
* | ||
* NOTE: this file must be saved in UTF-8 encoding. | ||
*/ | ||
return [ | ||
'Active' => 'Activo', | ||
'Are you sure you want to delete this item?' => '¿Estás seguro que quieres eliminar esa configuración?', | ||
'Change at your own risk' => 'Cámbialo bajo tu propio riesgo', | ||
'Create' => 'Crear', | ||
'Create {modelClass}' => 'Crear {modelClass}', | ||
'Created' => 'Creado', | ||
'Delete' => 'Eliminar', | ||
'ID' => 'ID', | ||
'Key' => 'Clave', | ||
'Modified' => 'Modificado', | ||
'Please select correct type' => 'Por favor selecciona el tipo correcto', | ||
'Reset' => 'Restablecer', | ||
'Search' => 'Buscar', | ||
'Section' => 'Sección', | ||
'Setting' => 'Configuración', | ||
'Settings' => 'Configuraciones', | ||
'Successfully saved settings on {section}' => 'Configuración guardada correctamente en la sección {section}', | ||
'Type' => 'Tipo', | ||
'Update' => 'Actualizar', | ||
'Update {modelClass}: ' => 'Actualizar {modelClass}: ', | ||
'Value' => 'Valor', | ||
'{attribute} "{value}" already exists for this section.' => '{attribute} "{value}" ya existe en esta sección.', | ||
'"{attribute}" must be a valid JSON object' => '"{attribute}" debe ser un objeto JSON válido', | ||
'string' => 'Cadena de texto', | ||
'integer' => 'Entero', | ||
'boolean' => 'Booleano', | ||
'float' => 'Decimal', | ||
'email' => 'Correo electrónico', | ||
'ip' => 'Dirección IP', | ||
'url' => 'URL', | ||
'object' => 'Objeto', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Message translations. | ||
* | ||
* This file is automatically generated by 'yii message' command. | ||
* It contains the localizable messages extracted from source code. | ||
* You may modify this file by translating the extracted messages. | ||
* | ||
* Each array element represents the translation (value) of a message (key). | ||
* If the value is empty, the message is considered as not translated. | ||
* Messages that no longer need translation will have their translations | ||
* enclosed between a pair of '@@' marks. | ||
* | ||
* Message string can be used with plural forms format. Check i18n section | ||
* of the guide for details. | ||
* | ||
* NOTE: this file must be saved in UTF-8 encoding. | ||
*/ | ||
return [ | ||
'Active' => 'พร้อมทำงาน', | ||
'Are you sure you want to delete this item?' => 'คุณแน่ใจใช่ไหมว่าต้องการที่จะลบข้อมูลนี้?', | ||
'Change at your own risk' => 'เปลี่ยนข้อมูลมีความเสี่ยง', | ||
'Create' => 'สร้าง', | ||
'Create {modelClass}' => 'สร้าง {modelClass}', | ||
'Created' => 'สร้าง', | ||
'Delete' => 'ลบ', | ||
'ID' => 'ไอดี', | ||
'Key' => 'คีย์', | ||
'Modified' => 'แก้ไข', | ||
'Reset' => 'คืนค่า', | ||
'Search' => 'ค้นหา', | ||
'Section' => 'ส่วน', | ||
'Setting' => 'การตั้งค่า', | ||
'Settings' => 'การตั้งค่า', | ||
'Type' => 'ชนิด', | ||
'Update' => 'ปรับปรุง', | ||
'Update {modelClass}: ' => 'ปรับปรุง {modelClass}: ', | ||
'Value' => 'ค่า', | ||
'{attribute} "{value}" already exists for this section.' => '{attribute} "{value}" มีแล้วในะระบบ', | ||
'"{attribute}" must be a valid JSON object' => '"{attribute}" ต้องอยู่ในรูปแบบ JSON', | ||
'Please select correct type' => 'เลือกให้ตรงชนิด', | ||
'string' => 'ตัวอักษร', | ||
'integer' => 'ตัวเลข', | ||
'boolean' => '0 หรือ 1', | ||
'float' => 'ค่าทศนิยม', | ||
'email' => 'E-mail', | ||
'ip' => 'IP', | ||
'url' => 'URL', | ||
'object' => 'JSON', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Message translations. | ||
* | ||
* This file is automatically generated by 'yii message/extract' command. | ||
* It contains the localizable messages extracted from source code. | ||
* You may modify this file by translating the extracted messages. | ||
* | ||
* Each array element represents the translation (value) of a message (key). | ||
* If the value is empty, the message is considered as not translated. | ||
* Messages that no longer need translation will have their translations | ||
* enclosed between a pair of '@@' marks. | ||
* | ||
* Message string can be used with plural forms format. Check i18n section | ||
* of the guide for details. | ||
* | ||
* NOTE: this file must be saved in UTF-8 encoding. | ||
*/ | ||
return [ | ||
'ID' => 'ID', | ||
'Type' => 'Typ', | ||
'Section' => 'Grupa', | ||
'Key' => 'Klucz', | ||
'Value' => 'Wartość', | ||
'Status' => 'Status', | ||
'Description' => 'Opis', | ||
'Created Date' => 'Data utworzenia', | ||
'Updated Date' => 'Data aktualizacji', | ||
'Settings' => 'Konfiguracja', | ||
'Create Setting' => 'Dodaj konfigurację', | ||
'Select Type' => 'Wybierz typ', | ||
'Select Section' => 'Wybierz grupę', | ||
'Select Status' => 'Wybierz status', | ||
'Actions' => 'Akcje', | ||
'Active' => 'Aktywne', | ||
'Inactive' => 'Nieaktywne', | ||
'Update Setting: {0} -> {1}' => 'Edytuj konfigurację: {0} -> {1}', | ||
'Update Setting' => 'Edytuj konfigurację', | ||
'Update' => 'Aktualizuj', | ||
'Create' => 'Dodaj', | ||
'Delete' => 'Usuń', | ||
'Go Back' => 'Wstecz', | ||
'String' => 'Tekst', | ||
'Integer' => 'Liczba całkowita', | ||
'Boolean' => 'Prawda/Fałsz', | ||
'Float' => 'Liczba zmiennoprzecinkowa', | ||
'Null' => 'Null', | ||
'Setting has been created.' => 'Konfiguracja została dodana.', | ||
'Setting has been deleted.' => 'Konfiguracja została usunięta.', | ||
'Setting has been updated.' => 'Konfiguracja została zaktualizowana.', | ||
'The requested page does not exist.' => 'Szukana strona nie istnieje', | ||
]; |
Oops, something went wrong.