Exemplo n.º 1
0
 /**
  * @return array
  * @throws CollectionExportWriteFailure
  * @throws DependencyInstanceNotFound
  */
 public static function makePhpStormMeta()
 {
     static::$instance ?: new static();
     // conveniences and declarations
     $app = static::$app;
     $self = static::$instance;
     $map = [];
     $code = '';
     // collect illuminate aliases
     $forge_aliases = static::getInstance()->aliases;
     /** @var PimpleDumpProvider $pds */
     $pds = static::find('pimple_dump_service');
     $pds->dump($app);
     // get Pimple keys and merge with aliases
     $keys = $app->keys();
     // fold in forge aliases that do not already exist in the $app.
     foreach ($forge_aliases as $abstract => $alias) {
         if (class_exists($abstract)) {
             isset($keys[$abstract]) ?: ($keys[] = "\\{$abstract}");
             $map[] = "'{$alias}' instanceof \\{$abstract},";
         }
     }
     // Iterate through the key list to collect registrations.
     foreach ($keys as $key) {
         // assume nothing
         $appKey = static::key_object_exists($key) ? $self->parseValue($app, $key) : self::parseKey($app, $key);
         // ignoring 'app' replications, add the new .phpstorm.meta entry.
         if ($appKey and $appKey !== '' and $key !== 'app') {
             $map[] = "'{$key}' instanceof \\{$appKey},";
         }
     }
     // sort and build code segment
     $map = array_unique($map);
     sort($map);
     // compile the map
     foreach ($map as $entry) {
         $code .= '            ' . $entry . PHP_EOL;
     }
     $template = file_get_contents(__DIR__ . '/assets/meta.php.template');
     $template = str_replace('%%MAP%%', $code, $template);
     $template = str_replace('%%DATE%%', Carbon::now()->toDateTimeString(), $template);
     $template = str_replace('%%COUNT%%', count($map), $template);
     $template = str_replace('%%ID%%', Lib::generate_token(8, '$meta$'), $template);
     if (FALSE === file_put_contents(ROOT . '.phpstorm.meta.php', $template)) {
         throw new CollectionExportWriteFailure('Unable to update .phpstorm.meta.php.');
     }
     return $map;
 }