This will return an ajax register, and reuse it from time to time
@return ServerImpl
191702
public function getAJAXServerInstance()
    {
        if ($this->ajaxServer === null) {
            $this->ajaxServer = new ServerImpl($this);
        }
        return $this->ajaxServer;
    }
601922
protected function registerMiddleware()
    {
        $this->app->singleton(NodesHttpMiddlewareRequest::class, function ($app) {
            $middleware = new NodesHttpMiddlewareRequest(
                $app,
                $app['api.exception'],
                $app['api.router'],
                $app['api.http.validator'],
                $app['events']
            );
            $middleware->setMiddlewares(config('nodes.api.middleware', []));

            return $middleware;
        });

        $this->app->singleton(NodesHttpMiddlewareAuth::class, function ($app) {
            return new NodesHttpMiddlewareAuth($app['api.router'], $app['api.auth']);
        });

        $this->app->singleton(NodesHttpMiddlewareRateLimit::class, function ($app) {
            return new NodesHttpMiddlewareRateLimit($app['api.router'], $app['api.limiting']);
        });

        $this->app->singleton(NodesHttpMiddlewarePrepareController::class, function ($app) {
            return new NodesHttpMiddlewarePrepareController($app['api.router']);
        });
    }
336602
public function getRegisteredObject()
    {
        if($this->registeredObject == null)
        {
            $di = jaxon()->di();
            // Use the Reflection class to get the parameters of the constructor
            if(($constructor = $this->reflectionClass->getConstructor()) != null)
            {
                $parameters = $constructor->getParameters();
                $parameterInstances = [];
                foreach($parameters as $parameter)
                {
                    // Get the parameter instance from the DI
                    $parameterInstances[] = $di->get($parameter->getClass()->getName());
                }
                $this->registeredObject = $this->reflectionClass->newInstanceArgs($parameterInstances);
            }
            else
            {
                $this->registeredObject = $this->reflectionClass->newInstance();
            }
        }
        return $this->registeredObject;
    }
204133
public static function register() {
		ini_set('display_errors', 0);
		ini_set('display_startup_errors', 0);
		error_reporting(-1);

		static::$reservedMemory = str_repeat('a', 10240);
		static::$errorAtStart = error_get_last();

		$errorHandler = new static();
		set_error_handler([$errorHandler, 'phpErrorHandler']);
		set_exception_handler([$errorHandler, 'exceptionHandler']);

		return $errorHandler;
	}
216169
function register()
	{
		set_error_handler(array($this,'_handleError'));
		set_exception_handler(array($this,'_handleException'));
		register_shutdown_function(array($this,'_shutdown'));
		$this->_registered = true;
		return $this;
	}
209441
public function register()
    {
        AliasLoader::getInstance()->alias( 'ArboryRouter', ArboryRouter::class );
        AliasLoader::getInstance()->alias( 'Admin', Admin::class );
        AliasLoader::getInstance()->alias( 'Page', Page::class );
        AliasLoader::getInstance()->alias( 'Settings', Settings::class );

        $this->app->singleton( NodesRepository::class, function()
        {
            $repository = new NodesRepository();

            $repository->setQueryOnlyActiveNodes( true );

            return $repository;
        } );

        $this->app->singleton( ContentTypeRegister::class, function ()
        {
            return new ContentTypeRegister();
        } );

        $this->app->singleton( 'arbory_router', function ()
        {
            return $this->app->make( ContentTypeRoutesRegister::class );
        } );

        $this->app->singleton( 'arbory_page_builder', function()
        {
            return new PageBuilder(
                $this->app->make( ContentTypeRegister::class ),
                $this->app->make( 'arbory_router' )
            );
        } );

        $this->routes = $this->app->make( 'arbory_router' );
    }
475308
protected function registerJs()
	{
		if (static::$JS_REGISTERED) return;

		JqueryAsset::register($this->getView());
		BootstrapAsset::register($this->getView());

		$js = new JsExpression(<<<JS
			var widgetClass = 'widget-memory-tabs';
			var storageName = 'widget-memory-tabs';

			var hasStorage = function() {
				var test = 'test';
				try {
					{$this->storageType}.setItem(test, test);
					{$this->storageType}.removeItem(test);
					return true;
				} catch(e) {
					return false;
				}
			};

			if (hasStorage) {

				var loadData = function() {
					var dataStr = {$this->storageType}.getItem(storageName);
					if (dataStr == null) return {};
					return JSON.parse(dataStr);
				};

				var saveData = function(dataObj) {
					dataStr = JSON.stringify(dataObj);
					{$this->storageType}.setItem(storageName, dataStr);
				};

				var activateIndex = function(tabId, index) {
					var tab = $('#' + tabId);
					var items = tab.children('li');
					if (items.length <= index) return;

					$('#' + tabId + ' li:eq(' + index + ') a').tab('show');
				};
				
				var getBaseUrlByAnchor = function(url) {
					var hashTagIndex = url.indexOf('#',0);
					if (hashTagIndex === -1) return null;
					return url.substring(0, hashTagIndex);
				};

				var initIndexes = function() {
					var data = loadData();
					var curUrl = window.location.href;
					if (data[curUrl] == null) {
						var baseUrl = getBaseUrlByAnchor(curUrl);
						if (baseUrl === null) {
							return;
						} else if (data[baseUrl] == null) {
							return;
						}
						curUrl = baseUrl;
					}
					var tabs = $('.' + widgetClass);
					tabs.each(function(i, el) {
						var tabId = $(this).attr('id');
						if (tabId != null) {
							var index = data[curUrl][tabId];
							activateIndex(tabId, index);
						}
					});
				};

				var setIndex = function(tabId, index) {
					var curUrl = window.location.href;
					var baseUrl = getBaseUrlByAnchor(curUrl);

					var data = loadData();
					
					if(data[curUrl] == null) {
						if (baseUrl !== null && data[baseUrl] == null) {
							data[baseUrl] = {};
						} else if (baseUrl === null) {
							data[curUrl] = {};
						} else {
							curUrl = baseUrl;
						}
					}

					data[curUrl][tabId] = index;

					saveData(data);
				};

				$('.widget-memory-tabs > li > a').mouseup(function(event) {
					var tabs = $(this).closest('.' + widgetClass);
					var selectedIndex = $(this).parent().prevAll().length;

					setIndex(tabs.attr('id'), selectedIndex);
				});

				initIndexes();
			}
JS
);
		$this->view->registerJs($js);

		static::$JS_REGISTERED = true;
	}
1326388
protected function registerService()
	{
	    $this->app->singleton($this->getProviderKey(), function($app)
	    {
	    	return new Service($this->getProviderKey(), new Processor($this->getAggregateService()), $this->getAggregateService());
	    });
	}
1286238
public function getInstance()
    {
        if (!$this->parserInstance) {
            /**
             * Check if Twig_Autoloader class exists
             * otherwise include it.
             */
        
            if (!class_exists('\Twig_Autoloader')) {
                require_once $this->parserDirectory . '/Autoloader.php';
            }

            \Twig_Autoloader::register();
            $loader = new \Twig_Loader_Filesystem($this->getTemplateDirs());
            $this->parserInstance = new \Twig_Environment(
                $loader,
                $this->parserOptions
            );

            foreach ($this->parserExtensions as $ext) {
                $extension = is_object($ext) ? $ext : new $ext;
                $this->parserInstance->addExtension($extension);
            }
        }

        return $this->parserInstance;
    }
625803
public function register(
        ServerRequestInterface $request, ResponseInterface $response
    ) {
        $this->request = $request;
        $this->response = $response;
        return $this;
    }
974804
public function ajax()
    {
        return datatables($this->query())
            ->setTransformer(app($this->transformer))
            ->filterColumn('country_code', function (Builder $builder, $keyword) {
                $countryCode = collect(countries())->search(function ($country) use ($keyword) {
                    return mb_strpos($country['name'], $keyword) !== false || mb_strpos($country['emoji'], $keyword) !== false;
                });

                ! $countryCode || $builder->where('country_code', $countryCode);
            })
            ->filterColumn('language_code', function (Builder $builder, $keyword) {
                $languageCode = collect(languages())->search(function ($language) use ($keyword) {
                    return mb_strpos($language['name'], $keyword) !== false;
                });

                ! $languageCode || $builder->where('language_code', $languageCode);
            })
            ->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1')
            ->make(true);
    }
609257
public static function createFromServerConfiguration() {
        //@codeCoverageIgnoreStart
        if (extension_loaded('gmp')) {
            return new \SecurityLib\BigMath\GMP();
        } elseif (extension_loaded('bcmath')) {
            return new \SecurityLib\BigMath\BCMath();
        } else {
            return new \SecurityLib\BigMath\PHPMath();
        }
        //@codeCoverageIgnoreEnd
    }
791294
public function invoke()
    {
        $arguments = $this->arguments;

        if (($serverHost = $arguments->{'server-host'}) !== null) {
            $this->server = new Server($serverHost, $arguments->{'server-root'});
            $this->server->start();
        }

        //Include bootstrap file if set
        if (($bootstrapFile = $arguments->bootstrap)) {
            require $bootstrapFile;
        }

        echo 'testphase v' . Testphase::getVersion() . PHP_EOL;

        if ($arguments->help) {
            echo 'Help:' . PHP_EOL;
            $printer = new ConsoleOptionPrinter;
            echo $printer->render(static::getArgumentSpecifications());
            return 0;
        } elseif ($arguments->debug) {
            echo 'Enabled options: ' . PHP_EOL;

            foreach ($arguments as $key => $spec) {
                echo $spec;
            }
        }

        try {
            $testParserCollection = $this->getTestParserCollection();
        } catch (\Exception $e) {
            echo $e->getMessage();
            return $this->stop(1);
        }

        //Statistics object
        $stats = (object)[
            'tests' => count($testParserCollection),
            'success' => 0,
            'error' => 0,
            'failure' => 0,
            'ignore' => 0,
            'incomplete' => 0,
            'errors' => []
        ];

        $testIndex = 0;

        foreach ($testParserCollection as $test) {

            //Check if subdir argument is set
            if (isset($arguments->subdir) && $arguments->subdir !== null) {
                //If so check if file name passes the given pattern

                //Remove base dir from filename
                $cleanFilename = trim(
                    str_replace(
                        $arguments->dir,
                        '',
                        $test->getFilename()
                    ),
                    '/'
                );

                $match = false;

                //Check if file name matches any of the subdir patterns
                foreach ($arguments->subdir as $pattern) {
                    $pattern = '@' . $pattern . '@';
                    if (!!preg_match($pattern, $cleanFilename)) {
                        $match = $match || true;
                        break;
                    }
                }

                if (!$match) {
                    //Ignore
                    $stats->ignore += 1;
                    if ($arguments->verbose) {
                        echo sprintf(
                            'I %s',
                            $test->getFilename()
                        ) . PHP_EOL;
                    } else {
                        echo 'I';
                    }
                    continue;
                }
            }

            $meta = $test->getMeta();

            if (isset($meta->ignore) && $meta->ignore) {
                if ($arguments->verbose) {
                    echo sprintf(
                        'I %s',
                        $test->getFilename()
                    ) . PHP_EOL;
                } else {
                    echo 'I';
                }
                $stats->ignore += 1;
                continue;
            }


            if (isset($meta->incomplete) && $meta->incomplete !== false) {
                $stats->incomplete += 1;
            }

            try {
                //Complete test's testphase collection
                $test->createTest();
            } catch (\Exception $e) {
                echo sprintf(
                    'Unable to create test from file "%s" %s With message: "%s"',
                    $test->getFilename(),
                    PHP_EOL,
                    $e->getMessage()
                ) . PHP_EOL;
                return $this->stop(1);
            }

            $testphaseCollection = $test->getTest();

            //Include number of additional testphase collections
            $stats->tests += count($testphaseCollection) - 1;
    
            //Iterate though test parser's testphase collection
            foreach ($testphaseCollection as $testphase) {
                try {
                    $testphase->run(function (
                        $responseStatusCode,
                        $responseHeaders,
                        $responseBody,
                        $responseBodyObject = null
                    ) use (
                        $test,
                        $arguments
                    ) {
                        //todo move to TestParser
                        $export = $test->getExport();

                        //Fetch all test exports and add them as globals
                        foreach ($export as $key => $value) {
                            $path = explode('.', $value);

                            $pathValue = $responseBodyObject;

                            foreach ($path as $p) {
                                //@todo implement array index
                                $arrayIndex = 0;

                                if (is_array($pathValue)) {
                                    $pathValue = $pathValue[$arrayIndex]->{$p};
                                } else {
                                    $pathValue = $pathValue->{$p};
                                }
                            }

                            Globals::set($key, $pathValue);
                        }

                        if ($arguments->debug) {
                            echo 'Response Status Code:' . PHP_EOL;
                            echo $responseStatusCode . PHP_EOL;
                            echo 'Response Headers:' . PHP_EOL;
                            print_r($responseHeaders);
                            echo PHP_EOL;
                            echo 'Response Body:' . PHP_EOL;
                            echo json_encode($responseBodyObject, JSON_PRETTY_PRINT) . PHP_EOL;
                        }
                    });

                    //Echo successful char
                    if ($arguments->verbose) {
                        echo sprintf(
                            '. %s',
                            $test->getFilename()
                        ) . PHP_EOL;
                    } else {
                        echo '.';
                    }
                    $stats->success += 1;
                } catch (UnsetGlobalException $e) {

                    //Error message
                    $message = $e->getMessage();

                    $message = sprintf(
                        self::colored('Test "%s" failed with message', 'red') . PHP_EOL . ' %s' . PHP_EOL,
                        $test->getFilename(),
                        $message
                    );

                    //push message to error message
                    $stats->errors[] = $message;

                    //Echo unsuccessful char
                    if ($arguments->verbose) {
                        echo sprintf(
                                'F %s',
                                $test->getFilename()
                            ) . PHP_EOL;
                    } else {
                        echo 'F';
                    }

                    //print if immediate
                    if ($arguments->immediate) {
                        echo PHP_EOL . $message . PHP_EOL;
                    }

                    //Error message
                    $stats->error += 1;
                } catch (\Exception $e) {

                    //Error message
                    $message = $e->getMessage();

                    if ($arguments->debug) {
                        $message .= PHP_EOL . $testphase->getResponseBody();
                    }

                    $message = sprintf(
                        self::colored('Test "%s" failed with message', 'red') . PHP_EOL . ' %s' . PHP_EOL,
                        $test->getFilename(),
                        $message
                    );

                    if (get_class($e) == IncorrectParametersException::class) {
                        $message .= 'Incorrect:' . PHP_EOL
                            . json_encode($e->getParameters(), JSON_PRETTY_PRINT) . PHP_EOL;
                    } elseif (get_class($e) == MissingParametersException::class) {
                        $message .= 'Missing:' . PHP_EOL
                            . json_encode($e->getParameters(), JSON_PRETTY_PRINT) . PHP_EOL;
                    }

                    //push message to error message
                    $stats->errors[] = $message;

                    //Echo unsuccessful char
                    if ($arguments->verbose) {
                        echo sprintf(
                            'F %s',
                            $test->getFilename()
                        ) . PHP_EOL;
                    } else {
                        echo 'F';
                    }

                    //print if immediate
                    if ($arguments->immediate) {
                        echo PHP_EOL . $message . PHP_EOL;
                    }

                    $stats->failure += 1;
                }
                ++$testIndex;
                //Show only 80 characters per line
                if (!($testIndex % 79)) {
                    echo PHP_EOL;
                }
            }
        }

        echo PHP_EOL;

        if ($arguments->{'show-globals'}) {
            echo 'Globals:' . PHP_EOL;
            echo Globals::toString() . PHP_EOL;
        }

        //don't print if immediate is true
        if (!$arguments->immediate && !empty($stats->errors)) {
            echo 'Errors:' . PHP_EOL;
            foreach ($stats->errors as $e) {
                echo $e . PHP_EOL;
            }
        }

        echo 'Complete!' . PHP_EOL;
        echo 'Tests:' . $stats->tests . ', ';
        Binary::output('Successful: ' . $stats->success, 'green');
        echo ', ';
        Binary::output('Ignored: ' . $stats->ignore, 'yellow');
        echo ', ';
        Binary::output('Incomplete: ' . $stats->incomplete, 'yellow');
        echo ', ';
        Binary::output('Error: ' . $stats->error, 'red');
        echo ', ';
        Binary::output('Failure: ' . $stats->failure . PHP_EOL, 'red');


        echo 'Memory usage: ' . (int)(memory_get_usage(true)/1048576) . ' MB' . PHP_EOL;
        echo 'Elapsed time: ' . (time() - $_SERVER['REQUEST_TIME']) . ' s' . PHP_EOL;

        if ($stats->error > 0) {
            return $this->stop(1);
        }
        if ($stats->failure > 0) {
            return $this->stop(2);
        }

        return $this->stop(0);
    }
39436
public function registerKernel()
    {
        if ($this->runningInConsole()) {
            $this->register('ConsoleKernel', new ConsoleKernel($this));
        }
        else {
            $this->register('HttpKernel', new HttpKernel($this));
        }

        return $this;
    }
754796
public function register()
    {
        $this->mergeConfigFrom(__DIR__.'/../config/ssr.php', 'ssr');

        $this->app->singleton(Node::class, function () {
            return new Node(
                $this->app->config->get('ssr.node.node_path'),
                $this->app->config->get('ssr.node.temp_path')
            );
        });

        $this->app->singleton(V8::class, function () {
            return new V8(new \V8Js());
        });

        $this->app->bind(Engine::class, function () {
            return $this->app->make($this->app->config->get('ssr.engine'));
        });

        $this->app->resolving(
            Renderer::class,
            function (Renderer $serverRenderer) {
                return $serverRenderer
                    ->enabled($this->app->config->get('ssr.enabled'))
                    ->debug($this->app->config->get('ssr.debug'))
                    ->context('url', $this->app->request->getRequestUri())
                    ->context($this->app->config->get('ssr.context'))
                    ->env($this->app->config->get('ssr.env'))
                    ->resolveEntryWith(new MixResolver($this->app->config->get('ssr.mix')));
            }
        );

        $this->app->alias(Renderer::class, 'ssr');
    }
1347113
public function registerClientScript()
	{
		$id=$this->getId();

		if($this->ajaxUpdate===false)
			$ajaxUpdate=array();
		else
			$ajaxUpdate=array_unique(preg_split('/\s*,\s*/',$this->ajaxUpdate.','.$id,-1,PREG_SPLIT_NO_EMPTY));
		$options=array(
			'ajaxUpdate'=>$ajaxUpdate,
			'ajaxVar'=>$this->ajaxVar,
			'pagerClass'=>$this->pagerCssClass,
			'loadingClass'=>$this->loadingCssClass,
			'sorterClass'=>$this->sorterCssClass,
			'enableHistory'=>$this->enableHistory
		);
		if($this->ajaxUrl!==null)
			$options['url']=CHtml::normalizeUrl($this->ajaxUrl);
		if($this->ajaxType!==null)
			$options['ajaxType']=strtoupper($this->ajaxType);
		if($this->updateSelector!==null)
			$options['updateSelector']=$this->updateSelector;
		foreach(array('beforeAjaxUpdate', 'afterAjaxUpdate', 'ajaxUpdateError') as $event)
		{
			if($this->$event!==null)
			{
				if($this->$event instanceof CJavaScriptExpression)
					$options[$event]=$this->$event;
				else
					$options[$event]=new CJavaScriptExpression($this->$event);
			}
		}

		$options=CJavaScript::encode($options);
		$cs=Yii::app()->getClientScript();
		$cs->registerCoreScript('jquery');
		$cs->registerCoreScript('bbq');
		if($this->enableHistory)
			$cs->registerCoreScript('history');
		$cs->registerScriptFile($this->baseScriptUrl.'/jquery.yiilistview.js',CClientScript::POS_END);
		$cs->registerScript(__CLASS__.'#'.$id,"jQuery('#$id').yiiListView($options);");
	}
1174612
public static function register(){
        ini_set('unserialize_callback_func', 'spl_autoload_call');
        spl_autoload_register(function($class){
            $cfile = strtr($class,'_\\','//') . '.php';
            foreach (static::$paths as $path => $v) {
                $file = rtrim($path,'/').'/'.$cfile;
                if(is_file($file)) return include($file);
            }
            return false;
        },false,true);
    }