예제 #1
2
 public function testAnyFieldIsPresentInSearchField()
 {
     $values = array('Key' => 'Value');
     $enumField = new Enum('testField', $values);
     $searchField = $enumField->scaffoldSearchField();
     $anyText = "(" . _t('Enum.ANY', 'Any') . ")";
     $this->assertEquals(true, $searchField->getHasEmptyDefault());
     $this->assertEquals($anyText, $searchField->getEmptyString());
 }
 public function prepValueForDB($value)
 {
     $value = parent::prepValueForDB($value);
     $ciphertext = $this->service->encrypt($value);
     $this->value = $ciphertext;
     return $ciphertext;
 }
예제 #3
0
 /**
  * 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 (IllegalArgumentException $e) {
         throw new FormatException($e->getMessage());
     }
 }
예제 #4
0
 private static function getConstants()
 {
     if (self::$calledClass != get_called_class() || self::$constCache === NULL) {
         $reflect = new ReflectionClass(get_called_class());
         self::$constCache = $reflect->getConstants();
     }
     return self::$constCache;
 }
예제 #5
0
 /**
  * Get defined values
  * 
  * @return array
  */
 private static function getConstants()
 {
     // Use Reflexion to get constants defined in child class
     if (self::$calledClass != get_called_class() || self::$constCache === null) {
         $reflect = new ReflectionClass(get_called_class());
         self::$constCache = $reflect->getConstants();
     }
     return self::$constCache;
 }
예제 #6
0
 /**
  * Creates this parameter source
  *
  */
 public function __construct($ordinal, $name)
 {
     parent::__construct($ordinal, $name);
     $this->convert = newinstance('webservices.rest.RestDeserializer', array(), '{
     public function deserialize($in, $target) {
       throw new IllegalStateException("Unused");
     }
   }');
 }
 /**
  *  set i18n namespace to the table name
  */
 public function setValue($value, $record = null)
 {
     parent::setValue($value, $record);
     if (is_array($record)) {
         $record = (object) $record;
     }
     if ($record && !empty($record->ClassName)) {
         $this->DbObjectName = $record->ClassName;
     }
 }
 /**
  * Returns the string which will be used in the template
  * @return string
  */
 public function forTemplate()
 {
     $isEditable = FrontendEditing::editingEnabled() && FrontendEditing::isEditable($this);
     $value = parent::forTemplate();
     if ($isEditable) {
         $field = $this->formField(null, null, false, $value)->setAttribute('data-feclass', FrontendEditing::getClassName($this))->setAttribute('data-feid', FrontendEditing::getID($this))->setAttribute('data-fefield', $this->name)->addExtraClass("frontend-editable frontend-editable-enum");
         $value = $field->forTemplate();
     }
     return $value;
 }
예제 #9
0
 protected function construct($args)
 {
     self::$enumValues = array_change_key_case(self::$enumValues, CASE_LOWER);
     if (!isset(self::$enumValues['_default_'])) {
         self::$enumValues = array('_default_' => FALSE) + self::$enumValues;
     }
     // value argument
     if (count($args) == 1) {
         $this->value = self::Validate($args[0]);
     }
 }
예제 #10
0
파일: Update.php 프로젝트: rakorium/okapi
 /**
  * @param Node|array $data
  * @return static
  */
 public function set($data)
 {
     if (!$this->fullNode($data)) {
         $items = [];
         foreach ($data as $n => $i) {
             if ($this->fullNode($i)) {
                 $items[] = Operator::bin(Identifier::node($n), '=', $i);
             } else {
                 $items[] = Operator::bin(Identifier::node($n), '=', Value::node($i));
             }
         }
         $data = Enum::expr($items);
     }
     $this->data = $data;
     return $this;
 }
예제 #11
0
 /**
  * Handles enums
  *
  * @param   lang.XPClass class
  */
 protected static function printEnum(XPClass $enum)
 {
     Console::write(implode(' ', Modifiers::namesOf($enum->getModifiers())));
     Console::write(' enum ', self::displayNameOf($enum));
     // Parent class, if not lang.Enum
     if (!XPClass::forName('lang.Enum')->equals($parent = $enum->getParentClass())) {
         Console::write(' extends ', self::displayNameOf($parent));
     }
     // Interfaces
     if ($interfaces = $enum->getInterfaces()) {
         Console::write(' implements ');
         $s = sizeof($interfaces) - 1;
         foreach ($interfaces as $i => $iface) {
             Console::write(self::displayNameOf($iface));
             $i < $s && Console::write(', ');
         }
     }
     // Constants
     Console::writeLine(' {');
     $i = 0;
     foreach ($enum->getConstants() as $name => $value) {
         Console::writeLine('  const ', $name, ' = ', xp::stringOf($value));
         $i++;
     }
     // Members
     $i && Console::writeLine();
     $i = 0;
     foreach (Enum::valuesOf($enum) as $member) {
         Console::write('  ', $member->ordinal(), ': ', $member->name());
         $class = $member->getClass();
         if ($class->isSubclassOf($enum)) {
             Console::writeLine(' {');
             foreach ($class->getDeclaredMethods() as $method) {
                 Console::writeLine('    ', $method);
                 $i++;
             }
             Console::writeLine('  }');
         } else {
             Console::writeLine();
         }
         $i++;
     }
     // Methods
     $i && Console::writeLine();
     self::printMethods($enum->getMethods());
     Console::writeLine('}');
 }
예제 #12
0
 function __construct($name, $enum = NULL, $default = NULL)
 {
     // MultiEnum needs to take care of its own defaults
     parent::__construct($name, $enum, null);
     // Validate and assign the default
     $this->default = null;
     if ($default) {
         $defaults = preg_split('/ *, */', trim($default));
         foreach ($defaults as $thisDefault) {
             if (!in_array($thisDefault, $this->enum)) {
                 user_error("Enum::__construct() The default value '{$thisDefault}' does not match " . "any item in the enumeration", E_USER_ERROR);
                 return;
             }
         }
         $this->default = implode(',', $defaults);
     }
 }
 public function GetRegistrationListResults($courseId, $learnerId, $resultsFormat)
 {
     $enum = new Enum();
     $request = new ServiceRequest($this->_configuration);
     $params = array();
     if (isset($courseId)) {
         $params['courseid'] = $courseId;
     }
     if (isset($learnerId)) {
         $params['learnerid'] = $learnerId;
     }
     if (isset($resultsFormat)) {
         $params['resultsformat'] = $enum->getRegistrationResultsFormat($resultsFormat);
     }
     $request->setMethodParams($params);
     $response = $request->CallService("rustici.registration.getRegistrationListResults");
     return $response;
 }
예제 #14
0
파일: FormType.php 프로젝트: keradus/ker
 public function __toString()
 {
     return parent::__toString();
 }
예제 #15
0
 public function staticPrimitiveMemberNotInEnumValuesOf()
 {
     Profiling::$fixture = array($this, $this->name);
     $this->assertEquals(array(Profiling::$INSTANCE, Profiling::$EXTENSION), Enum::valuesOf(XPClass::forName('net.xp_framework.unittest.core.Profiling')));
     Profiling::$fixture = NULL;
 }
예제 #16
0
 /**
  * Return a field type
  *
  * @return  unittest.web.Fields
  */
 public static function forTag($type)
 {
     return parent::valueOf(XPClass::forName('unittest.web.Fields'), strtoupper($type));
 }
예제 #17
0
 public function getDefault()
 {
     // Check for assigned default
     $default = parent::getDefault();
     if ($default) {
         return $default;
     }
     // Fallback to first option
     $enum = $this->getEnum();
     return reset($enum);
 }
예제 #18
0
 /**
  * @param mixed $id
  * @param string $name
  */
 protected function __construct($id, $name)
 {
     $this->name = $name;
     parent::__construct($id);
 }
예제 #19
0
파일: EnumTest.php 프로젝트: reisraff/input
 public function testErrorMessageIsCustomizable()
 {
     $constraint = new Enum(['foo', 'bar'], 'CUSTOM!');
     $this->assertSame('[field] CUSTOM!', $constraint->getErrorMessage('field'));
 }
예제 #20
0
 /**
  * Retrieve serialized representation of a variable
  *
  * @param   remote.protocol.SerializedData serialized
  * @param   array context default array()
  * @return  var
  * @throws  lang.ClassNotFoundException if a class cannot be found
  * @throws  lang.FormatException if an error is encountered in the format 
  */
 public function valueOf($serialized, $context = array())
 {
     static $types = NULL;
     if (!$types) {
         $types = array('N' => 'void', 'b' => 'boolean', 'i' => 'integer', 'd' => 'double', 's' => 'string', 'B' => new ClassReference('lang.types.Byte'), 'S' => new ClassReference('lang.types.Short'), 'f' => new ClassReference('lang.types.Float'), 'l' => new ClassReference('lang.types.Long'), 'a' => 'array', 'A' => new ClassReference('lang.types.ArrayList'), 'T' => new ClassReference('util.Date'));
     }
     $token = $serialized->consumeToken();
     switch ($token) {
         case 'N':
             return NULL;
         case 'b':
             return (bool) $serialized->consumeWord();
         case 'i':
             return (int) $serialized->consumeWord();
         case 'd':
             return (double) $serialized->consumeWord();
         case 's':
             return $serialized->consumeString();
         case 'a':
             // arrays
             $a = array();
             $size = $serialized->consumeSize();
             $serialized->consume('{');
             for ($i = 0; $i < $size; $i++) {
                 $key = $this->valueOf($serialized, $context);
                 $a[$key] = $this->valueOf($serialized, $context);
             }
             $serialized->consume('}');
             return $a;
         case 'E':
             // generic exceptions
             $instance = new ExceptionReference($serialized->consumeString());
             $size = $serialized->consumeSize();
             $serialized->consume('{');
             for ($i = 0; $i < $size; $i++) {
                 $member = $this->valueOf($serialized, $context);
                 $instance->{$member} = $this->valueOf($serialized, $context);
             }
             $serialized->consume('}');
             return $instance;
         case 'O':
             // generic objects
             $name = $serialized->consumeString();
             $members = array();
             try {
                 $class = XPClass::forName(strtr($name, $this->packages[0]));
             } catch (ClassNotFoundException $e) {
                 $instance = new UnknownRemoteObject($name);
                 $size = $serialized->consumeSize();
                 $serialized->consume('{');
                 for ($i = 0; $i < $size; $i++) {
                     $member = $this->valueOf($serialized, $context);
                     $members[$member] = $this->valueOf($serialized, $context);
                 }
                 $serialized->consume('}');
                 $instance->__members = $members;
                 return $instance;
             }
             $size = $serialized->consumeSize();
             $serialized->consume('{');
             if ($class->isEnum()) {
                 if ($size != 1 || 'name' != $this->valueOf($serialized, $context)) {
                     throw new FormatException(sprintf('Local class %s is an enum but remote class is not serialized as one (%s)', $name, $serialized->toString()));
                 }
                 $instance = Enum::valueOf($class, $this->valueOf($serialized, $context));
             } else {
                 $instance = $class->newInstance();
                 for ($i = 0; $i < $size; $i++) {
                     $member = $this->valueOf($serialized, $context);
                     $instance->{$member} = $this->valueOf($serialized, $context);
                 }
             }
             $serialized->consume('}');
             return $instance;
         case 'c':
             // builtin classes
             $type = $serialized->consumeWord();
             if (!isset($types[$type])) {
                 throw new FormatException('Unknown type token "' . $type . '"');
             }
             return $types[$type];
         case 'C':
             // generic classes
             return new ClassReference(strtr($serialized->consumeString(), $this->packages[0]));
         default:
             // default, check if we have a mapping
             if (!($mapping = $this->mapping($token, $m = NULL))) {
                 throw new FormatException('Cannot deserialize unknown type "' . $token . '" (' . $serialized->toString() . ')');
             }
             return $mapping->valueOf($this, $serialized, $context);
     }
 }
예제 #21
0
 /**
  * Constructor
  *
  * @param  int ordinal
  * @param  string name
  * @param  webservices.rest.RestSerializer serializer
  * @param  webservices.rest.RestDeserializer deserializer
  */
 public function __construct($ordinal, $name, $serializer, $deserializer)
 {
     parent::__construct($ordinal, $name);
     $this->serializer = $serializer;
     $this->deserializer = $deserializer;
 }
예제 #22
0
    public function testEnumProperty()
    {
        $enums = array('Yes','No');
        $valid = 'Yes';
        $invalid = 'Bob';

        $property = new Enum('AProperty', $enums, $valid);

        $this->assertEquals($enums, $property->getChoices());

        $property->setValue($valid);
        $this->assertEquals($valid, $property->getValue());

        $property->setValue($invalid);
        $this->assertNotEquals($invalid, $property->getValue());
    }
<?php

namespace PhoenixSNS\Objects;

\Enum::Create("PhoenixSNS\\Objects\\ConditionalStatementCombination", "Conjunction", "Disjunction");
\Enum::Create("PhoenixSNS\\Objects\\ConditionalStatementComparison", "Equals", "Contains", "StartsWith", "EndsWith");
class ConditionalStatementGroup
{
    public $Combination;
    public $Statements;
    public function __construct($combination = null, $statements = null)
    {
        if ($combination == null) {
            $combination = ConditionalStatementCombination::Conjunction;
        }
        if ($statements == null) {
            $statements = array();
        }
        $this->Combination = $combination;
        $this->Statements = $statements;
    }
    public function Evaluate($callbackParams)
    {
        $retval = false;
        foreach ($this->Statements as $stmt) {
            $value = $stmt->Evaluate($callbackParams);
            switch ($this->Combination) {
                case ConditionalStatementCombination::Conjunction:
                    $retval &= $value;
                    break;
                case ConditionalStatementCombination::Disjunction:
예제 #24
0
<?php

namespace PhoenixSNS\Modules\World\Objects;

\Enum::Create("PhoenixSNS\\Modules\\World\\Objects\\PlaceHotspotTargetType", "URL", "Script", "Place", "Unknown");
class PlaceHotspot
{
    public $ID;
    public $Title;
    public $Left;
    public $Top;
    public $Width;
    public $Height;
    // Target can be a script, a URL, or a Place ID depending on TargetType.
    public $TargetPlace;
    public $TargetScript;
    public $TargetURL;
    public $TargetType;
    public static function GetByAssoc($values)
    {
        $item = new PlaceHotspot();
        $item->ID = $values["hotspot_ID"];
        $item->Title = $values["hotspot_Title"];
        $item->Left = $values["hotspot_Left"];
        $item->Top = $values["hotspot_Top"];
        $item->Width = $values["hotspot_Width"];
        $item->Height = $values["hotspot_Height"];
        $item->TargetPlace = Place::GetByID($values["hotspot_TargetPlaceID"]);
        $item->TargetScript = $values["hotspot_TargetScript"];
        $item->TargetURL = $values["hotspot_TargetURL"];
        switch ($values["hotspot_TargetTypeID"]) {
예제 #25
0
 /**
  * Returns HTTP code understood by http standard instead of a const
  * @param $code
  * @return string
  */
 public static function Text($code)
 {
     return trim(ucwords(str_replace('_', ' ', strtolower(parent::Text($code)))));
 }
예제 #26
0
 public function testIsGettingErrorMessage()
 {
     $constraint = new Enum(['foo', 'bar']);
     $this->assertFalse($constraint->validate('test'), 'The "test" value is not part of the Enum');
     $this->assertEquals('Invalid option for enum. Allowed options are: foo, bar', $constraint->getErrorMessage());
 }
 public function GetRegistrationResultUrl($registrationId, $resultsFormat, $dataFormat)
 {
     $enum = new Enum();
     $request = new ServiceRequest($this->_configuration);
     $params = array('regid' => $registrationId, 'resultsformat' => $enum->getRegistrationResultsFormat($resultsFormat), 'dataformat' => $enum->getDataFormat($dataFormat));
     $request->setMethodParams($params);
     return $request->ConstructUrl("rustici.registration.getRegistrationResult");
 }
 public function GetMetadata($courseId, $versionId, $scope, $format)
 {
     $enum = new Enum();
     $request = new ServiceRequest($this->_configuration);
     $params = array('courseid' => $courseId);
     if (isset($versionId) && $versionId != 0) {
         $params['versionid'] = $versionId;
     }
     $params['scope'] = $enum->getMetadataScope($scope);
     $params['mdformat'] = $enum->getDataFormat($format);
     $request->setMethodParams($params);
     $response = $request->CallService("rustici.course.getMetadata");
     // Return the subset of the xml starting with the top <object>
     return $response;
 }
예제 #29
0
 /**
  * checks a enum element
  *
  * @param mixed $value
  * @param mixed $schema
  * @param mixed $path
  * @param mixed $i
  */
 protected function checkEnum($value, $schema = null, $path = null, $i = null)
 {
     $validator = new Enum($this->checkMode);
     $validator->check($value, $schema, $path, $i);
     $this->addErrors($validator->getErrors());
 }
예제 #30
0
    public function testEnumParsing()
    {
        $enum = new Enum('testField', "\n\t\t\tItem1,\n\t\t\tItem2,\n\t\t\tItem 3,\n\t\t\tItem-4,\n\t\t\titem 5\n\t\t\tstill 5,\n\t\t\ttrailing comma,\n\t\t");
        $this->assertEquals(ArrayLib::valuekey(array('Item1', 'Item2', 'Item 3', 'Item-4', 'item 5
			still 5', 'trailing comma')), $enum->enumValues());
    }