Example #1
0
 public static function create($street, $number, $county, $country, $city, $state, $zipCode)
 {
     $instance = new self();
     $instance->setStreet($street);
     $instance->setNumber($number);
     $instance->setCounty($county);
     $instance->setCountry($country);
     $instance->setCity($city);
     $instance->setState($state);
     $instance->setZipCode($zipCode);
     return $instance;
 }
 /**
  * Creates a new conditional proxy state.
  *
  * This should be called from the object implementing the conditional proxy 
  * <code>_if()</code> method.
  *
  * @param  ConditionalProxy  $object     A conditional proxy object.
  * @param  bool              $condition  The _if() condition.
  *
  * @return  ConditionalProxy  A conditional proxy object or handler.
  */
 public static function create($object, $condition)
 {
     if (!self::$store instanceof \SplObjectStorage) {
         self::$store = new \SplObjectStorage();
     }
     self::verifyObjectType($object);
     if (self::$store->contains($object)) {
         throw new Exception('_if() cannot be nested.');
     }
     $handler = new self($object, $condition);
     $handler->setState(self::STATE_IF);
     self::$store->attach($object, $handler);
     return $condition ? $object : $handler;
 }
 /**
  * Read from a file
  *
  * @deprecated  Use img.io.MetaDataReader instead
  * @param   io.File file
  * @param   var default default void what should be returned in case no data is found
  * @return  img.util.IptcData
  * @throws  lang.FormatException in case malformed meta data is encountered
  * @throws  lang.ElementNotFoundException in case no meta data is available
  * @throws  img.ImagingException in case reading meta data fails
  */
 public static function fromFile(File $file)
 {
     if (FALSE === getimagesize($file->getURI(), $info)) {
         $e = new ImagingException('Cannot read image information from ' . $file->getURI());
         xp::gc(__FILE__);
         throw $e;
     }
     if (!isset($info['APP13'])) {
         if (func_num_args() > 1) {
             return func_get_arg(1);
         }
         throw new ElementNotFoundException('Cannot get IPTC information from ' . $file->getURI() . ' (no APP13 marker)');
     }
     if (!($iptc = iptcparse($info['APP13']))) {
         throw new FormatException('Cannot parse IPTC information from ' . $file->getURI());
     }
     // Parse creation date
     if (3 == sscanf(@$iptc['2#055'][0], '%4d%2d%d', $year, $month, $day)) {
         $created = Date::create($year, $month, $day, 0, 0, 0);
     } else {
         $created = NULL;
     }
     with($i = new self());
     $i->setTitle(@$iptc['2#005'][0]);
     $i->setUrgency(@$iptc['2#010'][0]);
     $i->setCategory(@$iptc['2#015'][0]);
     $i->setSupplementalCategories(@$iptc['2#020']);
     $i->setKeywords(@$iptc['2#025']);
     $i->setSpecialInstructions(@$iptc['2#040'][0]);
     $i->setDateCreated($created);
     $i->setAuthor(@$iptc['2#080'][0]);
     $i->setAuthorPosition(@$iptc['2#085'][0]);
     $i->setCity(@$iptc['2#090'][0]);
     $i->setState(@$iptc['2#095'][0]);
     $i->setCountry(@$iptc['2#101'][0]);
     $i->setOriginalTransmissionReference(@$iptc['2#103'][0]);
     $i->setHeadline(@$iptc['2#105'][0]);
     $i->setCredit(@$iptc['2#110'][0]);
     $i->setSource(@$iptc['2#115'][0]);
     $i->setCopyrightNotice(@$iptc['2#116'][0]);
     $i->setCaption(@$iptc['2#120'][0]);
     $i->setWriter(@$iptc['2#122'][0]);
     return $i;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public static function fromArray(array $values)
 {
     $message = new self();
     $values = array_merge(['state' => null, 'battle_type' => null, 'server_ms' => null, 'battle_actions' => [], 'battle_start_timestamp_ms' => null, 'battle_end_timestamp_ms' => null], $values);
     $message->setState($values['state']);
     $message->setBattleType($values['battle_type']);
     $message->setServerMs($values['server_ms']);
     $message->setBattleStartTimestampMs($values['battle_start_timestamp_ms']);
     $message->setBattleEndTimestampMs($values['battle_end_timestamp_ms']);
     foreach ($values['battle_actions'] as $item) {
         $message->addBattleActions($item);
     }
     return $message;
 }
Example #5
0
 /**
  * Adds the user to the database. 
  * There are bunch of required parameters required to be passed as $params array:
  * - login: the arbitrary string which will be used as a login for the user. The checks defined in
  * {@link setLogin} method will be performed.
  * - password: user's password. The checks defined in {@link setPassword} will be performed.
  * - email: required parameter to, for example, send confirmation emails. The checks defined in 
  * {@link setEmail} method will be performed.
  *
  * Optionally, the 'state' parameter may be passed, showing the status of newly created user. 
  * If it's omitted, the "not_confirmed" or "active" state will be chosen depending on the 
  * <code>config.user.registration_confirm</code> config parameter. If the value distinguish 
  * from the described ones, make sure that this value could be held by the DB schema of the 'state' column.
  *
  * If <code>config.user.registration_confirm</code> config parameter is set to non-false value, 
  * the one time token will be added for newly created user. This could be used for example to
  * send activation email. Logic behind that should be created separately in the model/controller.
  *
  * Additionally, the profile entry for the new user will be created.
  *
  * Behavior BeforeAddNewUser is defined.
  *
  * @param array parameters for the new user as described above
  * @return User new user object
  * @throws UserException in case of errors
  */
 static function add(array $params)
 {
     if (empty($params['login']) || empty($params['password']) || empty($params['email'])) {
         throw new UserException("Login, password and email must be passed");
     }
     $config = Config::getInstance();
     if (empty($params['state'])) {
         $params['state'] = $config->user->registration_confirm ? "not_confirmed" : "active";
     }
     if (self::findBy('login', $params['login'])) {
         throw new UserException("User with the same login already exists");
     }
     $new_user = new self(null);
     $new_user->setLogin($params['login']);
     $new_user->setPassword($params['password']);
     $new_user->setState($params['state']);
     $new_user->setEmail($params['email']);
     $new_user->trigger("BeforeAddNewUser", array($new_user, &$params));
     $new_user->save();
     $one_time_token = null;
     if ($config->user->registration_confirm) {
         $one_time_token = OneTimeTokenAuth::generateAndAddToken($new_user->getId());
     }
     Profile::addUser($new_user->getId());
     return $new_user;
 }
Example #6
0
 public static function obHandler($output)
 {
     if (!self::$ob_skip) {
         $instance = new self(self::LOG_WARNING);
         $state = $instance->getState();
         $instance->current_stage = $state['stage_name'] . '_' . self::STATE_ERROR;
         $instance->current_chunk_id = $state['chunk_id'];
         $message = $output;
         if ($error = error_get_last()) {
             $message .= sprintf('%s @%s:%d', $error['message'], $error['file'], $error['line']);
         }
         $instance->writeLog(__METHOD__ . ' error : ' . $message, self::LOG_ERROR);
         $state = array_merge($state, array('error' => $message, 'stage_status' => self::STATE_ERROR));
         $instance->setState($state);
     }
     return $output;
 }
Example #7
0
 public static function create(array $data)
 {
     $add = new self();
     if (isset($data['street'])) {
         $add->setStreet($data['street']);
     }
     if (isset($data['city'])) {
         $add->setCity($data['city']);
     }
     if (isset($data['state'])) {
         $add->setState($data['state']);
     }
     if (isset($data['country'])) {
         $add->setCountry($data['country']);
     }
     if (isset($data['neighborhood'])) {
         $add->setNeighborhood($data['neighborhood']);
     }
     if (isset($data['number'])) {
         $add->setNumber((int) $data['number']);
     }
     if (isset($data['zipcode'])) {
         $add->setZipcode($data['zipcode']);
     }
     return $add;
 }
 public static function obHandler($output)
 {
     if (!self::$ob_skip) {
         $instance = new self(self::LOG_WARNING);
         $state = $instance->getState();
         $instance->current_stage = $state['stage_name'] . '_' . self::STATE_ERROR;
         $instance->current_chunk_id = $state['chunk_id'];
         $instance->writeLog(__METHOD__ . ' error: ' . strip_tags($output), self::LOG_ERROR);
         $state = array_merge($state, array('error' => strip_tags($output), 'stage_status' => self::STATE_ERROR));
         $instance->setState($state);
     }
     return $output;
 }