Create default detector

@param DictionaryInterface $dictionary

@return LanguageDetector
549225
public static function createDefault(DictionaryInterface $dictionary = null)
    {
        /** @var LanguageDetector $detector */
        $detector = new static();

        $dataDirectory = realpath(__DIR__ . '/../../../data');

        $alphabetLoader = new AlphabetLoader();
        $sectionLoader = new SectionLoader();

        $sections = $sectionLoader->load($dataDirectory . '/sections.yml');
        $alphabets = $alphabetLoader->load($dataDirectory . '/alphabets.yml');

        $detector
            ->addVisitor(new SectionVisitor($sections), -1024)
            ->addVisitor(new AlphabetVisitor($alphabets), -512);

        if ($dictionary) {
            $detector->addVisitor(new DictionaryVisitor($dictionary), -256);
        }

        return $detector;
    }
991175
public static function parser(ParserInterface $parser = null)
	{
		if($parser) {
			static::$parser = $parser;
		}
		elseif(!static::$parser) {
			static::$parser = new Annotation\KeyValuePairParser;
		}

		return static::$parser;
	}
609959
public function expected(AsserterInterface $asserter)
    {
        if (is_null($this->lastKey)) {
            throw new \BadMethodCallException();
        }

        $this->keys[$this->lastKey] = $asserter;

        return $this;
    }
1306777
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');

        if (isset($config['i18n']['default_locale'])) {
            Locale::setDefault($config['i18n']['default_locale']);
        }

        $locale = new Locale($this->findLocale());
        return $locale;
    }
1354311
private function detectFromHeader(ServerRequestInterface $request)
    {
        $accept = $request->getHeaderLine('Accept-Language');
        $language = $this->negotiateHeader($accept, new LanguageNegotiator(), $this->languages);

        if (empty($language)) {
            return isset($this->languages[0]) ? $this->languages[0] : '';
        }

        return $language;
    }
991801
public function registerDetector(DetectorInterface $spamDetector)
	{
		$detectorId = $this->classSimpleName($spamDetector);

		if (isset($this->detectors[$detectorId]))
		{
			throw new RuntimeException(
				sprintf('Spam Detector [%s] already registered', $detectorId)
			);
		}

		$this->detectors[$detectorId] = $spamDetector;

		return $this;
	}
355577
protected function parseLine(Dictionary $dictionary, string $line = null)
    {
        if (is_null($line)) {
            if ($this->type === 'Inteligenceω クイズ') {
                $output = $this->parseQuestionLine($dictionary, null);
            }
        } elseif ($line[0] !== '%') {
            // 空行でなければ
            if (is_null($this->type)) {
                // 辞書の種類が与えられてなければ
                $this->type = stripos($line, 'Q,') === 0 ? 'Inteligenceω クイズ' : 'Inteligenceω しりとり';
            }
            
            if ($this->type === 'Inteligenceω しりとり') {
                // しりとり辞書なら
                $output = $this->parseShiritoriLine($dictionary, $line);
            } elseif (stripos($line, 'Q,') === 0) {
                // 問題行なら
                $output = $this->parseQuestionLine($dictionary, $line);
            } elseif (stripos($line, 'A,') === 0) {
                // 解答行なら
                $this->parseAnswerLine($line);
            } else {
                throw new SyntaxException(_('壊れた行が含まれています:') . "\n" . $line);
            }
        }
        
        return $output ?? null;
    }
1266413
protected function getType($prefixedType, ContextInterface $context)
    {
        $defaultVocabulary = $context->getDefaultVocabulary();
        if ($defaultVocabulary && strpos($prefixedType, $defaultVocabulary->getUri()) === 0) {
            $prefixedType = substr($prefixedType, strlen($defaultVocabulary->getUri()));
        }
        return parent::getType($prefixedType, $context);
    }
903921
protected function getLanguageIdentifier($idLocale, DataSetInterface $dataSet)
    {
        foreach ($dataSet[AddLocalesStep::KEY_LOCALES] as $localeName => $localeId) {
            if ($idLocale === $localeId) {
                return mb_substr($localeName, 0, 2);
            }
        }

        throw new Exception(sprintf('Could not extract language identifier for idLocale "%s"', $idLocale));
    }
329959
protected function findOrCreateCategory(DataSetInterface $dataSet)
    {
        $categoryEntity = SpyCategoryQuery::create()
            ->filterByCategoryKey($dataSet[static::KEY_CATEGORY_KEY])
            ->findOneOrCreate();

        $categoryEntity->fromArray($dataSet->getArrayCopy());

        if (!empty($dataSet[static::KEY_TEMPLATE_NAME])) {
            $categoryTemplateEntity = $this->getCategoryTemplate($dataSet);
            $categoryEntity->setFkCategoryTemplate($categoryTemplateEntity->getIdCategoryTemplate());
        }

        if ($categoryEntity->isNew() || $categoryEntity->isModified()) {
            $categoryEntity->save();
        }

        return $categoryEntity;
    }
99337
protected function buildDetectOrder()
    {

        $detectOrder = [];

        foreach ($this->defaultDetectOrder as $i=>$charset) {
            if ($this->converter->canConvert($charset)) {
                $detectOrder[] = $charset;
            }
        }

        return $detectOrder;

    }
878075
public function setDefault(LanguageListener $listener, $id)
    {
        DB::beginTransaction();
        try {
            $current             = Languages::query()->where('is_default', 1)->firstOrFail();
            $current->is_default = 0;
            $current->save();

            $language             = Languages::query()->findOrFail($id);
            $language->is_default = 1;
            $language->save();
        } catch (Exception $ex) {
            DB::rollback();
            return $listener->defaultFailed($ex->getMessage());
        }
        DB::commit();
        return $listener->defaultSuccess();
    }
254631
protected function loadAdditionalDefinitions(ContainerInterface $container)
    {
        if (null !== $this->getFromDca('dca_config/data_provider')) {
            $dataContainerName = $container->getName();
            $this->getDispatcher()->addListener(
                PopulateEnvironmentEvent::NAME,
                function (PopulateEnvironmentEvent $event) use ($dataContainerName) {
                    $environment = $event->getEnvironment();
                    $definition  = $environment->getDataDefinition();
                    if ($definition->getName() !== $dataContainerName) {
                        return;
                    }

                    $parentName = $definition->getBasicDefinition()->getParentDataProvider();
                    if ($parentName) {
                        if ($parentName === $definition->getName()) {
                            $parentDefinition = $definition;
                        } else {
                            $parentDefinition = (new DcGeneralFactory())
                                ->setEventDispatcher($environment->getEventDispatcher())
                                ->setTranslator($environment->getTranslator())
                                ->setContainerName($parentName)
                                ->createDcGeneral()
                                ->getEnvironment()
                                ->getDataDefinition();
                        }
                        $environment->setParentDataDefinition($parentDefinition);
                    }

                    $rootName = $definition->getBasicDefinition()->getRootDataProvider();
                    if ($rootName) {
                        if ($rootName === $definition->getName()) {
                            $rootDefinition = $definition;
                        } else {
                            $rootDefinition = (new DcGeneralFactory())
                                ->setEventDispatcher($environment->getEventDispatcher())
                                ->setTranslator($environment->getTranslator())
                                ->setContainerName($rootName)
                                ->createDcGeneral()
                                ->getEnvironment()
                                ->getDataDefinition();
                        }

                        $environment->setRootDataDefinition($rootDefinition);
                    }
                }
            );
        }
    }
429688
public function getDispatcherFactory(ContainerInterface $container): DispatcherFactoryInterface
    {
        $autowired = $container->get('ellipse.dispatcher.autowiring.status');

        if ($autowired) {

            $interfaces = $container->get('ellipse.dispatcher.autowiring.interfaces');

            $container = new ReflectionContainer($container, $interfaces);

        }

        return new DefaultResolver($container);
    }
950228
public function setExceptionHandler(DiInterface $di)
  {
    //return $this;
    set_exception_handler(
      function ($exception) use ($di)
      {
        /** @var $exception Exception */

        // Handled exceptions
        if (is_a($exception, 'Phrest\API\\Exceptions\\HandledException'))
        {
          $response = new Response();

          $response->setStatusCode(
            $exception->getCode(),
            $exception->getMessage()
          );

          $response->addMessage(
            $exception->getMessage(),
            ResponseMessage::TYPE_WARNING
          );

          return (new JSONResponse($response))->send();
        }
        else
        {
          $response = new Response();

          $response->setStatusCode(500, 'Internal Server Error');

          $response->addMessage(
            'Internal Server Error',
            ResponseMessage::TYPE_WARNING
          );

          (new JSONResponse($response))->send();
        }

        // Log the exception
        error_log($exception);
        error_log($exception->getTraceAsString());

        return true;
      }
    );
  }
1245466
protected static function defaultCreateApi(ContainerInterface $container, string $class): CrudInterface
    {
        static::assertClassImplements($class, CrudInterface::class);

        /** @var FactoryInterface $factory */
        $factory = $container->get(FactoryInterface::class);
        $api     = $factory->createApi($class);

        return $api;
    }
1236256
public static function create(RequestInterface $request, ResponseInterface $response = null)
    {
        $uri = $request->getUri();

        if (is_null($response)) {
            return new static("No response error, uri: '$uri'");
        }

        // Extract error message from body
        $status = $response->getStatusCode();
        $json   = json_decode($response->getBody());
        if (json_last_error() !== JSON_ERROR_NONE) {
            return new static("KeyCDN API error ($status) on: '$uri'", $status);
        }

        // Error message
        if (isset($json->status, $json->description) && $json->status === 'error') {
            return new static($json->description . ", uri: '$uri'", $status);
        }

        // Unknown
        return new static("Unknown error, uri: '$uri'");

    }