コード例 #1
0
ファイル: AsEnum.class.php プロジェクト: xp-framework/csv
 /**
  * Processes cell value
  *
  * @param   var in
  * @return  var
  * @throws  lang.FormatException
  */
 public function process($in)
 {
     try {
         return $this->proceed(Enum::valueOf($this->enum, $in));
     } catch (\lang\IllegalArgumentException $e) {
         throw new \lang\FormatException($e->getMessage());
     }
 }
コード例 #2
0
 public function abstract_enum_with_one_member()
 {
     $class = self::define('abstract enum', 'PartialOperation', null, '{
   plus {
     public int evaluate(int $x, int $y) { return $x + $y; }
   };
   
   public abstract int evaluate(int $x, int $y);
 }');
     $this->assertEquals('SourcePartialOperation', $class->getName());
     $this->assertTrue($class->isEnum());
     $plus = Enum::valueOf($class, 'plus');
     $this->assertEquals(2, $plus->evaluate(1, 1));
 }
コード例 #3
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->marshallers = create('new util.collections.HashTable<lang.Type, webservices.rest.TypeMarshaller>');
     // Deprecated!
     if (PHP_VERSION < 7 && ClassLoader::getDefault()->providesPackage('lang.types')) {
         $strings = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) {
             return $t->toString();
         }, 'unmarshal' => function (Type $target, $in) {
             return $target->newInstance($in);
         }]);
         $integers = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) {
             return $t->intValue();
         }, 'unmarshal' => function (Type $target, $in) {
             return $target->newInstance($in);
         }]);
         $decimals = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) {
             return $t->doubleValue();
         }, 'unmarshal' => function (Type $target, $in) {
             return $target->newInstance($in);
         }]);
         $booleans = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) {
             return (bool) $t->value;
         }, 'unmarshal' => function (Type $target, $in) {
             return $target->newInstance($in);
         }]);
         $this->marshallers[XPClass::forName('lang.types.String')] = $strings;
         $this->marshallers[XPClass::forName('lang.types.Character')] = $strings;
         $this->marshallers[XPClass::forName('lang.types.Long')] = $integers;
         $this->marshallers[XPClass::forName('lang.types.Integer')] = $integers;
         $this->marshallers[XPClass::forName('lang.types.Short')] = $integers;
         $this->marshallers[XPClass::forName('lang.types.Byte')] = $integers;
         $this->marshallers[XPClass::forName('lang.types.Float')] = $decimals;
         $this->marshallers[XPClass::forName('lang.types.Double')] = $decimals;
         $this->marshallers[XPClass::forName('lang.types.Boolean')] = $booleans;
     }
     $this->marshallers[XPClass::forName('lang.Enum')] = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) {
         return $t->name();
     }, 'unmarshal' => function (Type $target, $in) {
         return Enum::valueOf($target, (string) $in);
     }]);
 }
コード例 #4
0
 public function minus()
 {
     $this->assertEquals(-1, Enum::valueOf(self::$fixture, 'minus')->evaluate(1, 2));
 }
コード例 #5
0
 public function diff($type, $strdate1, $strdate2)
 {
     return DateMath::diff(Enum::valueOf(XPClass::forName('util.TimeInterval'), strtoupper($type)), new Date($strdate1), new Date($strdate2));
 }
コード例 #6
0
 public function monday_is_not_a_weekend()
 {
     $this->assertFalse(Enum::valueOf(self::$fixture, 'MON')->isWeekend());
 }
コード例 #7
0
 public function member_color($name, $ordinal, $color)
 {
     $this->assertEquals($color, Enum::valueOf(self::$fixture, $name)->color());
 }
コード例 #8
0
 public function staticMemberNotWithEnumValueOf()
 {
     \lang\Enum::valueOf(\lang\XPClass::forName('net.xp_framework.unittest.core.Profiling'), 'fixture');
 }
コード例 #9
0
ファイル: Fields.class.php プロジェクト: xp-framework/webtest
 /**
  * Return a field type
  *
  * @return  unittest.web.Fields
  */
 public static function forTag($type)
 {
     return parent::valueOf(\lang\XPClass::forName('unittest.web.Fields'), strtoupper($type));
 }
コード例 #10
0
 /**
  * Returns a operation member by a specified name, case-insensitively
  *
  * @param  string $name
  * @return text.json.patch.Operations
  */
 public static function named($name)
 {
     return parent::valueOf(new XPClass(self::class), strtoupper($name));
 }
コード例 #11
0
ファイル: Currency.class.php プロジェクト: johannes85/core
 /**
  * Gets the currency instance for a given currency code
  *
  * @param   string code ISO 4217 code
  * @return  self
  * @throws  lang.IllegalArgumentException
  */
 public static function getInstance($code)
 {
     return parent::valueOf(new XPClass(__CLASS__), $code);
 }
コード例 #12
0
ファイル: Currency.class.php プロジェクト: xp-framework/core
 /**
  * Gets the currency instance for a given currency code
  *
  * @param   string code ISO 4217 code
  * @return  self
  * @throws  lang.IllegalArgumentException
  */
 public static function getInstance($code)
 {
     return parent::valueOf(new XPClass(self::class), $code);
 }