/**
     * 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);
        }
    }
Пример #2
0
 /**
  *
  * Fetches an associative array of rows as key-value pairs (first
  * column is the key, second column is the value).
  *
  * @param string $statement The SQL statement to prepare and execute.
  *
  * @param callable $callable A callable to be applied to each of the rows
  * to be returned.
  *
  * @param array $values Values to bind to the query.
  *
  * @return array
  *
  */
 public function fetchPairs($statement, array $values = array(), $callable = null)
 {
     $result = $this->pdo->fetchPairs($statement, $values, $callable);
     $this->logProfiles(__FUNCTION__);
     return $result;
 }