/**
  * @param string $text
  * @return array
  */
 public static function analyse($text)
 {
     // to lowercase
     $text = mb_strtolower(trim($text), 'utf-8');
     // remove accents
     $text = Transliterator::unaccent($text);
     // considering very special chars as spaces
     $text = str_replace(array('@', '.', ',', '¿', '♠', '♣', '♥', '♦', '-', '+', '←', '↑', '→', '↓', "'", '’', '´', '●', '•', '¼', '½', '¾', '“', '”', '„', '°', '™', '©', '®', '³', '²'), ' ', $text);
     // remove multiple spaces
     $text = preg_replace('/\\s+/', ' ', $text);
     if ($text) {
         return explode(' ', $text);
     }
     return [];
 }
 /**
  * @dataProvider provideUnaccentCases
  */
 public function testUnaccent($input, $expected)
 {
     $this->assertSame($expected, Transliterator::unaccent($input));
 }
예제 #3
0
 /**
  * Generates a slug of the text after transliterating the UTF-8 string to ASCII.
  *
  * Unaccent umlauts/accents prior to transliteration.
  * Uses transliteration tables to convert any kind of utf8 character.
  *
  * @param string $text
  * @param string $separator
  *
  * @return string $text
  */
 public static function transliterate($text, $separator = '-')
 {
     $text = parent::unaccent($text);
     return parent::transliterate($text, $separator);
 }
예제 #4
0
 /**
  * Does not transliterate correctly eastern languages
  *
  * @param string $text
  * @param string $separator
  *
  * @return string
  */
 public static function urlize($text, $separator = '-', $excludeTwig = false)
 {
     $text = parent::unaccent($text);
     return self::postProcessText($text, $separator, $excludeTwig);
 }
 private function _refreshPackage(Package $package)
 {
     // Get latest info
     try {
         $packgist = new Packagist();
         $data = $packgist->package($package->author, $package->name);
     } catch (\Exception $e) {
         return null;
     }
     //print_r($data);exit;
     // Save package data
     $package->description = $data['description'];
     $package->downloads = $data['downloads']['total'];
     $package->downloads_m = $data['downloads']['monthly'];
     $package->downloads_d = $data['downloads']['daily'];
     $package->stars = $data['favers'];
     $package->type = $data['type'];
     $package->repo = $data['repository'];
     $package->domain = parse_url($data['repository'], PHP_URL_HOST);
     $package->save();
     // Maintainers
     $ids = [];
     foreach ($data['maintainers'] as $maintainer) {
         $model = Maintainer::firstOrCreate(['name' => $maintainer['name']]);
         $ids[] = $model->id;
     }
     $package->maintainers()->sync($ids);
     // Get the latets version
     usort($data['versions'], function ($a, $b) {
         $a = $a['time'];
         $b = $b['time'];
         if ($a == $b) {
             return 0;
         }
         return $a > $b ? -1 : 1;
     });
     if (isset($data['versions'][0])) {
         $data = $data['versions'][0];
         // Authors
         $ids = [];
         if (isset($data['authors'])) {
             foreach ($data['authors'] as $author) {
                 if (isset($author['email']) && $author['email']) {
                     $model = Author::firstOrNew(['email' => $author['email']]);
                     foreach ($author as $field => $value) {
                         if ($value) {
                             $value = Transliterator::unaccent($value);
                             $model->{$field} = $value;
                         }
                     }
                     $model->save();
                     $ids[] = $model->id;
                 }
             }
         }
         $package->authors()->sync($ids);
         // Tags
         $ids = [];
         if (isset($data['keywords'])) {
             foreach ($data['keywords'] as $tag) {
                 $model = Tag::firstOrCreate(['name' => $tag]);
                 $ids[] = $model->id;
             }
         }
         $package->tags()->sync($ids);
         // Dependencies
         $ids = [];
         if (isset($data['require'])) {
             foreach ($data['require'] as $fullNname => $version) {
                 $explode = explode('/', $fullNname, 2);
                 list($author, $name) = array_pad($explode, 2, '');
                 $model = Package::where('author', '=', $author)->where('name', '=', $name)->get()->first();
                 if ($model) {
                     $ids[$model->id] = ['version' => $version];
                 }
             }
         }
         $package->dependencies()->sync($ids);
     }
     // Mark as updated even if nothing changed.
     $package->touch();
     return $package;
 }