/**
  * Compares service providers found in files with the config service providers
  *
  * @return array
  */
 public function find($readCache = false)
 {
     $availableProviders = $this->inheritanceFinder->findExtends('\\Illuminate\\Support\\ServiceProvider');
     $usedProviders = \Config::get('app.providers');
     $assertedServiceProviders = $this->assortArrays($availableProviders, $usedProviders);
     if ($readCache === true) {
         $serviceProviderPath = \Config::get('providers.storage_path');
         $serviceProviderCachePath = $serviceProviderPath . '/service_provider.cache';
         if (!file_exists($serviceProviderPath) || !file_exists($serviceProviderCachePath)) {
             if (!file_exists($serviceProviderPath)) {
                 mkdir($serviceProviderPath, 0775, true);
             }
             file_put_contents($serviceProviderCachePath, serialize([]));
         }
         $cache = unserialize(file_get_contents($serviceProviderCachePath));
         if (!empty($cache['ignore'])) {
             foreach ($assertedServiceProviders['first_diff_second'] as $key => $serviceProvider) {
                 if (in_array($serviceProvider, $cache['ignore'])) {
                     unset($assertedServiceProviders['first_diff_second'][$key]);
                 }
             }
         }
     }
     return $assertedServiceProviders;
 }
Example #2
0
 public function getClasses($applicationRoot)
 {
     $result = ['excluded' => [], 'included' => [], 'all' => []];
     $classes = $this->inheritanceFinder->findImplements('Synga\\PhpStormMeta\\PhpStormMetaExtensionInterface');
     if (is_array($classes)) {
         foreach ($classes as $class) {
             $result['all'][] = $class->getFullQualifiedNamespace();
         }
     }
     $cachePath = $applicationRoot . '/.phpstorm.meta.cache';
     if (file_exists($cachePath)) {
         $result['excluded'] = unserialize(file_get_contents($cachePath));
     }
     $result['included'] = array_diff($result['all'], $result['excluded']);
     return $result;
 }
 public function exclude($applicationRoot)
 {
     $namespaces = [];
     $excludeArray = [];
     $classes = $this->inheritanceFinder->findImplements('\\Synga\\PhpStormMeta\\PhpStormMetaExtensionInterface');
     if (is_array($classes)) {
         $namespaces = [];
         foreach ($classes as $class) {
             $namespaces[] = $class->getFullQualifiedNamespace();
         }
     }
     $cachePath = $applicationRoot . '/.phpstorm.meta.cache';
     if (file_exists($cachePath)) {
         $excludeArray = unserialize(file_get_contents($cachePath));
     }
     $activeClasses = array_diff($namespaces, $excludeArray);
     $this->output->choice('Which class do you want to exclude?', $activeClasses, null, null, true);
 }
 /**
  * @param $applicationRoot
  */
 public function generate($applicationRoot)
 {
     $classes = $this->classSelector->getClasses($applicationRoot);
     $factory = new BuilderFactory();
     foreach ($classes['included'] as $class) {
         try {
             $class = $this->inheritanceFinder->findClass($class);
             /* @var $object \Synga\PhpStormMeta\PhpStormMetaExtensionInterface */
             $object = $this->resolver->resolve($class->getFullQualifiedNamespace());
             $object->execute($factory);
             $this->output->info('Class' . $class->getFullQualifiedNamespace() . ' added to .phpstorm.meta.php');
         } catch (\Exception $e) {
             $this->output->warn('Class ' . $class->getFullQualifiedNamespace() . ' could not be initiated.');
         }
     }
     $builder = $factory->getAndRemoveBuilder();
     file_put_contents($applicationRoot . '/.phpstorm.meta.php', $builder->build());
     $this->output->info('.phpstorm.meta.php file written in application root.');
 }