예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function load($path)
 {
     $data = Yaml::parse($path);
     $storage = new Storage();
     if (!$data) {
         return $storage;
     }
     $types = array('alphabet' => Section::TYPE_ALPHABET, 'abugida' => Section::TYPE_ABUGIDA, 'syllabary' => Section::TYPE_SYLLABARY, 'abjad' => Section::TYPE_ABJAD, 'semisyllabary' => Section::TYPE_SEMISYLLABARY);
     foreach ($data as $sectionKey => $sectionInfo) {
         $languages = $sectionInfo['languages'];
         $type = $sectionInfo['type'];
         $diap = $sectionInfo['diap'];
         if (null === $languages) {
             $languages = array();
         }
         if ($type) {
             if (!isset($types[$type])) {
                 throw new \RuntimeException(sprintf('Undefined type "%s".', $type));
             }
             $type = $types[$type];
         }
         $section = new Section($sectionKey, $diap, $type, $languages);
         $storage->add($section);
     }
     return $storage;
 }
 /**
  * {@inheritDoc}
  */
 public function visit($string, array &$codes, Languages $languages)
 {
     foreach ($codes as $key => $code) {
         if ($code >= 32 && $code <= 47 || $code >= 58 && $code <= 64 || $code >= 91 && $code <= 96 || $code >= 123 && $code <= 127) {
             // This is a special char. Not detected.
             unset($codes[$key]);
             continue;
         }
         $section = $this->sections->findByCode($code);
         if ($section === null) {
             // Not found section for this char code
             continue;
         }
         if (count($section->getLanguages()) === 0) {
             // Not found languages for this char code.
             // This chan can is a special char (music, arrows, etc...)
             unset($codes[$key]);
         }
         $languages->addDetectedLanguages($section->getLanguages());
     }
 }