Exemple #1
0
 /**
  * Generate the data from the PHPDoc markup.
  *
  * @param string $path   Directory or file to scan for PHPDoc
  * @param string $format What format the data is returned in: [json|array].
  *
  * @return string|array
  */
 protected function _get_phpdoc_data($path, $format = 'json')
 {
     $output_cache_file = dirname(__DIR__) . '/cache-phpdoc.json';
     /**
      * Force delete last cache of phpdoc
      * Compare directory and WordPress Version for detecting
      */
     $delete_output_cache_file = false;
     $wp_parser_root_import_dir = get_option('wp_parser_root_import_dir', '');
     $directory_to_compare = wp_normalize_path(__DIR__);
     if (false !== strpos($wp_parser_root_import_dir, $directory_to_compare)) {
         $current_wp_version = get_bloginfo('version');
         $wp_parser_imported_wp_version = get_option('wp_parser_imported_wp_version', $current_wp_version);
         $delete_output_cache_file = $wp_parser_imported_wp_version != $current_wp_version;
     }
     /**
      * Delete last cache of phpdoc, true for deleting or false to skip
      *
      * Default: false or compare wordpress version see above
      */
     $delete_output_cache_file = apply_filters('sublime_delete_phpdoc_output_cache', $delete_output_cache_file);
     if ($delete_output_cache_file) {
         if (false !== stream_resolve_include_path($output_cache_file)) {
             unlink($output_cache_file);
         }
     }
     if (false !== stream_resolve_include_path($output_cache_file)) {
         if ($output = file_get_contents($output_cache_file)) {
             $output = 'json' == $format ? $output : json_decode($output, true);
         }
     } else {
         WP_CLI::line(sprintf('Extracting PHPDoc from %s. This may take a few minutes...', $path));
         $is_file = is_file($path);
         $files = $is_file ? array($path) : Importer::set_parser_phpdoc($path);
         $path = $is_file ? dirname($path) : $path;
         if ($files instanceof WP_Error) {
             WP_CLI::error(sprintf('Problem with %1$s: %2$s', $path, $files->get_error_message()));
             exit;
         }
         $output = Importer::get_parser_phpdoc($files, $path);
         /**
          * Generate cache file from phpdoc, true for generate or false to skip
          *
          * Default: true
          */
         if (apply_filters('sublime_create_phpdoc_output_cache', true)) {
             file_put_contents($output_cache_file, json_encode($output, JSON_PRETTY_PRINT));
         }
         if ('json' == $format) {
             $output = json_encode($output, JSON_PRETTY_PRINT);
         }
     }
     if ($helper_directory = realpath(dirname(__DIR__) . '/missing')) {
         $helpers = glob($helper_directory . '/*.php');
         if (is_array($helpers)) {
             $output = array_merge($output, Importer::get_parser_phpdoc($helpers, $helper_directory));
         }
     }
     return $output;
 }