示例#1
0
 /**
  * @param null $arg
  * @return \JBZoo\SimpleTypes\Type\Type
  */
 public function val($arg = null)
 {
     $configName = '\\JBZoo\\SimpleTypes\\Config\\' . ucfirst($this->_type);
     $className = '\\JBZoo\\SimpleTypes\\Type\\' . $this->_type;
     Config::registerDefault($this->_type, new $configName());
     return new $className($arg);
 }
示例#2
0
 public function testEmptyDefault()
 {
     is(null, Config::getDefault('undefined'));
 }
示例#3
0
 /**
  * @param Config $config
  * @return Config
  * @throws \JBZoo\SimpleTypes\Exception
  */
 protected function _getConfig(Config $config = null)
 {
     $defaultConfig = Config::getDefault($this->_type);
     $config = $config ? $config : $defaultConfig;
     // Hack for getValidValue method
     if (!$defaultConfig && $config) {
         Config::registerDefault($this->_type, $config);
     }
     return $config;
 }
示例#4
0
/**
 * @param null $arg
 * @return \JBZoo\SimpleTypes\Type\Money
 */
function val($arg = null)
{
    Config::registerDefault('money', new ConfigMoney());
    return new Money($arg);
}
示例#5
0
 * @license   MIT
 * @copyright Copyright (C) JBZoo.com,  All rights reserved.
 * @link      https://github.com/JBZoo/SimpleTypes
 */
require_once __DIR__ . '/vendor/autoload.php';
use JBZoo\SimpleTypes\Type\Money;
use JBZoo\SimpleTypes\Config\Config;
use JBZoo\SimpleTypes\Type\Weight;
use JBZoo\SimpleTypes\Type\Length;
use JBZoo\SimpleTypes\Config\Money as ConfigMoney;
use JBZoo\SimpleTypes\Config\Weight as ConfigWeight;
use JBZoo\SimpleTypes\Config\Length as ConfigLength;
// Set config object for all Money objects as default
Config::registerDefault('money', new ConfigMoney());
Config::registerDefault('weight', new ConfigWeight());
Config::registerDefault('length', new ConfigLength());
// Create Money object that represents 1 EUR
// Some different ways
$money = new Money('10 eur');
$money = new Weight('1000');
// Gram is default in the ConfigWeight class
$money = new Length('500 km');
$money = new Money('100500 usd', new ConfigMoney());
// my custom params only for that object
// Smart parser can find number, understand decimal symbol, trim, letter cases, e.t.c...
$money = new Money(' - 1 2 3 , 4 5 6 rub ');
// Equals -123.456 rubles
$money = new Money('1.0e+18 EUR ');
// Really huge number
$money = new Money('  EuR 3,50   ');
$money = new Money('usd');