コード例 #1
0
ファイル: Income.php プロジェクト: kissarat/tornados.su
 public static function make($node_id, User $user, $type_id, $time, $amount)
 {
     $user->account += (double) $amount;
     if ($user->update(false, ['account'])) {
         $income = new static(['node_id' => $node_id, 'user_name' => $user->name, 'type_id' => $type_id, 'time' => $time]);
         if ($income->save()) {
             return $income;
         } else {
             throw new Exception(json_encode($income->getErrors(), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
         }
     } else {
         throw new Exception(json_encode(func_get_args()));
     }
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 public function check($value = null, $schema = null, $path = null, $i = null)
 {
     $type = isset($schema->type) ? $schema->type : null;
     $isValid = true;
     if (is_array($type)) {
         // @TODO refactor
         $validatedOneType = false;
         $errors = array();
         foreach ($type as $tp) {
             $validator = new static($this->checkMode);
             $subSchema = new \stdClass();
             $subSchema->type = $tp;
             $validator->check($value, $subSchema, $path, null);
             $error = $validator->getErrors();
             if (!count($error)) {
                 $validatedOneType = true;
                 break;
             }
             $errors = $error;
         }
         if (!$validatedOneType) {
             $this->addErrors($errors);
             return;
         }
     } elseif (is_object($type)) {
         $this->checkUndefined($value, $type, $path);
     } else {
         $isValid = $this->validateType($value, $type);
     }
     if ($isValid === false) {
         if (!isset(self::$wording[$type])) {
             throw new StandardUnexpectedValueException(sprintf("No wording for %s available, expected wordings are: [%s]", var_export($type, true), implode(', ', array_filter(self::$wording))));
         }
         $errorMsg = I18n::t("constraints.type.required", ['actual' => ucwords(gettype($value)), 'required' => self::$wording[$type]]);
         $this->addError($path, $errorMsg, 'type');
     }
 }
コード例 #3
0
 /**
  * Create a new instance for the result failures.
  *
  * @param  array $items
  * @param  array $bulkItems
  * @return static
  */
 public static function createForResults(array $items, array $bulkItems)
 {
     $instance = new static();
     $instance->processResults($items, $bulkItems);
     $errors = [];
     foreach ($instance->getErrors() as $e) {
         $errors[] = $e->getMessage();
     }
     $instance->message = implode("\n", $errors);
     return $instance;
 }
コード例 #4
0
 /**
  * Stores a CommandInterface object in the database.
  * 
  * @param CommandInterface $command
  * @throws YiiException
  */
 public static function map(CommandInterface $command)
 {
     $mapper = new static();
     $mapper->setCommand($command);
     if ($mapper->save() === false) {
         throw new YiiException('Unable to save an instance of \\jlorente\\command\\db\\CommandMapper. Errors: [' . Json::encode($mapper->getErrors()) . ']');
     }
 }