コード例 #1
0
ファイル: SingularRead.php プロジェクト: torchline/frest
 /**
  * @param bool $forceRegen
  * @return Result\SingularRead
  * @throws FREST\Exception
  */
 public function generateResult($forceRegen = FALSE)
 {
     $this->frest->startTimingForLabel(Type\Timing::PROCESSING, 'singularread');
     $otherResult = parent::generateResult($forceRegen);
     if (isset($otherResult)) {
         return $otherResult;
     }
     $fieldString = $this->generateFieldString($this->fieldSpecs);
     $tablesToReadString = $this->generateTableString($this->tableSpecs);
     $joinString = $this->generateJoinString($this->resource, $this->joinSpecs);
     /** @var Setting\Field $idFieldSetting */
     $idField = $this->resource->getIDField($idFieldSetting);
     $tableWithID = $this->resource->getTableForField($idField);
     $tableAbbrvWithID = $this->getTableAbbreviation($tableWithID);
     $this->frest->stopTimingForLabel(Type\Timing::PROCESSING, 'singularread');
     $this->frest->startTimingForLabel(Type\Timing::SQL, 'singularread');
     $pdo = $this->frest->getConfig()->getPDO();
     $sql = "SELECT {$fieldString} FROM {$tablesToReadString}{$joinString} WHERE {$tableAbbrvWithID}.{$idField} = :id LIMIT 1";
     $stmt = $pdo->prepare($sql);
     $success = $stmt->execute(array(':id' => $this->resourceID));
     if (!$success) {
         throw new FREST\Exception(FREST\Exception::SQLError, 'Failed reading resource from database');
     }
     $objects = $stmt->fetchAll(\PDO::FETCH_OBJ);
     $resultsCount = count($objects);
     if ($resultsCount == 0) {
         throw new FREST\Exception(FREST\Exception::NoResults);
     }
     $this->frest->stopTimingForLabel(Type\Timing::SQL, 'singularread');
     $this->parseObjects($this->resource, $objects, $this->readSettings);
     $this->result = new Result\SingularRead($objects[0]);
     return $this->result;
 }
コード例 #2
0
ファイル: PluralRead.php プロジェクト: torchline/frest
 /**
  * @param $parameter
  * @param $value
  * @return bool
  * @throws FREST\Exception
  */
 protected function isValidURLParameter($parameter, $value)
 {
     /** @noinspection PhpUndefinedClassInspection */
     $isValid = parent::isValidURLParameter($parameter, $value);
     if (!$isValid) {
         // if not already determined to be valid
         $conditionSettings = $this->resource->getConditionSettings();
         $aliasValues = NULL;
         $alias = self::getHandleAndValues($parameter, $aliasValues) ?: $parameter;
         if (!isset($alias) || isset($aliasValues) && count($aliasValues) != 1) {
             throw new FREST\Exception(FREST\Exception::InvalidField, $parameter);
         }
         if (isset($conditionSettings[$alias])) {
             /** @var Setting\Condition $conditionSetting */
             $conditionSetting = $conditionSettings[$alias];
             $fieldSetting = $this->resource->getFieldSettingForAlias($conditionSetting->getAlias());
             if (!isset($fieldSetting)) {
                 throw new FREST\Exception(FREST\Exception::Config, "No field setting found for condition '{$alias}' in resource {$this->resource->getName()}");
             }
             $isValid = TRUE;
         }
     }
     return $isValid;
 }