registerDefault() 공개 정적인 메소드

public static registerDefault ( string $type, Config $config )
$type string
$config Config
예제 #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 testRegisterDefault()
 {
     Config::registerDefault('weight', new ConfigTestWeight());
     Config::registerDefault('info', new ConfigTestInfo());
     // weight
     $weight1 = new Weight('1gram');
     $weight2 = new Weight('1kg');
     isBatch(array(array('1 gram', $weight1->dump(false)), array('1000 gram', $weight2->convert('gram')->dump(false))));
     // info
     $info1 = new Info(1);
     $info2 = new Info('1024byte');
     isBatch(array(array('1 byte', $info1->dump(false)), array('1 kb', $info2->convert('kb')->dump(false))));
 }
예제 #3
0
파일: Type.php 프로젝트: jbzoo/simpletypes
 /**
  * @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
파일: demo.php 프로젝트: jbzoo/simpletypes
 * @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');