Creates an options list for truncate

@param mixed $thrower
@return array|null
513376
private function createOptionsForTruncateTrace($thrower): ?array
    {
        if ($thrower) {
            if (is_string($thrower)) {
                return [
                    'namespace' => $thrower,
                ];
            }
            if (is_object($thrower)) {
                return [
                    'namespace' => preg_replace('/(\\\\[^\\\\]+)$/s', '', get_class($thrower)),
                ];
            }
            return null;
        }
        $options = $this->howTruncateTrace;
        if ($options === null) {
            $options = Opts::getHowTruncateTrace();
        }
        if (!$options) {
            return null;
        }
        if ($options === true) {
            $ns = preg_replace('/(\\\\[^\\\\]+)$/s', '', get_class($this));
            /* True: use the current namespace for errors.
             * It is nested namespace for the target namespace.
             * Truncate it.
             */
            if ($ns === 'axy\errors') {
                /* Trimming for axy\errors will result "axy". And it spreads to all axy-libs.
                 * Therefore, do not trim it.
                 * Return because axy\errors do not throws any exception.
                 * And return requires for TraceTruncateTest::testAxyNS()
                 */
                return null;
            }
            $ns = preg_replace('/(\\\\[^\\\\]+)$/s', '', $ns);
            $options = [
                'namespace' => $ns,
            ];
        } elseif (!is_array($options)) {
            $options = [
                'namespace' => $options,
            ];
        }
        return $options;
    }
951523
public function getExecOptionsResolver()
    {
        if (null === $this->execOptionsResolver) {
            if (null !== $this->parent) {
                $this->execOptionsResolver = clone $this->parent->getExecOptionsResolver();
            } else {
                $this->execOptionsResolver = new OptionsResolver();
            }

            $this->innerType->setExecOptions($this->execOptionsResolver);

            foreach ($this->typeExtensions as $extension) {
                $extension->setExecOptions($this->execOptionsResolver);
            }
        }

        return $this->execOptionsResolver;
    }
284293
protected function configureOptions(OptionsResolver $resolver)
    {
        $resolver->remove(['depth', 'parent_location_id', 'subtree']);
        $resolver->setRequired('location');
        $resolver->setAllowedTypes('location', SiteLocation::class);

        $resolver->setDefault('sort', function (Options $options) {
            /** @var \Netgen\EzPlatformSiteApi\API\Values\Location $location */
            $location = $options['location'];
            return $location->innerLocation->getSortClauses();
        });
    }
1301819
public function end($setter = null)
    {
        if (!count($this->stack)) {
            throw new \UnexpectedValueException("Stack is empty. Did you call end() too many times?");
        }
        $current = array_pop($this->stack);
        if ($parent = $this->current()) {
            $parentClassName = get_class($parent);
            $entityLocalName = Str::classname(get_class($current));

            if ($current instanceof $parentClassName) {
                if (method_exists($parent, 'addChildren')) {
                    call_user_func(array($parent, 'addChildren'), $current);
                }
            }
            if (is_null($setter)) {
                foreach (array('set', 'add') as $methodPrefix) {
                    $methodName = $methodPrefix . $entityLocalName;

                    if (method_exists($parent, $methodName)) {
                        $setter = $methodName;
                        break;
                    }
                }
            }
            if (!is_null($setter)) {
                call_user_func(array($parent, $setter), $current);
            }

            $parentClassNames = array_merge(class_parents($parentClassName), array($parentClassName));

            foreach (array_reverse($parentClassNames) as $lParentClassName) {
                $lParentClass = Str::classname($lParentClassName);
                $parentSetter = 'set' . $lParentClass;
                if ($lParentClassName == get_class($current)) {
                    $parentSetter = 'setParent';
                }
                if (method_exists($current, $parentSetter)) {
                    call_user_func(
                        array($current, $parentSetter),
                        $parent
                    );
                    break;
                }
            }
            foreach ($this->alwaysDo as $callable) {
                call_user_func($callable, $parent);
            }
        }
        foreach ($this->alwaysDo as $callable) {
            call_user_func($callable, $current);
        }
        return $this;
    }
619463
public static function wrap( \Throwable $throwable ): Helper\ThrowableInterface {

    switch( true ) {
      //
      case $throwable instanceof Helper\ThrowableInterface:
        return $throwable;

      //
      case $throwable instanceof \LogicException:
      case $throwable instanceof \Error:
        return new Exception\Logic( $throwable->getMessage(), Exception\Logic::ID, [], $throwable );

      //
      case $throwable instanceof \RuntimeException:
        return new Exception\Runtime( $throwable->getMessage(), Exception\Runtime::ID, [], $throwable );
    }

    return new static( $throwable->getMessage(), static::ID, [], $throwable );
  }
670511
public function setOptions(array $options = [], $reset = false)
    {
        return $this->setLength(current($options) ? (int) current($options) : 80)
                ->setEnding(next($options) !== false ? current($options) : '...')
                ->setBoundary(next($options) !== false ? true : false);
    }
162426
public function getCompactors()
    {
        $compactors = array();

        if (isset($this->raw->compactors)) {
            foreach ((array) $this->raw->compactors as $class) {
                if (false === class_exists($class)) {
                    throw new InvalidArgumentException(
                        sprintf(
                            'The compactor class "%s" does not exist.',
                            $class
                        )
                    );
                }

                $compactor = new $class();

                if (false === ($compactor instanceof CompactorInterface)) {
                    throw new InvalidArgumentException(
                        sprintf(
                            'The class "%s" is not a compactor class.',
                            $class
                        )
                    );
                }

                if ($compactor instanceof Php) {
                    if (!empty($this->raw->annotations)) {
                        $tokenizer = new Tokenizer();

                        if (isset($this->raw->annotations->ignore)) {
                            $tokenizer->ignore(
                                (array) $this->raw->annotations->ignore
                            );
                        }

                        $compactor->setTokenizer($tokenizer);
                    }
                }

                $compactors[] = $compactor;
            }
        }

        return $compactors;
    }
14789
public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $defaultConfigs = array();
        
        $resolver->setDefaults(array(
            'translation_domain' => 'ThraceFormBundle',
            'by_reference' => false,
            'configs' => $defaultConfigs,
        ));
        
        $resolver->setNormalizers(array(
            'configs' => function (Options $options, $value) use ($defaultConfigs){
                $configs = array_replace_recursive($defaultConfigs, $value);
                return $configs;
            }
        ));
          
        $resolver->setRequired(array('reference_class', 'inversed_class', 'inversed_property'));
    }
723705
public function doHandler(\Throwable $throwable)
    {
        $exceptionClass = get_class($throwable);
        $collector      = ExceptionHandlerCollector::getCollector();
        $isNotExistHandler = !isset($collector[$exceptionClass]) && !isset($collector[\Exception::class]);
        if (empty($collector) || $isNotExistHandler) {
            return $this->handleThrowtable($throwable);
        }

        if(isset($collector[$exceptionClass])){
            list($classBeanName, $methodName) = $collector[$exceptionClass];
        }else{
            list($classBeanName, $methodName) = $collector[\Exception::class];
        }

        $handler    = App::getBean($classBeanName);
        $bindParams = $this->getBindParams($classBeanName, $methodName, $throwable);
        $response   = PhpHelper::call([$handler, $methodName], $bindParams);
        if ($response instanceof ResponseInterface) {
            return $response;
        }

        throw new \Exception("the handler of exception must be return the object of response!");
    }
532003
private function fieldsOf(\Throwable $throwable = null): string
    {
        if (null === $throwable) {
            return '||||';
        }

        return '|' . get_class($throwable)
             . '|' . $throwable->getMessage()
             . '|' . $throwable->getFile()
             . '|' . $throwable->getLine();
    }
83074
protected function buildOptionParser(ConsoleOptionParser $parser)
    {
        $parser->setDescription(__d('link-scanner', 'Performs a complete scan'));

        return $parser->addOptions([
            'export' => [
                'boolean' => true,
                'default' => false,
                'help' => __d('link-scanner', 'Export results. The filename will be generated automatically'),
                'short' => 'e',
            ],
            'export-with-filename' => [
                'help' => __d('link-scanner', 'Export results. You must pass a relative or absolute path'),
            ],
            'follow-redirects' => [
                'boolean' => true,
                'default' => false,
                'help' => __d('link-scanner', 'Follows redirect'),
            ],
            'force' => [
                'boolean' => true,
                'default' => false,
                'help' => __d('link-scanner', 'Force mode: removes the lock file and does not ask questions'),
                'short' => 'f',
            ],
            'full-base-url' => [
                'help' => __d('link-scanner', 'Full base url. By default, the `{0}` value will be used', 'App.fullBaseUrl'),
            ],
            'max-depth' => [
                'help' => __d('link-scanner', 'Maximum depth of the scan. Default: {0}', $this->LinkScanner->getConfig('maxDepth')),
                'short' => 'd',
            ],
            'no-cache' => [
                'boolean' => true,
                'default' => false,
                'help' => __d('link-scanner', 'Disables the cache'),
            ],
            'no-external-links' => [
                'boolean' => true,
                'default' => false,
                'help' => __d('link-scanner', 'Disable the scanning of external links'),
            ],
            'timeout' => [
                'help' => __d('link-scanner', 'Timeout in seconds for GET requests. Default: {0}', $this->LinkScanner->Client->getConfig('timeout')),
                'short' => 't',
            ],
        ]);
    }
496193
public function truncate(array $options = [])
    {
        $response = $this->kuzzle->query(
            $this->buildQueryArgs('collection', 'truncate'),
            $this->kuzzle->addHeaders([], $this->headers),
            $options
        );

        return $response['result']['ids'];
    }
560166
function with(array $options, $throwException = false)
    {
        if ( empty($options) )
            # nothing to do
            return $options;

        if ( array_values($options) == $options )
            throw new \InvalidArgumentException(sprintf(
                'Setters Array must be associative array. given: %s'
                , var_export($options, true)
            ));


        // TODO use sort inside base foreach to achieve more performance
        if (isset($this->_t_configurable_setter_Priorities)
            && is_array($this->_t_configurable_setter_Priorities)
        ) {
            $sortQuee = $this->_t_configurable_setter_Priorities;
            uksort($options, function($a, $b) use ($sortQuee) {
                // sort array to reach setter priorities
                $ai = array_search($a, $sortQuee);
                $ai = ($ai !== false) ? $ai : 1000;

                $bi = array_search($b, $sortQuee);
                $bi = ($bi !== false) ? $bi : 1000;

                return $ai < $bi ? -1 : ($ai == $bi) ? 0 : 1;
            });
        }

        $remained = [];
        foreach($options as $key => $val) {
            foreach (['set', 'give'] as $prefix) {
                $setter = $prefix . StdString::of((string) $key)->PascalCase();
                // It can be public or protected methods
                // usually protected methods can be used as helper
                // to build class with options
                if ( method_exists($this, $setter) ) {
                    // check for methods
                    call_user_func([$this, $setter], $val);
                    break; // stop chain

                } elseif($throwException) {
                    throw new \InvalidArgumentException(sprintf(
                        'The option (%s) does not have a matching (%s) setter method on (%s).',
                        $key, $setter, get_class($this)
                    ));

                }
                else {
                    $remained[$key] = $val;
                }
            }
        }

        return $remained;
    }
845849
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'widget' => 'single_text',
                'widget_position' => 'right',
                'html5' => false,
                'locale' => $this->locale,
                'format' => null,
                'date_type' => \IntlDateFormatter::SHORT,
                'time_type' => \IntlDateFormatter::SHORT,
            ]
        );
        $resolver->setNormalizer(
            'format',
            function (Options $options, $value) {
                if (null !== $value) {
                    return $value;
                }
                $locale = $options['locale'] ?: 'en';
                $formatter = \IntlDateFormatter::create(
                    $locale,
                    $options['date_type'],
                    $options['time_type']
                );

                return $formatter->getPattern();
            }
        );
    }
1178534
private function configureStartControlProperties(OptionsResolver $resolver)
    {
        $resolver->setDefined('autostart')
            ->setAllowedTypes('autostart', 'bool');

        $resolver
            ->setDefined('autorestart')
            ->setAllowedTypes('autorestart', ['bool', 'string'])
            ->setAllowedValues('autorestart', [true, false, 'true', 'false', 'unexpected'])
            ->setNormalizer('autorestart', function (Options $options, $value) {
                return (is_bool($value) or $value === 'unexpected') ? $value : ($value === 'true' ? true : false);
            });

        $resolver->setDefined('startsecs')
            ->setAllowedTypes('startsecs', 'int');

        $resolver->setDefined('startretries')
            ->setAllowedTypes('startretries', 'int');
    }
232233
protected function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setRequired(
            [
                'family',
            ]
        );
        /** @noinspection PhpUnusedParameterInspection */
        $resolver->setNormalizer(
            'family',
            function (Options $options, $value) {
                if ($value instanceof FamilyInterface) {
                    return $value;
                }

                return $this->familyRegistry->getFamily($value);
            }
        );
        $resolver->setAllowedTypes('family', ['string', FamilyInterface::class]);
    }
1130185
function accessArray( $ignoreLimitIdentifier = false )
    {
        $limitations = $this->limitationList( true, $ignoreLimitIdentifier );
        if ( $this->Disabled === true )
        {
            return array();
        }

        if ( !$limitations )
        {
            return array( $this->attribute( 'module_name' ) => array ( $this->attribute( 'function_name' ) => array( '*' => '*' ) ) );
        }

        $limitArray = array();

        foreach( array_keys( $limitations ) as $limitKey )
        {
            $limitArray = array_merge_recursive( $limitArray, $limitations[$limitKey]->limitArray() );
        }

        $policyName = 'p_' . $this->attribute( 'id' ) . ( isset($this->UserRoleID) ? ( '_' . $this->UserRoleID ) : '' );

        return array( $this->attribute( 'module_name' ) => array ( $this->attribute( 'function_name' ) => array( $policyName => $limitArray ) ) );
    }