Beispiel #1
0
 /**
  * Creates a new selectbox in an elementcontainer, with room for an error/notice block and a label.
  * Clientside JS validation will be applied and can be chained using bitmasking.
  * @param string The id and the name of the formfield
  * @param \System\Collection\Map the options to be displayed
  * @param string The selectedvalue of the selectbox
  * @param string The error/notice to display in the elementcontainer
  * @param string The label to show before the element
  * @param int A bitwise combination of \Module\HTMLForm\FormBuilder\ValidationOptions for JS clientside validation
  * @return \Module\HTMLForm\Element\Label A Label with nested elements to be outputted to a form
  */
 public static final function createSelectBox($id, \System\Collection\Map $options, $value = '', $notice = '', $label = '', $validationMethod = \Module\HTMLForm\FormBuilder\ValidationOptions::VALIDATE_NONE)
 {
     $vectorOptions = new \System\Collection\Vector();
     foreach ($options as $index => $option) {
         $vOption = new \Module\HTMLForm\Element\Option($option, $index);
         $vectorOptions->add($vOption);
     }
     $selectBox = new \Module\HTMLForm\Element\Select($id);
     $selectBox->setId($id);
     $selectBox->addOptions($vectorOptions);
     $selectBox->setSelectedValue($value);
     if (!empty($notice)) {
         $selectBox->setClass('notice');
     }
     self::applyValidationScript($selectBox, $validationMethod, '');
     $container = new \Module\HTMLForm\Element\ElementContainer($selectBox, $notice);
     $label = new \Module\HTMLForm\Element\Label($container, $label);
     return $label;
 }
 /**
  * Retrieves the field from the object and returns the desired field, if exists.
  * @param string The name of the called method
  * @param string The name of the field to retrieve
  * @param array The arguments given to the function call
  * @return mixed The requested field
  */
 private final function retrieveField($name, $fieldName, array $arguments)
 {
     $fieldMap = self::validateMap(self::$fieldMap);
     $virtualMap = self::validateMap(self::$virtualMap);
     $dataMap = $this->validateInstanceMap($this->data);
     //check for the existance of a property that adheres to the given fieldName
     if ($fieldMap->keyExists($fieldName)) {
         $fieldData = $fieldMap->{$fieldName};
         //first check if we are allowed to access this field
         if (isset($fieldData['noget']) && mb_strtolower((string) $fieldData['noget']) == 'true') {
             throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not exist in this context.');
         }
         //we retrieve the data from the object
         $value = $dataMap->{$fieldName};
         //if the internal data equals the optional nullify property, we pretend the value to be an empty string, thus uninitialized.
         if (isset($fieldData['nullify']) && (string) $fieldData['nullify'] == $value) {
             $value = '';
         }
         //we interpret our data as the given type
         switch (mb_strtolower((string) $fieldData['type'])) {
             case \System\Type::TYPE_TIMESTAMP:
                 return \System\Calendar\Time::fromMySQLTimestamp($value);
             case \System\Type::TYPE_BOOL:
             case \System\Type::TYPE_BOOLEAN:
                 return (bool) $value;
             case \System\Type::TYPE_SERIALIZED:
                 //this type is deprecated and we try to convert current existing fields to array type
             //this type is deprecated and we try to convert current existing fields to array type
             case \System\Type::TYPE_ARRAY:
                 return self::decodeArray($value);
             case \System\Type::TYPE_INT:
             case \System\Type::TYPE_INTEGER:
                 return (int) $value;
             default:
                 return $value;
         }
     } elseif ($virtualMap->keyExists($fieldName)) {
         //we can use different databases, but default to one used by this instance
         $db = $this->getDatabase();
         //first check the parameter count
         if (count($arguments) > 1 || count($arguments) == 1 && !$arguments[0] instanceof \System\Db\Database) {
             throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not accept the given parameters. Expected: ' . $this->getClassName() . '->' . $name . '(\\System\\Db\\Database) or ' . $this->getClassName() . '->' . $name . '().');
         }
         //check if there is an optional database given to use for the virtual function
         if (count($arguments) == 1 && $arguments[0] instanceof \System\Db\Database) {
             $db = $arguments[0];
         }
         $virtualMethod = $virtualMap->{$fieldName};
         $parameters = new \System\Collection\Vector();
         //virtuals only have <value> nodes as children
         foreach ($virtualMethod->children() as $parameterElement) {
             //during the creation of the object we included these fields, so we dont need to check their existence in the field list; we know they exist.
             $queryField = 'virtual_' . (string) $parameterElement;
             $parameters->add($dataMap[$queryField]);
         }
         //do we want the result as a set?
         $alwaysUseContainer = isset($virtualMethod['alwaysusecontainer']) && (mb_strtolower((string) $virtualMethod['alwaysusecontainer']) == 'true' || mb_strtolower((string) $virtualMethod['alwaysusecontainer']) == 'yes');
         return \System\Db\Object::load($db, (string) $virtualMethod['type'], (string) $virtualMethod['condition'], $parameters, $alwaysUseContainer);
     } else {
         throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not exist in this context.');
     }
 }
Beispiel #3
0
 /**
  * Returns a \System\Collection\Vector containing all the information about all the currently loaded
  * modules. This information is using a default format and displays any information from the iModule interface
  * and outputs additional information retrieval function.
  * @return \System\Collection\Vector A Vector containing a listing of all loaded modules
  */
 public static final function getAllModules()
 {
     $register = self::getRegistryModuleEntry();
     $map = new \System\Collection\Vector();
     foreach ($register->modules as $moduleName => $module) {
         $mod = new \System\Collection\Map();
         $mod->name = $module->getModuleName();
         $mod->manifest = $moduleName;
         $mod->major = $module->getMajor();
         $mod->minor = $module->getMinor();
         $mod->revision = \System\Version::transformRevStringToInt($module->getSourceRevision());
         $additional = $module->getModuleInformation();
         $additional->requiredConfigDirectives = implode(', ', $module->getRequiredConfigDirectives()->getArrayCopy());
         $mod->additional = $additional;
         $map->add($mod);
     }
     return $map;
 }
Beispiel #4
0
 /**
  * The main processing loop. This function is not supposed to exit.
  */
 public final function run()
 {
     $time = time();
     while (true) {
         //we make sure the mastersocket is in the sockets list
         if (empty($this->sockets)) {
             $this->sockets[self::MASTERSOCKET_KEY] = $this->masterSocket;
         }
         $read = $this->sockets;
         //these sockets are wachted for reading
         $write = array();
         //these sockets are watched for writing
         $except = array();
         //these sockets are watched for exceptions
         //we check for the changes in the socket list, and this modifies the arrays
         if (@socket_select($read, $write, $except, 0) === false) {
             $this->handleSocketError();
         }
         //we iterate over all the read sockets to process them
         foreach ($read as $socket) {
             //when the socket is the master, we check if we can accept a new connection
             if ($socket == $this->masterSocket) {
                 if ($client = @socket_accept($socket)) {
                     $this->connect($client);
                 } else {
                     $this->handleSocketError(false);
                 }
             } else {
                 //there is a client socket with info to read
                 $buffer = null;
                 $numberOfBytes = @socket_recv($socket, $buffer, $this->maximumBufferSize, 0);
                 if ($numberOfBytes === false) {
                     $this->handleSocketError(false);
                     $this->disconnect($socket);
                 } elseif ($numberOfBytes == 0) {
                     $this->disconnect($socket);
                 } else {
                     $connection = $this->getConnectionBySocket($socket);
                     if (!$connection->getHandshake()) {
                         $tmp = str_replace("\r", '', $buffer);
                         if (strpos($tmp, "\n\n") === false) {
                             //the client has not finished sending the initiation header, so we wait another cycle
                             continue;
                         }
                         $this->doHandshake($connection, $buffer);
                     } else {
                         //we split the packet into frame and send it to deframe
                         $this->splitPacket($numberOfBytes, $buffer, $connection);
                     }
                 }
             }
         }
         //prepare a cycle
         $connections = new \System\Collection\Vector();
         foreach ($this->connections as $connection) {
             if ($connection != $this->masterSocket && !$connection->isHandlingPartialPacket() && !$connection->isSendingContinuous() && !$connection->isSentClose()) {
                 $connections->add($connection);
             }
         }
         $onCycleEvent = new \System\Web\Websocket\Event\OnCycleEvent();
         $onCycleEvent->setServer($this);
         $onCycleEvent->setConnections($connections);
         $onCycleEvent->raise();
         if ($time != time()) {
             $on1SCycleEvent = new \System\Web\Websocket\Event\On1SCycleEvent();
             $on1SCycleEvent->setServer($this);
             $on1SCycleEvent->setConnections($connections);
             $on1SCycleEvent->raise();
             $time = time();
         }
     }
 }
Beispiel #5
0
 /**
  * Executes a query on the database system and tries to return it as a vector
  * The result will be converted to a \System\Collection\Vector.
  * The first field will be added as the value.
  * If the number of fields retrieved from the query does not equal 1 an exception will be thrown.
  * @param Query The query to be executed
  * @return \System\Collection\Vector A Vector
  */
 public final function queryScalar(\System\Db\Query $query)
 {
     $results = $this->query($query);
     $vec = new \System\Collection\Vector();
     if (count($results->getFields()) == 1) {
         $fields = $results->getFields();
         foreach ($results as $result) {
             $value = $fields[0]->name;
             $vec->add($result->{$value});
         }
     } else {
         throw new \System\Error\Exception\DatabaseQueryException('Given query should have 1 field but has: ' . count($results->getFields()));
     }
     return $vec;
 }