public function execute(&$value, &$error)
 {
     $class_name = $this->getParameter('class_name');
     $field_const_name = $this->getParameter('field_const_name');
     $form_field_name = $this->getParameter('form_field_name');
     $form_field_value = $this->getContext()->getRequest()->getParameter($form_field_name);
     $form_id_name = $this->getParameter('form_id_name');
     if ($form_id_name) {
         $form_id_value = $this->getContext()->getRequest()->getParameter($form_id_name);
     }
     $class = new ReflectionClass($class_name);
     if ($class->hasConstant($field_const_name)) {
         $criteria = new Criteria();
         $criteria->add($class->getConstant($field_const_name), $form_field_value);
         if (isset($form_id_value) && $form_id_value && $class->hasConstant('ID')) {
             $criteria->add($class->getConstant('ID'), $form_id_value, Criteria::NOT_EQUAL);
         }
         if ($class->hasMethod('doSelectOne')) {
             $ref_method = $class->getMethod('doSelectOne');
             $object = $ref_method->invoke(null, $criteria);
             if (!$object) {
                 return true;
             }
         }
         sfContext::getInstance()->getLogger()->info('Buraya geldi');
     }
     $error = $this->getParameter('unique_error');
     return false;
 }
 /**
  * @param  \SplFileInfo[]   $templates
  * @param $resourcesPath
  * @param $moduleCode
  * @throws \Exception
  * @throws \SmartyException
  */
 protected function processModule($templates, $resourcesPath, $modulePath, $moduleCode)
 {
     foreach ($templates as $template) {
         $fileName = str_replace("__MODULE__", $moduleCode, $template->getFilename());
         $fileName = str_replace("FIX", "", $fileName);
         $relativePath = str_replace($resourcesPath, "", $template->getPath() . DS);
         $completeFilePath = $modulePath . $relativePath . DS . $fileName;
         $isFix = false !== strpos($template->getFilename(), "FIX");
         // Expect special rule for Module\Module
         $isModuleClass = $modulePath . $relativePath . DS . $moduleCode . ".php" === $completeFilePath;
         if ($isFix && !file_exists($completeFilePath) || !$isFix) {
             if ($isModuleClass && is_file($completeFilePath)) {
                 $caught = false;
                 try {
                     $reflection = new \ReflectionClass("{$moduleCode}\\{$moduleCode}");
                 } catch (\ReflectionException $e) {
                     $caught = true;
                     // The class is not valid
                 }
                 if (!$caught && $reflection->hasConstant("MESSAGE_DOMAIN")) {
                     continue;
                     // If the class already have the constant, don't override it
                 }
             }
             $fetchedTemplate = $this->parser->fetch($template->getRealPath());
             $this->writeFile($completeFilePath, $fetchedTemplate, true, true);
         }
     }
 }
Beispiel #3
0
 protected static function getClassAnnotation(ReflectionClass $reflector, $name)
 {
     if ($reflector->hasConstant($name)) {
         return $reflector->getConstant($name);
     }
     return null;
 }
Beispiel #4
0
 /**
  * Constructor. By passing needed values in constructor, you can quickly contruct instances of FormField in one line of code.
  *
  * @param string $name Field name
  * @param string $field_type Field type. Must be a member of FORM_FIELD_TYPE
  * @param string $title Field title as it will appear on the form
  * @param bool $isrequired Either field must be filled by the user.
  * @param array $options Flat key=>value array to draw SELECT HTML control values. Only applicable if FormFieldType is FORM_FIELD_TYPE::SELECT
  * @param string $default_value Default value that will be in the field when form is drawn.
  * @param string $value Filed Value. The same as default_value
  * @param string $hint  Inline help that will appear as yellow hint after the field.
  */
 public function __construct($name, $field_type, $title, $isrequired = false, $options = array(), $default_value = null, $value = null, $hint = null, $allow_multiple_choice = false)
 {
     // Defalts if we blindly pass nullz
     if ($options == null) {
         $options = array();
     }
     if ($isrequired == null) {
         $isrequired = false;
     }
     // Validation
     // type
     $Reflect = new ReflectionClass("FORM_FIELD_TYPE");
     if (!$Reflect->hasConstant(strtoupper($field_type))) {
         throw new Exception("field_type must be of type FORM_FIELD_TYPE");
     }
     $this->Name = $name;
     $this->FieldType = $field_type;
     $this->Title = $title;
     $this->DefaultValue = $default_value;
     if ($allow_multiple_choice) {
         $this->Value = explode(",", $value);
     } else {
         $this->Value = $value;
     }
     $this->IsRequired = $isrequired;
     $this->Hint = $hint;
     $this->Options = $options;
     $this->AllowMultipleChoice = $allow_multiple_choice;
 }
 /**
  * Get variant of ENUM value
  *
  * @param string      $enumConst ENUM value
  * @param string|null $enumType  ENUM type
  *
  * @throws EnumTypeIsNotRegisteredException
  * @throws NoRegisteredEnumTypesException
  * @throws ConstantIsFoundInFewRegisteredEnumTypesException
  * @throws ConstantIsNotFoundInAnyRegisteredEnumTypeException
  *
  * @return string
  */
 public function getEnumValue($enumConst, $enumType = null)
 {
     if (!empty($this->registeredEnumTypes) && is_array($this->registeredEnumTypes)) {
         // If ENUM type was set, e.g. {{ player.position|readable('BasketballPositionType') }}
         if (!empty($enumType)) {
             if (!isset($this->registeredEnumTypes[$enumType])) {
                 throw new EnumTypeIsNotRegisteredException(sprintf('ENUM type "%s" is not registered', $enumType));
             }
             return constant($this->registeredEnumTypes[$enumType] . '::' . $enumConst);
         } else {
             // If ENUM type wasn't set, e.g. {{ player.position|readable }}
             $occurrences = [];
             // Check if value exists in registered ENUM types
             foreach ($this->registeredEnumTypes as $registeredEnumType) {
                 $refl = new \ReflectionClass($registeredEnumType);
                 if ($refl->hasConstant($enumConst)) {
                     $occurrences[] = $registeredEnumType;
                 }
             }
             // If found only one occurrence, then we know exactly which ENUM type
             if (count($occurrences) == 1) {
                 $enumClassName = array_pop($occurrences);
                 return constant($enumClassName . '::' . $enumConst);
             } elseif (count($occurrences) > 1) {
                 throw new ConstantIsFoundInFewRegisteredEnumTypesException(sprintf('Constant "%s" is found in few registered ENUM types. You should manually set the appropriate one', $enumConst));
             } else {
                 throw new ConstantIsNotFoundInAnyRegisteredEnumTypeException(sprintf('Constant "%s" wasn\'t found in any registered ENUM type', $enumConst));
             }
         }
     } else {
         throw new NoRegisteredEnumTypesException('There are no registered ENUM types');
     }
 }
 /**
  */
 public function testAddConstant()
 {
     $prop = new ReflectionConstant('test', "value");
     $this->assertFalse($this->object->hasConstant('test'));
     $this->object->addConstant($prop);
     $this->assertTrue($this->object->hasConstant('test'));
 }
Beispiel #7
0
 /**
  * Convert packable object to an array.
  * 
  * @param  PackableInterface $object
  * @return array
  */
 public static function pack(PackableInterface $object)
 {
     $reflect = new \ReflectionClass(get_class($object));
     $data = array();
     foreach ($object as $key => $value) {
         // we don't want to send null variables
         if ($value === null) {
             continue;
         }
         // run the packer over packable objects
         if ($value instanceof PackableInterface) {
             $value = self::pack($value);
         }
         // find packing strategy
         $strategy = sprintf('%s_PACKER_STRATEGY', $key);
         $strategy = $reflect->hasConstant($strategy) ? $reflect->getConstant($strategy) : self::SINGLE_KEY_STRATEGY;
         // execute
         $strategy::pack($data, $key, $value);
     }
     // default actions
     foreach ($data as $key => $value) {
         // make sure all objects have been packed
         if ($value instanceof PackableInterface) {
             $value = self::pack($value);
         }
         // compress any remaining data structures
         if (is_array($value)) {
             Compress::pack($data, $key, $value);
         }
     }
     return $data;
 }
 public function testGeneratePostActivation()
 {
     // Touch a new "insert.sql" file and copy a "create.sql" file
     /** @var \org\bovigo\vfs\vfsStreamFile $file */
     $configDir = $this->stream->getChild("Config");
     $file = vfsStream::newFile("create.sql")->at($configDir);
     $file->setContent(file_get_contents(__DIR__ . "/../" . static::TEST_MODULE_PATH . "Config" . DS . "thelia.sql"));
     vfsStream::newFile("insert.sql")->at($configDir);
     // Then run the generator
     $generator = new ModulePhpGenerator($this->getSmarty());
     $generator->doGenerate($this->event);
     // Read the class
     include $this->getStreamPath("TheliaStudioTestModule.php");
     $reflection = new \ReflectionClass("TheliaStudioTestModule\\TheliaStudioTestModule");
     $this->assertTrue($reflection->hasConstant("MESSAGE_DOMAIN"));
     $this->assertEquals("theliastudiotestmodule", $reflection->getConstant("MESSAGE_DOMAIN"));
     $this->assertTrue($reflection->hasMethod("postActivation"));
     // get a method closure
     $method = $reflection->getMethod("postActivation");
     $closure = $method->getClosure($reflection->newInstance());
     // Test that the table doesn't exist
     /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */
     $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'");
     $this->assertEquals(0, $stmt->count());
     // Execute the method
     $closure($this->con);
     // Now it exists
     /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */
     $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'");
     $this->assertEquals(1, $stmt->count());
 }
Beispiel #9
0
 public static function __callStatic($name, $arguments)
 {
     $reflectionClass = new \ReflectionClass(get_called_class());
     if (!$reflectionClass->hasConstant($name)) {
         throw new InvalidKey($name);
     }
     return new static($reflectionClass->getConstant($name), false);
 }
Beispiel #10
0
 /**
  * Static factory (ex. ExampleEnum::ONE())
  *
  * @param $method
  * @param $arguments
  *
  * @throws \BadMethodCallException When given constant is undefined
  *
  * @return Enum
  */
 public static function __callStatic($method, $arguments)
 {
     $class = get_called_class();
     $refl = new \ReflectionClass($class);
     if (!$refl->hasConstant($method)) {
         throw new \BadMethodCallException(sprintf('Undefined class constant "%s" in "%s"', $method, $class));
     }
     return new static($refl->getConstant($method), false);
 }
/**
 * @param string|object $class
 * @param string $prefix
 * @return array
 * @throws \Exception
 */
function getConstantWithPrefixForChoice($class, $prefix, $value)
{
    $reflection = new \ReflectionClass($class);
    $labelPrefixConstantName = 'LABELPREFIX_' . rtrim($prefix, '_');
    if (!$reflection->hasConstant($labelPrefixConstantName)) {
        throw new \Exception(sprintf('A constant with name: %s is needed as labelprefix', $labelPrefixConstantName));
    }
    $labelPrefix = $reflection->getConstant($labelPrefixConstantName);
    return $labelPrefix . $value;
}
 public function instantiate($className, array $constructorArgs)
 {
     $class = new \ReflectionClass($this->qualifyClassName($className));
     array_unshift($constructorArgs, $this->dataStore);
     $newClass = $class->newInstanceArgs($constructorArgs);
     if ($class->hasConstant("CUSTOM_DATA")) {
         $newClass->customData;
     }
     return $newClass;
 }
Beispiel #13
0
 public static function GetValue($class_name, $key)
 {
     //property_exists
     $ReflectionClassThis = new ReflectionClass($class_name);
     if ($ReflectionClassThis->hasConstant($key)) {
         return $ReflectionClassThis->getConstant($key);
     } else {
         throw new Exception(sprintf(_("Called %s::GetValue('%s') for non-existent property %s"), $class_name, $key, $key));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function on($class, ...$args)
 {
     $reflection = new \ReflectionClass($class);
     if (false === $reflection->hasConstant('NAME')) {
         throw new Exception\InvalidEventNameException($class);
     }
     if (false === $reflection->isSubclassOf(EventInterface::class)) {
         throw new Exception\EventInterfaceImplementationException($class);
     }
     $this->push(['class' => $class, 'args' => $args]);
 }
Beispiel #15
0
 public static function table($name)
 {
     $name = strtoupper($name);
     $ret = self::$prefix . '_';
     $reflection = new \ReflectionClass(__CLASS__);
     if ($reflection->hasConstant($name)) {
         return strtolower($ret . $reflection->getConstant($name));
     } else {
         return strtolower($ret . $name);
     }
 }
 /**
  * @param  int        $statusCode
  * @return string
  * @throws \Exception
  */
 protected static function getStatusMessage($statusCode)
 {
     static $reflectionResponse;
     if (null === $reflectionResponse) {
         $responseClass = 'Saxulum\\HttpClient\\Response';
         $reflectionResponse = new \ReflectionClass($responseClass);
     }
     $constantName = self::getCodeConstantName($statusCode);
     if (!$reflectionResponse->hasConstant($constantName)) {
         throw new \Exception("Unknown status code {$statusCode}!");
     }
     return $reflectionResponse->getConstant($constantName);
 }
		/**
		 * Get value of property by property name
		 * FIXME: Move to parent class Struct, when php will have late static binding
		 *
		 * @param  $key
		 */
		public static function GetValue($key)
		{
			//property_exists
			$ReflectionClassThis = new ReflectionClass(__CLASS__);
			if ($ReflectionClassThis->hasConstant($key))
			{
				return $ReflectionClassThis->getConstant($key);
			}
			else 
			{
				throw new Exception(sprintf(_("Called %s::GetValue('{$key}') for non-existent property {$key}"), __CLASS__));
			}
		}
 public function instantiate($className, array $constructorArgs)
 {
     $class = new \ReflectionClass($this->qualifyClassName($className));
     array_unshift($constructorArgs, $this->dataStore);
     $newClass = $class->newInstanceArgs($constructorArgs);
     if ($class->hasConstant("CUSTOM_DATA")) {
         $newClass->customData;
     }
     if ($newClass instanceof \Stormpath\Resource\SamlProvider) {
         $newClass = $this->convertSamlAttributeStatementMappingRules($newClass);
     }
     return $newClass;
 }
Beispiel #19
0
 /**
  * @test
  */
 public function testResourceConstants()
 {
     $reflection = new \ReflectionClass('Scalr\\Acl\\Acl');
     $this->assertTrue($reflection->hasConstant('RESOURCE_FARMS'));
     $this->assertEquals(0x100, Acl::RESOURCE_FARMS);
     //All IDs of the resources must be unique
     $uniq = array();
     foreach ($reflection->getConstants() as $name => $value) {
         if (strpos($name, 'RESOURCE_') === 0) {
             $this->assertFalse(isset($uniq[$value]), sprintf('Not unique ID(0x%x) of the ACL resource has been found', $value));
             $uniq[$value] = $name;
         }
     }
     unset($uniq);
 }
Beispiel #20
0
 /**
  * Create a new enum
  * @param Object $value The enum value
  */
 public function __construct($value = null)
 {
     $enum = new \ReflectionClass($this);
     if ($value == null) {
         if (!$enum->hasConstant(self::DEFAULT_NAME)) {
             throw new \InvalidArgumentException("Cannot create enum as no value has been passed and no default is specified");
         } else {
             $value = $enum->getConstant(self::DEFAULT_NAME);
         }
     }
     foreach ($enum->getConstants() as $name => $enumValue) {
         if ($enumValue == $value) {
             $this->value = $value;
             return;
         }
     }
     throw new \InvalidArgumentException("Unknown enum value " . $value);
 }
Beispiel #21
0
 /**
  * Gets the table name from the 'TABLE' constant of the active record
  * class if defined, otherwise use the class name as table name.
  * @param TActiveRecord active record instance
  * @return string table name for the given record class.
  */
 protected function getRecordTableName(TActiveRecord $record)
 {
     $class = new ReflectionClass($record);
     if ($class->hasConstant(self::TABLE_CONST)) {
         $value = $class->getConstant(self::TABLE_CONST);
         if (empty($value)) {
             throw new TActiveRecordException('ar_invalid_tablename_property', get_class($record), self::TABLE_CONST);
         }
         return $value;
     } elseif ($class->hasMethod(self::TABLE_METHOD)) {
         $value = $record->{self::TABLE_METHOD}();
         if (empty($value)) {
             throw new TActiveRecordException('ar_invalid_tablename_method', get_class($record), self::TABLE_METHOD);
         }
         return $value;
     } else {
         return strtolower(get_class($record));
     }
 }
Beispiel #22
0
 public function genericBlend($opacity = 1, $fill = 1, $mode = 'COPY', $options = array())
 {
     $class = new \ReflectionClass("\\Imagick");
     if ($class->hasConstant('COMPOSITE_' . strtoupper($mode))) {
         $baseImg = $this->base->getImage();
         $overlayImg = $this->top->getImage();
         $overlayImg->setImageOpacity($opacity);
         if (!isset($options['botx'])) {
             $options['botx'] = 0;
         }
         if (!isset($options['boty'])) {
             $options['boty'] = 0;
         }
         $baseImg->compositeImage($overlayImg, constant('\\Imagick::COMPOSITE_' . strtoupper($mode)), $options['botx'], $options['boty']);
     } else {
         throw new \InvalidArgumentException('Blending mode ' . $mode . ' not available using Imagick');
         return null;
     }
     return $baseImg;
 }
Beispiel #23
0
 public static function getType($fid)
 {
     $parts = explode(':', $fid);
     if (strlen($fid) < 32 || !Numbers::between(count($parts), 4, 5)) {
         return null;
     }
     if ($parts[0] != 'FID') {
         return null;
     }
     $type = $subType = $parts[1];
     if (count($parts) === 5) {
         $subType = $parts[2];
     }
     $reflection = new \ReflectionClass('\\Fortifi\\FortifiApi\\Foundation\\Fids\\FidTypes');
     $const = $type . '_' . $subType;
     if ($reflection->hasConstant($const)) {
         return $reflection->getConstant($const);
     }
     return null;
 }
Beispiel #24
0
 public function install()
 {
     $this->_hooks = array('displayCarrierList', 'actionValidateOrder', 'displayAdminOrder', 'displayBackOfficeHeader', 'displayFooter');
     $installRes = parent::install();
     if (!$installRes) {
         return false;
     }
     $wys = Paczkomat::paczkomatUżytkownika("*****@*****.**");
     $wysPaczk = Paczkomat::pobierzDanePaczkomatu($wys['glowny']);
     $refl = new ReflectionClass($this);
     foreach ($this->_konf as $name => $value) {
         $defName = str_replace("KONFIG_", "DOM_", $name);
         if ($refl->hasConstant($defName)) {
             Configuration::updateValue(self::KONFIG_PREFIX . $value, $refl->getConstant($defName));
         }
     }
     foreach (array(self::KONFIG_PACZKOMAT_WYSYLKOWY => base64_encode(serialize($wysPaczk['paczkomat']))) as $key => $value) {
         Configuration::updateValue(self::KONFIG_PREFIX . $key, $value);
     }
     return $installRes;
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(array $values)
 {
     $string = $values['value'];
     // Handle classes.
     if (strpos($string, '::') !== FALSE) {
         list($class, $constant) = explode('::', $string);
         try {
             $reflection = new \ReflectionClass($class);
             if ($reflection->hasConstant($constant)) {
                 $this->value = $reflection->getConstant($constant);
                 return;
             }
         } catch (\ReflectionException $e) {
         }
     }
     // Handle procedural constants.
     if (!$this->value && defined($string)) {
         $this->value = constant($string);
         return;
     }
     throw AnnotationException::semanticalErrorConstants($this->value);
 }
 public function testValidate()
 {
     $doctrine = new ReflectionClass('Doctrine');
     if ($doctrine->hasConstant('VALIDATE_USER')) {
         Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_USER);
     } else {
         //I only want my overridden Record->validate()-methods for validation
         Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL & ~Doctrine_Core::VALIDATE_LENGTHS & ~Doctrine_Core::VALIDATE_CONSTRAINTS & ~Doctrine_Core::VALIDATE_TYPES);
     }
     $user = Doctrine_Core::getTable('Ticket_1652_User')->findOneById(1);
     $user->name = "test";
     if ($user->isValid()) {
         try {
             $user->save();
         } catch (Doctrine_Validator_Exception $dve) {
             // ignore
         }
     }
     $user = Doctrine_Core::getTable('Ticket_1652_User')->findOneById(1);
     $this->assertNotEqual($user->name, 'test');
     //reset validation to default for further testcases
     Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_NONE);
 }
 protected function assertConstants(\ReflectionClass $reflection, array $constants)
 {
     foreach ($constants as $key => $value) {
         $this->assertTrue($reflection->hasConstant($key));
         $this->assertEquals($value, $reflection->getConstant($key));
     }
     $reflectionConstants = $reflection->getConstants();
     $this->assertCount(count($constants), $reflectionConstants);
 }
Beispiel #28
0
 /**
  *Checks if a class has a constant named $constant
  *@param String $name class name
  *@param String $constant constant to be checked 
  *@return boolean TRUE if the class has a constant named $constant
  *@return boolean FALSE if the class doesn't has a constant named $constant
  *@see self::parameterValidation for other return values
  */
 public static function hasConstant($name, $constant)
 {
     $stdValidation = self::parameterValidation($name, $constant);
     $rc = new \ReflectionClass($name);
     return $rc->hasConstant($constant);
 }
Beispiel #29
0
 /**
  * Get reflection for something
  *
  * @param string $thing The thing to get reflection for
  *
  * @return mixed ReflectionFoo instance
  */
 protected function getReflection($thing)
 {
     switch (true) {
         case is_object($thing):
             return new ReflectionObject($thing);
         case class_exists($thing, false):
             return new ReflectionClass($thing);
         case function_exists($thing):
             return new ReflectionFunction($thing);
         case strstr($thing, '::'):
             list($class, $what) = explode('::', $thing);
             $rc = new ReflectionClass($class);
             switch (true) {
                 case substr($what, -2) == '()':
                     $what = substr($what, 0, strlen($what) - 2);
                 case $rc->hasMethod($what):
                     return $rc->getMethod($what);
                 case substr($what, 0, 1) == '$':
                     $what = substr($what, 1);
                 case $rc->hasProperty($what):
                     return $rc->getProperty($what);
                 case $rc->hasConstant($what):
                     return $rc->getConstant($what);
             }
         case is_string($thing):
             return var_export($thing) . "\n";
     }
 }
Beispiel #30
0
 /**
  * Get ctype name
  * extract constant CTYPE to ctype_id
  */
 function _get_ctype()
 {
     if (!isset($this->_ctype)) {
         if (loader::is_php53()) {
             $this->_ctype = defined('static::CTYPE') ? static::CTYPE : false;
         } else {
             // php 5.2, no lsb
             $class = get_class($this);
             $reflector = new ReflectionClass($class);
             $this->_ctype = $reflector->hasConstant('CTYPE') ? $reflector->getConstant('CTYPE') : false;
         }
     }
     return $this->_ctype;
 }