/**
     * Adds ref to project.
     *
     * @param string  $ref        Ref.
     * @param integer $project_id Project ID.
     *
     * @return integer
     */
    public function addRefToProject($ref, $project_id)
    {
        $sql = 'INSERT INTO ProjectRefs (ProjectId, Name)
				VALUES (:project_id, :name)';
        $this->database->perform($sql, array('project_id' => $project_id, 'name' => $ref));
        return $this->database->lastInsertId();
    }
    /**
     * Processes methods.
     *
     * @param integer          $class_id Class ID.
     * @param \ReflectionClass $class    Class.
     *
     * @return void
     */
    protected function processClassMethods($class_id, \ReflectionClass $class)
    {
        $sql = 'SELECT Name, Id
				FROM ClassMethods
				WHERE ClassId = :class_id';
        $old_methods = $this->db->fetchPairs($sql, array('class_id' => $class_id));
        $insert_sql = '	INSERT INTO ClassMethods (ClassId, Name, ParameterCount, RequiredParameterCount, Scope, IsAbstract, IsFinal, IsStatic, IsVariadic, ReturnsReference, HasReturnType, ReturnType)
						VALUES (:class_id, :name, :parameter_count, :required_parameter_count, :scope, :is_abstract, :is_final, :is_static, :is_variadic, :returns_reference, :has_return_type, :return_type)';
        $update_sql = '	UPDATE ClassMethods
						SET ParameterCount = :parameter_count, RequiredParameterCount = :required_parameter_count, Scope = :scope, IsAbstract = :is_abstract, IsFinal = :is_final, IsStatic = :is_static, IsVariadic = :is_variadic, ReturnsReference = :returns_reference, ReturnType = :return_type, HasReturnType = :has_return_type
						WHERE ClassId = :class_id AND Name = :name';
        $new_methods = array();
        $class_name = $class->getName();
        foreach ($class->getMethods() as $method) {
            if ($method->class !== $class_name) {
                continue;
            }
            $method_name = $method->getName();
            $new_methods[] = $method_name;
            // Doesn't work for parent classes (see https://github.com/goaop/parser-reflection/issues/16).
            $has_return_type = $method->hasReturnType();
            $return_type = $has_return_type ? (string) $method->getReturnType() : null;
            $this->db->perform(isset($old_methods[$method_name]) ? $update_sql : $insert_sql, array('class_id' => $class_id, 'name' => $method_name, 'parameter_count' => $method->getNumberOfParameters(), 'required_parameter_count' => $method->getNumberOfRequiredParameters(), 'scope' => $this->getMethodScope($method), 'is_abstract' => (int) $method->isAbstract(), 'is_final' => (int) $method->isFinal(), 'is_static' => (int) $method->isStatic(), 'is_variadic' => (int) $method->isVariadic(), 'returns_reference' => (int) $method->returnsReference(), 'has_return_type' => (int) $has_return_type, 'return_type' => $return_type));
            $method_id = isset($old_methods[$method_name]) ? $old_methods[$method_name] : $this->db->lastInsertId();
            $this->processClassMethodParameters($method_id, $method);
        }
        $deleted_methods = array_diff($old_methods, $new_methods);
        if ($deleted_methods) {
            $this->deleteClassMethods($class_id, $deleted_methods);
        }
    }
Пример #3
0
 public function insert(array $aParameters)
 {
     $this->formatToDb($aParameters);
     list($sQuery, $aParameters) = $this->buildInsertQuery($this->get('entity'), $aParameters);
     try {
         $this->oPdo->perform($sQuery, $aParameters);
     } catch (\PDOException $oException) {
         $sErrMsg = $oException->getMessage() . "\n  Entity: " . $this->get('entity') . "\n  Query: {$sQuery}" . "\n  Parameters: " . print_r($aParameters, true);
         throw new \RuntimeException($sErrMsg);
     }
     return $this->oPdo->lastInsertId();
 }
Пример #4
0
 /**
  *
  * Returns the last inserted autoincrement sequence value.
  *
  * @param string $name The name of the sequence to check; typically needed
  * only for PostgreSQL, where it takes the form of `<table>_<column>_seq`.
  *
  * @return int
  *
  * @see http://php.net/manual/en/pdo.lastinsertid.php
  *
  */
 public function lastInsertId($name = null)
 {
     $result = $this->pdo->lastInsertId($name);
     $this->logProfiles(__FUNCTION__);
     return $result;
 }