createFromGlobals example

// Configure settings.     $this->setUpSettings();

    // @todo Allow test classes based on this class to act on further installer     // screens.
    // Configure site.     $this->setUpSite();

    if ($this->isInstalled) {
      // Import new settings.php written by the installer.       $request = Request::createFromGlobals();
      $class_loader = require $this->container->getParameter('app.root') . '/autoload.php';
      Settings::initialize($this->container->getParameter('app.root'), DrupalKernel::findSitePath($request)$class_loader);

      // After writing settings.php, the installer removes write permissions       // from the site directory. To allow drupal_generate_test_ua() to write       // a file containing the private key for drupal_valid_test_ua(), the site       // directory has to be writable.       // BrowserTestBase::tearDown() will delete the entire test site directory.       // Not using File API; a potential error must trigger a PHP warning.       chmod($this->container->getParameter('app.root') . '/' . $this->siteDirectory, 0777);
      $this->kernel = DrupalKernel::createFromRequest($request$class_loader, 'prod', FALSE);
      
$renderer = \Drupal::service('renderer');
    /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
    $render_cache = \Drupal::service('render_cache');

    $build = $view->buildRenderable();
    $original = $build;

    // Ensure the current request is a GET request so that render caching is     // active for direct rendering of views, just like for actual requests.     /** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
    $request_stack = \Drupal::service('request_stack');
    $request = Request::createFromGlobals();
    $request->server->set('REQUEST_TIME', REQUEST_TIME);
    $view->setRequest($request);
    $request_stack->push($request);
    $renderer->renderRoot($build);

    // Check render array cache tags.     sort($expected_render_array_cache_tags);
    $this->assertEqualsCanonicalizing($expected_render_array_cache_tags$build['#cache']['tags']);

    if ($views_caching_is_enabled) {
      // Check Views render cache item cache tags.
$dumper->dump($var);
        };
    }

    private static function getDefaultContextProviders(): array
    {
        $contextProviders = [];

        if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && class_exists(Request::class)) {
            $requestStack = new RequestStack();
            $requestStack->push(Request::createFromGlobals());
            $contextProviders['request'] = new RequestContextProvider($requestStack);
        }

        $fileLinkFormatter = class_exists(FileLinkFormatter::class) ? new FileLinkFormatter(null, $requestStack ?? null) : null;

        return $contextProviders + [
            'cli' => new CliContextProvider(),
            'source' => new SourceContextProvider(null, null, $fileLinkFormatter),
        ];
    }
}
use Drupal\Core\Command\DbToolsApplication;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;

if (PHP_SAPI !== 'cli') {
  return;
}

// Bootstrap. $autoloader = require __DIR__ . '/../../autoload.php';
$request = Request::createFromGlobals();
Settings::initialize(dirname(__DIR__, 2), DrupalKernel::findSitePath($request)$autoloader);
DrupalKernel::createFromRequest($request$autoloader, 'prod')->boot();

// Run the database dump command. $application = new DbToolsApplication();
$application->run();


use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

chdir('../../..');

$autoloader = require_once 'autoload.php';

$kernel = DrupalKernel::createFromRequest(Request::createFromGlobals()$autoloader, 'prod');
$kernel->boot();
$container = $kernel->getContainer();

$views = $container
  ->get('config.factory')
  ->get('statistics.settings')
  ->get('count_content_views');

if ($views) {
  $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT);
  if ($nid) {
    
    $connection_info = Database::getConnectionInfo();
    unset($connection_info['default']['pdo']);
    unset($connection_info['default']['init_commands']);

    $this->settings['databases']['default'] = (object) [
      'value' => $connection_info,
      'required' => TRUE,
    ];

    // Use the kernel to find the site path because the site.path service should     // not be available at this point in the install process.     $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
    // Pre-configure config directories.     $this->settings['settings']['config_sync_directory'] = (object) [
      'value' => $site_path . '/files/config_sync',
      'required' => TRUE,
    ];
    mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
  }

  /** * Visits the interactive installer. */
  
$this->time = new Time($this->requestStack);
  }

  /** * Tests the getRequestTime method. * * @covers ::getRequestTime */
  public function testGetRequestTime() {
    $expected = 12345678;

    $request = Request::createFromGlobals();
    $request->server->set('REQUEST_TIME', $expected);

    // Mocks a the request stack getting the current request.     $this->requestStack->expects($this->any())
      ->method('getCurrentRequest')
      ->willReturn($request);

    $this->assertEquals($expected$this->time->getRequestTime());
  }

  /** * Tests the getRequestMicroTime method. * * @covers ::getRequestMicroTime */
return $this->_view;
    }

    /** * Retrieve test case request object * * @return Enlight_Controller_Request_RequestTestCase */
    public function Request()
    {
        if ($this->_request === null) {
            $this->_request = Enlight_Controller_Request_RequestTestCase::createFromGlobals();
        }

        return $this->_request;
    }

    /** * Retrieve test case response object * * @return Enlight_Controller_Response_ResponseTestCase */
    public function Response()
    {
/** * Controller action which is used to upload a theme zip file * and extract it into the engine\Shopware\Themes folder. * * @throws Exception * * @return void */
    public function uploadAction()
    {
        $file = Symfony\Component\HttpFoundation\Request::createFromGlobals()->files->get('fileId');
        $system = new Filesystem();

        if (strtolower($file->getClientOriginalExtension()) !== 'zip') {
            $name = $file->getClientOriginalName();

            $system->remove($file->getPathname());

            throw new Exception(sprintf('Uploaded file %s is no zip file', $name));
        }
        $targetDirectory = $this->container->get(PathResolver::class)->getFrontendThemeDirectory();

        
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

// Change the directory to the Drupal root. chdir('..');

$autoloader = require_once __DIR__ . '/../autoload.php';
require_once __DIR__ . '/includes/utility.inc';

$request = Request::createFromGlobals();
// Manually resemble early bootstrap of DrupalKernel::boot(). DrupalKernel::bootEnvironment();

try {
  Settings::initialize(dirname(__DIR__), DrupalKernel::findSitePath($request)$autoloader);
}
catch (HttpExceptionInterface $e) {
  $response = new Response('', $e->getStatusCode());
  $response->prepare($request)->send();
  exit;
}

$dumper->dump($var);
        };
    }

    private static function getDefaultContextProviders(): array
    {
        $contextProviders = [];

        if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && class_exists(Request::class)) {
            $requestStack = new RequestStack();
            $requestStack->push(Request::createFromGlobals());
            $contextProviders['request'] = new RequestContextProvider($requestStack);
        }

        $fileLinkFormatter = class_exists(FileLinkFormatter::class) ? new FileLinkFormatter(null, $requestStack ?? null) : null;

        return $contextProviders + [
            'cli' => new CliContextProvider(),
            'source' => new SourceContextProvider(null, null, $fileLinkFormatter),
        ];
    }
}
$options = [];

    // Mocks the formatDiff function of the dateformatter object.     $this->dateFormatterStub
      ->expects($this->exactly(2))
      ->method('formatDiff')
      ->willReturnMap([
        [$timestamp$request_time$options$expected],
        [$timestamp$request_time$options + ['return_as_object' => TRUE]new FormattedDateDiff('1 second', 1)],
      ]);

    $request = Request::createFromGlobals();
    $request->server->set('REQUEST_TIME', $request_time);
    // Mocks a the request stack getting the current request.     $this->requestStack->expects($this->any())
      ->method('getCurrentRequest')
      ->willReturn($request);

    $this->assertEquals($expected$this->dateFormatterStub->formatTimeDiffSince($timestamp$options));
    $options['return_as_object'] = TRUE;
    $expected_object = new FormattedDateDiff('1 second', 1);
    $this->assertEquals($expected_object$this->dateFormatterStub->formatTimeDiffSince($timestamp$options));
  }

  
use Drupal\Core\Command\DbDumpApplication;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;

if (PHP_SAPI !== 'cli') {
  return;
}

// Bootstrap. $autoloader = require __DIR__ . '/../../autoload.php';
$request = Request::createFromGlobals();
Settings::initialize(dirname(__DIR__, 2), DrupalKernel::findSitePath($request)$autoloader);
DrupalKernel::createFromRequest($request$autoloader, 'prod')->boot();

// Run the database dump command. $application = new DbDumpApplication();
$application->run();
protected $otherObject;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->keyValue = $this->createMock('Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface');
    $this->lock = $this->createMock('Drupal\Core\Lock\LockBackendInterface');
    $this->requestStack = new RequestStack();
    $request = Request::createFromGlobals();
    $session = $this->createMock(SessionInterface::class);
    $request->setSession($session);
    $this->requestStack->push($request);
    $current_user = $this->createMock(AccountProxyInterface::class);

    $this->tempStore = new SharedTempStore($this->keyValue, $this->lock, $this->owner, $this->requestStack, $current_user, 604800);

    $this->ownObject = (object) [
      'data' => 'test_data',
      'owner' => $this->owner,
      'updated' => (int) $request->server->get('REQUEST_TIME'),
    ];

    public static function uri(?string $uri = null, bool $getShared = true)
    {
        if ($getShared) {
            return static::getSharedInstance('uri', $uri);
        }

        if ($uri === null) {
            $appConfig = config(App::class);
            $factory   = AppServices::siteurifactory($appConfig, AppServices::superglobals());

            return $factory->createFromGlobals();
        }

        return new URI($uri);
    }

    /** * The Validation class provides tools for validating input data. * * @return ValidationInterface */
    public static function validation(?ValidationConfig $config = null, bool $getShared = true)
    {
Home | Imprint | This part of the site doesn't use cookies.