Define instantiator specific options (usually needed to resolve class inheritance). Might
return null if associated instantiator is unknown to DocumentSchema.

@param SchemaBuilder $builder

@return mixed
353933
protected function instantiationOptions(SchemaBuilder $builder)
    {
        if ($this->getInstantiator() != DocumentInstantiator::class) {
            //Unable to define options for non default inheritance based instantiator
            return null;
        }

        //Let's define a way how to separate one model from another based on given fields
        $helper = new InheritanceHelper($this, $builder->getSchemas());

        return $helper->makeDefinition();
    }
503220
public function query() : Builder
	{
		if (! is_null($this->min) && ! is_null($this->max)) {
			$this->builder->whereBetween('price', [$this->min, $this->max]);
		}

		if (! is_null($this->min) && is_null($this->max)) {
			$this->builder->where('price', '>=', $this->min);
		}

		if (is_null($this->min) && ! is_null($this->max)) {
			$this->builder->where('price', '<=', $this->max);
		}

		return $this->builder;
	}
108728
public static function builder($builder = null)
    {
        if (is_object($builder)) {
            self::$builder = $builder;
        }

        return isset(self::$builder) ? self::$builder : self::$builder = new Builder;
    }
552252
protected function configureContainer(ContainerBuilder $builder)
    {
        $this->default_definitions = array_merge($this->default_definitions, [
            "XhrMiddleware" => function(ContainerInterface $c)
            {
                return new XhrMiddleware($c);
            }
        ]);

        if (is_api_request())
        {
            $this->default_definitions = array_merge($this->default_definitions, [
                # override not found handler
                'notFoundHandler' => function(ContainerInterface $view)
                {
                    return function($request, $response)
                    {
                        return $response->withStatus(404)
                                ->withHeader('Content-Type', "text/json")
                                ->write(json_encode([
                                    'success' => false,
                                    'message' => "It seems you are in the wrong place.",
                                    'status_code' => 404
                                ]));
                    };
                },

                # override not allowed handler
                'notAllowedHandler' => function(ContainerInterface $view)
                {
                    return function($request, $response, $methods)
                    {
                        return $response->withStatus(405)
                                ->withHeader('Allow', implode(', ', $methods))
                                ->withHeader('Content-Type', "text/json")
                                ->write(json_encode([
                                    'success' => false,
                                    'message' => "It seems you are in the wrong place.",
                                    'status_code' => 405
                                ]));
                    };
                },

                # override error handler
                'errorHandler' => function(ContainerInterface $view)
                {
                    return function($request, $response, $exception)
                    {
                        \Log::debug(print_r($exception->getMessage(), true));

                        return $response->withStatus(500)
                                ->withHeader('Content-Type', "text/json")
                                ->write(json_encode([
                                    'success' => false,
                                    'message' => "Looks like something went wrong!. We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.",
                                    'status_code' => 500
                                ]));
                    };
                },

                # override php error handler
                'phpErrorHandler' => function(ContainerInterface $view)
                {
                    return function($request, $response, $exception)
                    {
                        \Log::debug(print_r($exception->getMessage(), true));

                        return $response->withStatus(500)
                                ->withHeader('Content-Type', "text/json")
                                ->write(json_encode([
                                    'success' => false,
                                    'message' => "Looks like something went wrong!. We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.",
                                    'status_code' => 500
                                ]));
                    };
                }
            ]);
        }
        else
        {
            $this->default_definitions = array_merge($this->default_definitions, [
                # override not found handler
                'notFoundHandler' => function(Twig $view)
                {
                    return new NotFoundHandler($view);
                },

                # override not allowed handler
                'notAllowedHandler' => function(Twig $view)
                {
                    return new NotAllowedHandler($view);
                },

                # override error handler
                'errorHandler' => function(Twig $view)
                {
                    return new ErrorHandler($view);
                },

                # override php error handler
                'phpErrorHandler' => function(Twig $view)
                {
                    return new PhpErrorHandler($view);
                },

                # tracy debug bar need this
                'twig_profile' => function()
                {
                    return new \Twig_Profiler_Profile;
                },

                # twig view
                'view' => function(ContainerInterface $c)
                {
                    $view_path = resources_path(config('app.use_dist') ? 'dist-views' : "views");

                    $view = new Twig($view_path, ['cache' => config('twig-view.cache')]);

                    $view->addExtension(new TwigExtension($c->get('router'), $c->get('request')->getUri()));

                    if (is_dev())
                    {
                        $view->addExtension(new \Twig_Extension_Profiler($c->get('twig_profile')));
                        $view->addExtension(new \Twig_Extension_Debug());
                    }

                    $system_functions = ["config", "in_array", "img", "str_title"];
                    $custom_functions = include_once system_path("registered-twig-functions.php");
                    $functions = array_merge($system_functions, $custom_functions);

                    foreach ($functions as $function) {
                        $view->getEnvironment()->addFunction(new \Twig_SimpleFunction($function, $function));
                    }

                    $view->getEnvironment()->addFunction(new \Twig_SimpleFunction('ClassStaticMethod', function() {
                        $args = func_get_args();

                        $class = array_shift($args);
                        $method = array_shift($args);

                        return $class::$method($args);
                    }));

                    # Make 'flash' global
                    $view->getEnvironment()->addGlobal('flash', $c->get('flash'));

                    return $view;
                },

                # slim/flash
                'flash' => function()
                {
                    return new Messages;
                },

                # slim/csrf
                'csrf' => function(Twig $view)
                {
                    $guard = new Guard;
                    $guard->setFailureCallable(function($request, $response, $next) use($view) {
                        if (is_prod())
                        {
                            return $view->render(
                                $response->withStatus(403)->withHeader('Content-Type', "text/html"),
                                config('twig-view.error_pages.403')
                            );
                        }

                        return $response->withStatus(403)
                                        ->withHeader('Content-Type', "text/html")
                                        ->write("Failed CSRF check!");
                    });
                    return $guard;
                },

                # Service injection
                Twig::class => function(ContainerInterface $c)
                {
                    return $c->get('view');
                }
            ]);
        }

        // Use default error handler on development mode
        if (is_dev())
        {
            unset($this->default_definitions['errorHandler']);
            unset($this->default_definitions['phpErrorHandler']);
        }

        # push default controllers in default definitions
        $this->pushControllersInDefinition("\\", app_path("Controllers"), $this->default_definitions);

        if (file_exists(app_path("Middlewares")))
        {
            # push default middlewares in default definitions
            $this->pushMiddlewaresInDefinition("\\", app_path("Middlewares"), $this->default_definitions);
        }

        if (file_exists(app_path("Requests")))
        {
            # push default requests in default definitions
            $this->pushRequestsInDefinition("\\", app_path("Requests"), $this->default_definitions);
        }

        $config_app = config('app');

        if (array_key_exists('modules', $config_app))
        {
            $modules = $config_app['modules'];

            foreach ($modules as $module) {
                if (!empty($module))
                {
                    $module = trim($module, "/");
                    $alias_namespace = str_replace("/", "\\", $module) . "App\\";

                    // controllers
                    if (file_exists($directory = app_path("{$module}/Controllers")))
                    {
                        $this->pushControllersInDefinition($alias_namespace, $directory, $this->default_definitions);
                    }

                    // middlewares
                    if (file_exists($directory = app_path("{$module}/Middlewares")))
                    {
                        $this->pushmiddlewaresInDefinition($alias_namespace, $directory, $this->default_definitions);
                    }

                    // requests
                    if (file_exists($directory = app_path("{$module}/Requests")))
                    {
                        $this->pushRequestsInDefinition($alias_namespace, $directory, $this->default_definitions);
                    }

                    // validation
                    if (file_exists(app_path("{$module}/Validation")))
                    {
                        $rule_prefix = "{$alias_namespace}Validation\\Rules\\";
                        Validator::with($rule_prefix);
                    }

                    // debug bar
                    if (file_exists(app_path("{$module}/Debugbar.php")))
                    {
                        $classPanel = "{$alias_namespace}Debugbar";
                        Debugger::getBar()->addPanel(new $classPanel);
                    }
                }
            }
        }

        // override default settings if the key of it existed in custom definition
        if (!empty($this->custom_definitions))
        {
            $custom_def_keys = array_keys($this->custom_definitions);
            foreach ($custom_def_keys as $key)
            {
                if (array_key_exists($key, $this->default_definitions))
                {
                    unset($this->default_definitions[$key]);
                }
            }
        }

        $builder->addDefinitions(array_merge($this->default_definitions, $this->custom_definitions));
    }
1161391
public function getSchema(): ?Builder
    {
        if (!$this->hasSchema()) {
            $this->setSchema($this->getDefaultSchema());
        }
        return $this->schema;
    }
910060
private function createGeneralTab(FormBuilderInterface $builder)
    {
        return $this->createTab($builder, 'general', array('label' => 'General'))
            ->add('title', TextType::class, array(
                'label' => 'Title',
            ))
            ->add('node', NodeType::class, array(
                'required' => false,
                'placeholder' => 'None',
            ))
            ->add('url', TextType::class, array(
                'required' => false,
            ));
    }
285938
protected static function getBuilder()
    {
        if (self::$builder === null) {
            $setup = new Setup();
            self::$builder = $setup->run();
        }
        return self::$builder;
    }
197211
protected function getFieldBuilder(ClassMetadataBuilder $builder, array $mapping)
    {
        return Field::make(
            $builder,
            $mapping['type'],
            $this->name
        );
    }
200600
public function declareTables(SchemaBuilder $builder): array
    {
        if (!$this->option(Record::CREATE_PIVOT)) {
            //No pivot table creation were requested, noting really to do
            return [];
        }

        $sourceTable = $this->sourceTable($builder);
        $targetTable = $this->targetTable($builder);

        $sourceContext = $this->definition->sourceContext();
        $targetContext = $this->definition->targetContext();

        if (
            $sourceTable->getDriver() != $targetTable->getDriver()
            || $sourceContext->getDatabase() != $targetContext->getDatabase()
        ) {
            //todo: support cross database and cross driver many to many
            throw new RelationSchemaException(
                "ManyToMany relations can only exists inside same database"
            );
        }

        $pivotTable = $builder->requestTable(
            $this->pivotTable(),
            $sourceContext->getDatabase(),
            false,
            true
        );

        /*
         * Declare columns in map/pivot table.
         */
        $thoughtInnerKey = $pivotTable->column($this->option(Record::THOUGHT_INNER_KEY));
        $thoughtInnerKey->nullable(false);
        $thoughtInnerKey->setType($this->resolveType(
            $sourceContext->getColumn($this->option(Record::INNER_KEY))
        ));

        $thoughtOuterKey = $pivotTable->column($this->option(Record::THOUGHT_OUTER_KEY));
        $thoughtOuterKey->nullable(false);
        $thoughtOuterKey->setType($this->resolveType(
            $targetContext->getColumn($this->option(Record::OUTER_KEY))
        ));

        /*
         * Declare user columns in pivot table.
         */
        $rendered = new ColumnRenderer();
        $rendered->renderColumns(
            $this->option(Record::PIVOT_COLUMNS),
            $this->option(Record::PIVOT_DEFAULTS),
            $pivotTable
        );

        //Map might only contain unique link between source and target
        if ($this->option(Record::CREATE_INDEXES)) {
            $pivotTable->index([
                $thoughtInnerKey->getName(),
                $thoughtOuterKey->getName()
            ])->unique();
        }

        //There is 2 constrains between map table and source and table
        if ($this->isConstrained()) {
            $this->createForeign(
                $pivotTable,
                $thoughtInnerKey,
                $sourceContext->getColumn($this->option(Record::INNER_KEY)),
                $this->option(Record::CONSTRAINT_ACTION),
                $this->option(Record::CONSTRAINT_ACTION)
            );

            $this->createForeign(
                $pivotTable,
                $thoughtOuterKey,
                $targetContext->getColumn($this->option(Record::OUTER_KEY)),
                $this->option(Record::CONSTRAINT_ACTION),
                $this->option(Record::CONSTRAINT_ACTION)
            );
        }

        return [$pivotTable];
    }
1287685
private static function _makeBuilder()
    {
        $builder = new Builder();
        $builder->table = self::getTableName();
        $builder->order = self::getOrder();
        $builder->cls   = get_called_class();
        return $builder;
    }
632295
public function run(Builder $builder): Builder
    {
        if ($builder->getQuery()->getConnection() instanceof PostgresConnection) {
            return $builder->whereRaw('content::TEXT ILIKE ?', '%'.$this->request->get('search').'%');
        }

        return $builder->where('content', 'LIKE', '%'.$this->request->get('search').'%');
    }
1081672
protected function addCreatedAt(ModelQueryBuilder $builder): ModelQueryBuilder
    {
        // `Doctrine` specifics: `setValue` works for inserts and `set` for updates
        $timestamp = $this->convertDateTimeToDbValue($builder, new DateTimeImmutable());
        $builder->setValue(CommonFields::FIELD_CREATED_AT, $builder->createNamedParameter($timestamp));

        return $builder;
    }
679326
public function setBuilder(AssertionBuilder $builder)
    {
        if ( ! is_null($this->builder) and $this->configuration["implicit_validation"]) {
            $this->go();
        }

        $this->builders[] = $builder;
        $this->builder = $builder;
    }
272648
public function apply(Builder $builder)
    {
        $this->builder = $builder;

        // We need to select all columns from the original
        // table, since many joins can mess up the selected fields
        $this->builder->select("{$this->getTableName()}.*");

        foreach ($this->filters() as $name => $value) {
            $this->callFilterMethod($name, $value);
        }

        return $this->builder;
    }
963924
public function defineFormBuilder(FormBuilderInterface $formBuilder)
    {
        /** @var AbstractAdmin $admin */
        $admin = $this;

        $mapper = new \Compo\Sonata\AdminBundle\Form\FormMapper($admin->getFormContractor(), $formBuilder, $admin);

        $this->configureFormFields($mapper);

        foreach ($admin->getExtensions() as $extension) {
            $extension->configureFormFields($mapper);
        }

        $this->attachInlineValidator();
    }
1097292
public function prepare($builder = null)
    {
        // NOTE: because the same ActiveQuery may be used to build different SQL statements
        // (e.g. by ActiveDataProvider, one for count query, the other for row data query,
        // it is important to make sure the same ActiveQuery can be used to build SQL statements
        // multiple times.
        if (!empty($this->joinWith)) {
            $this->buildJoinWith();
            $this->joinWith = null;
        }

        return $this;
    }
99846
public function addSchema(SchemaInterface $schema): SchemaBuilder
    {
        $this->schemas[$schema->getClass()] = $schema;

        return $this;
    }