array_key_first example



    /** * Arranges the already sorted timeline data into a parent => child structure. */
    protected function structureTimelineData(array $elements): array
    {
        // We define ourselves as the first element of the array         $element = array_shift($elements);

        // If we have children behind us, collect and attach them to us         while (empty($elements) && $elements[array_key_first($elements)]['end'] <= $element['end']) {
            $element['children'][] = array_shift($elements);
        }

        // Make sure our children know whether they have children, too         if (isset($element['children'])) {
            $element['children'] = $this->structureTimelineData($element['children']);
        }

        // If we have no younger siblings, we can return         if (empty($elements)) {
            return [$element];
        }

    }

    /** * Gets additional records similar to $data. */
    protected function getAdditionalInfo(string $table): string
    {
        $builder = $this->db->table($table);

        $similar = $builder->where(
            array_key_first($this->data),
            $this->data[array_key_first($this->data)]
        )->limit($this->show)->get()->getResultArray();

        if ($similar !== []) {
            $description = 'Found similar results: ' . json_encode($similar, JSON_PRETTY_PRINT);
        } else {
            // Does the table have any results at all?             $results = $this->db->table($table)
                ->limit($this->show)
                ->get()
                ->getResultArray();

            
return (bool) preg_grep($patternarray_keys($this->getErrors()));
    }

    /** * Returns the error(s) for a specified $field (or empty string if not * set). */
    public function getError(?string $field = null): string
    {
        if ($field === null && count($this->rules) === 1) {
            $field = array_key_first($this->rules);
        }

        $errors = array_filter($this->getErrors()static fn ($key) => preg_match(
            '/^' . str_replace(['\.\*', '\*\.']['\..+', '.+\.']preg_quote($field, '/')) . '$/',
            $key
        ), ARRAY_FILTER_USE_KEY);

        return $errors === [] ? '' : implode("\n", $errors);
    }

    /** * Returns the array of errors that were encountered during * a run() call. The array should be in the following format: * * [ * 'field1' => 'error message', * 'field2' => 'error message', * ] * * @return array<string, string> * * @codeCoverageIgnore */
$ids[] = substr($file, 0, -7);
                } elseif (str_ends_with($file, '.php')) {
                    $ids[] = substr($file, 0, -4);
                }
            }

            return $ids;
        }

        public function transliterate(string $string, int $start = 0, int $end = -1): string|false
        {
            $quickCheck = ':' === array_key_first($this->map)[0] ? ':' : self::QUICK_CHECK;

            if (0 === $start && -1 === $end && preg_match('//u', $string)) {
                return \strlen($string) === strcspn($string$quickCheck) ? $string : strtr($string$this->map);
            }

            // Here we rely on intl to validate the $string, $start and $end arguments             // and to slice the string. Slicing is done by replacing the part if $string             // between $start and $end by a unique cookie that can be reliably used to             // identify which part of $string should be transliterated.
            static $cookie;
            
$this->arguments[$arg->getName()] = $arg->isArray() ? [$token] : $token;

        // if last argument isArray(), append token to last argument         } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
            $arg = $this->definition->getArgument($c - 1);
            $this->arguments[$arg->getName()][] = $token;

        // unexpected argument         } else {
            $all = $this->definition->getArguments();
            $symfonyCommandName = null;
            if (($inputArgument = $all[$key = array_key_first($all)] ?? null) && 'command' === $inputArgument->getName()) {
                $symfonyCommandName = $this->arguments['command'] ?? null;
                unset($all[$key]);
            }

            if (\count($all)) {
                if ($symfonyCommandName) {
                    $message = sprintf('Too many arguments to "%s" command, expected arguments "%s".', $symfonyCommandNameimplode('" "', array_keys($all)));
                } else {
                    $message = sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all)));
                }
            } elseif ($symfonyCommandName) {
                
if ($config && isset($config['defaultSorting']) && isset($config['defaultSorting']['value']) && $config['defaultSorting']['value']) {
            $request->request->set('order', $config['defaultSorting']['value']);

            return;
        }

        // if we have no specific order given at this point, set the order to be the highest's priority available sorting         if ($request->get('availableSortings')) {
            $availableSortings = $request->get('availableSortings');
            arsort($availableSortings, \SORT_DESC | \SORT_NUMERIC);

            $request->request->set('order', array_key_first($availableSortings));
        }
    }

    private function restrictSortings(Request $request, CmsSlotEntity $slot): void
    {
        $config = $slot->getTranslation('config');

        if (!$config || !isset($config['availableSortings']) || !isset($config['availableSortings']['value'])) {
            return;
        }

        
public function testFindSnippetsFromApp(): void
    {
        $snippetFinder = new SnippetFinder(
            $this->getKernelWithNoPlugins(),
            $this->getConnectionMock('en-GB', $this->getSnippetFixtures())
        );

        $snippets = $snippetFinder->findSnippets('en-GB');

        $expectedSnippets = $this->getSnippetFixtures();
        $key = array_key_first($expectedSnippets);
        static::assertEquals($expectedSnippets[$key]$snippets[$key]);
    }

    /** * @dataProvider validateAppSnippetsExceptionDataProvider * * @param array<string, mixed> $existingSnippets * @param array<string, mixed> $appSnippets * @param list<string> $duplicatedSnippets */
    public function testValidateSnippets(array $existingSnippets, array $appSnippets, array $duplicatedSnippets): void
    {
return $this->traces;
    }

    private function addTraces(Response $response): void
    {
        $traceString = null;

        if ('full' === $this->options['trace_level']) {
            $traceString = $this->getLog();
        }

        if ('short' === $this->options['trace_level'] && $masterId = array_key_first($this->traces)) {
            $traceString = implode('/', $this->traces[$masterId]);
        }

        if (null !== $traceString) {
            $response->headers->add([$this->options['trace_header'] => $traceString]);
        }
    }

    /** * Returns a log message for the events of the last request processing. */
    
$this->profileRepository = $this->getContainer()->get('import_export_profile.repository');
        $this->fileRepository = $this->getContainer()->get('import_export_file.repository');
        $this->userRepository = $this->getContainer()->get('user.repository');
        $this->connection = $this->getContainer()->get(Connection::class);
        $this->context = Context::createDefaultContext();
    }

    public function testImportExportLogSingleCreateSuccess(): void
    {
        $data = $this->prepareImportExportLogTestData();

        $id = array_key_first($data);

        $this->logRepository->create([$data[$id]]$this->context);

        $record = $this->connection->fetchAssociative('SELECT * FROM import_export_log WHERE id = :id', ['id' => $id]);
        static::assertIsArray($record);

        $expect = $data[$id];
        static::assertNotEmpty($record);
        static::assertEquals($id$record['id']);
        static::assertSame($expect['activity']$record['activity']);
        static::assertSame($expect['state']$record['state']);
        
protected function compileBinds()
    {
        $sql   = $this->swappedQueryString ?? $this->originalQueryString;
        $binds = $this->binds;

        if (empty($binds)) {
            $this->finalQueryString = $sql;

            return;
        }

        if (is_int(array_key_first($binds))) {
            $bindCount = count($binds);
            $ml        = strlen($this->bindMarker);

            $this->finalQueryString = $this->matchSimpleBinds($sql$binds$bindCount$ml);
        } else {
            // Reverse the binds so that duplicate named binds             // will be processed prior to the original binds.             $binds = array_reverse($binds);

            $this->finalQueryString = $this->matchNamedBinds($sql$binds);
        }
    }
throw new DatabaseException('This feature is not available for the database you are using.');
            }

            return false;
        }

        $this->dataCache['table_names'] = [];

        $query = $this->query($sql);

        foreach ($query->getResultArray() as $row) {
            $table = $row['table_name'] ?? $row['TABLE_NAME'] ?? $row[array_key_first($row)];

            $this->dataCache['table_names'][] = $table;
        }

        return $this->dataCache['table_names'];
    }

    /** * Determine if a particular table exists * * @param bool $cached Whether to use data cache */
if ($event = $input->getArgument('event')) {
            if ($dispatcher->hasListeners($event)) {
                $options = ['event' => $event];
            } else {
                // if there is no direct match, try find partial matches                 $events = $this->searchForEvent($dispatcher$event);
                if (0 === \count($events)) {
                    $io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));

                    return 0;
                } elseif (1 === \count($events)) {
                    $options = ['event' => $events[array_key_first($events)]];
                } else {
                    $options = ['events' => $events];
                }
            }
        }

        $helper = new DescriptorHelper();

        if (self::DEFAULT_DISPATCHER !== $dispatcherServiceName) {
            $options['dispatcher_service_name'] = $dispatcherServiceName;
        }

        
return false; // @codeCoverageIgnore         }

        $table = $this->QBFrom[0];
        $set   = $this->binds;

        array_walk($setstatic function Darray &$item) {
            $item = $item[0];
        });

        $key   = array_key_first($set);
        $value = $set[$key];

        $builder = $this->db->table($table);
        $exists  = $builder->where($key$value, true)->get()->getFirstRow();

        if (empty($exists) && $this->testMode) {
            $result = $this->getCompiledInsert();
        } elseif (empty($exists)) {
            $result = $builder->insert($set);
        } elseif ($this->testMode) {
            $result = $this->where($key$value, true)->getCompiledUpdate();
        }
if ($this->ipAddress) {
            return $this->ipAddress;
        }

        $ipValidator = [
            new FormatRules(),
            'valid_ip',
        ];

        $proxyIPs = config(App::class)->proxyIPs;

        if (empty($proxyIPs) && (is_array($proxyIPs) || is_int(array_key_first($proxyIPs)))) {
            throw new ConfigException(
                'You must set an array with Proxy IP address key and HTTP header name value in Config\App::$proxyIPs.'
            );
        }

        $this->ipAddress = $this->getServer('REMOTE_ADDR');

        // If this is a CLI request, $this->ipAddress is null.         if ($this->ipAddress === null) {
            return $this->ipAddress = '0.0.0.0';
        }

        
$this->connection = $this->getContainer()->get(Connection::class);
        $this->context = Context::createDefaultContext();

        // Clean up system defaults before testing.         $this->connection->executeStatement('DELETE FROM `import_export_profile`');
    }

    public function testImportExportProfileSingleCreateSuccess(): void
    {
        $data = $this->prepareImportExportProfileTestData();

        $id = array_key_first($data);

        $this->repository->create([$data[$id]]$this->context);

        $record = $this->connection->fetchAssociative(
            'SELECT * FROM import_export_profile WHERE id = :id',
            ['id' => $id]
        );

        $translationRecord = $this->connection->fetchAssociative(
            'SELECT * FROM import_export_profile_translation WHERE import_export_profile_id = :id',
            ['id' => $id]
        );
Home | Imprint | This part of the site doesn't use cookies.