getArray example


class PhpArrayDumper extends OptimizedPhpArrayDumper {

  /** * {@inheritdoc} */
  public function getArray() {
    $this->serialize = FALSE;
    return parent::getArray();
  }

  /** * {@inheritdoc} */
  protected function dumpCollection($collection, &$resolve = FALSE) {
    $code = [];

    foreach ($collection as $key => $value) {
      if (is_array($value)) {
        $code[$key] = $this->dumpCollection($value);
      }
/** * A list of container aliases. * * @var array */
  protected $aliases;

  /** * {@inheritdoc} */
  public function dump(array $options = []): string|array {
    return serialize($this->getArray());
  }

  /** * Gets the service container definition as a PHP array. * * @return array * A PHP array representation of the service container. */
  public function getArray() {
    $definition = [];
    // Warm aliases first.
// If there is no container and no cached container definition, build a new     // one from scratch.     if (!isset($container) && !isset($container_definition)) {
      $container = $this->compileContainer();

      // Only dump the container if dumping is allowed. This is useful for       // KernelTestBase, which never wants to use the real container, but always       // the container builder.       if ($this->allowDumping) {
        $dumper = new $this->phpArrayDumperClass($container);
        $container_definition = $dumper->getArray();
      }
    }

    // The container was rebuilt successfully.     $this->containerNeedsRebuild = FALSE;

    // Only create a new class if we have a container definition.     if (isset($container_definition)) {
      // Drupal provides two dynamic parameters to access specific paths that       // are determined from the request.       $container_definition['parameters']['app.root'] = $this->getAppRoot();
      
/** * Tests that alias processing works properly. * * @covers ::getAliases * * @dataProvider getAliasesDataProvider */
    public function testGetAliases($aliases$definition_aliases) {
      $this->containerDefinition['aliases'] = $definition_aliases;
      $this->containerBuilder->getAliases()->willReturn($aliases);
      $this->assertEquals($this->containerDefinition, $this->dumper->getArray(), 'Expected definition matches dump.');
    }

    /** * Data provider for testGetAliases(). * * @return array[] * Returns data-set elements with: * - aliases as returned by ContainerBuilder. * - aliases as expected in the container definition. */
    public function getAliasesDataProvider() {
      
Home | Imprint | This part of the site doesn't use cookies.