src/WordPress/Plugin.php
static function bootstrap($bootstrap)
  {
    $basepath = realpath(dirname($bootstrap));

    $fs = new Filesystem;

    $pluginSrcFile = $basepath.'/src/plugin.php';

    require_once $pluginSrcFile;
    
    $source = $fs->get($pluginSrcFile);
    
    $pluginClass = static::getFirstPluginClassName($source);
    
    // now check to see if we've been here before...
    if (!empty(static::$plugins[$pluginClass])) {
      return static::$plugins[$pluginClass];
    }

    // the plugin will have already been bootstrapped by
    // the time we get here IF the autoload file exists;
    // if it doesn't, setup a fallback class loader
    if (!file_exists($composer = $basepath.'/vendor/autoload.php')) {
      
      spl_autoload_register(function($name) use ($fs, $basepath) {

        $src = $basepath.'/src';
        $files = $fs->glob($src.'/**/*.php');
        
        static $classmap;

        // build the classmap
        if ($classmap === null) {
          $classmap = [];
          foreach($files as $file) {
            $contents = $fs->get($file);
            $namespace = '';
            if (preg_match('/namespace\s+(.*?);/i', $contents, $matches)) {
              $namespace = $matches[1];
            }
            if (preg_match_all('/class\s+([\w\_]+).*?{/i', $contents, $matches)) {
              foreach($matches[1] as $className) {
                $classmap["{$namespace}\\{$className}"] = $file;
              }
            }
          }
        }

        // if we found a match, load it
        if (!empty($classmap[$name])) {
          require_once $classmap[$name];
        }
      });

    }

    $plugin = new $pluginClass($bootstrap);

    static::$plugins[$pluginClass] = $plugin;
    static::$plugins[$plugin->getSlug()] = $plugin;
    
    return static::$plugins[$pluginClass];
  }
static function bootstrap($bootstrap)
  {
    $basepath = realpath(dirname($bootstrap));

    $fs = new Filesystem;

    $pluginSrcFile = $basepath.'/src/plugin.php';

    require_once $pluginSrcFile;
    
    $source = $fs->get($pluginSrcFile);
    
    $pluginClass = static::getFirstPluginClassName($source);
    
    // now check to see if we've been here before...
    if (!empty(static::$plugins[$pluginClass])) {
      return static::$plugins[$pluginClass];
    }

    // the plugin will have already been bootstrapped by
    // the time we get here IF the autoload file exists;
    // if it doesn't, setup a fallback class loader
    if (!file_exists($composer = $basepath.'/vendor/autoload.php')) {
      
      spl_autoload_register(function($name) use ($fs, $basepath) {

        $src = $basepath.'/src';
        $files = $fs->glob($src.'/**/*.php');
        
        static $classmap;

        // build the classmap
        if ($classmap === null) {
          $classmap = [];
          foreach($files as $file) {
            $contents = $fs->get($file);
            $namespace = '';
            if (preg_match('/namespace\s+(.*?);/i', $contents, $matches)) {
              $namespace = $matches[1];
            }
            if (preg_match_all('/class\s+([\w\_]+).*?{/i', $contents, $matches)) {
              foreach($matches[1] as $className) {
                $classmap["{$namespace}\\{$className}"] = $file;
              }
            }
          }
        }

        // if we found a match, load it
        if (!empty($classmap[$name])) {
          require_once $classmap[$name];
        }
      });

    }

    $plugin = new $pluginClass($bootstrap);

    static::$plugins[$pluginClass] = $plugin;
    static::$plugins[$plugin->getSlug()] = $plugin;
    
    return static::$plugins[$pluginClass];
  }
static function bootstrap ( $ bootstrap ) { $ basepath = realpath ( dirname ( $ bootstrap ) ) ; $ fs = new Filesystem ; $ pluginSrcFile = $ basepath . '/src/plugin.php' ; require_once $ pluginSrcFile ; $ source = $ fs -> get ( $ pluginSrcFile ) ; $ pluginClass = static :: getFirstPluginClassName ( $ source ) ; // now check to see if we've been here before... if ( ! empty ( static :: $ plugins [ $ pluginClass ] ) ) { return static :: $ plugins [ $ pluginClass ] ; } // the plugin will have already been bootstrapped by // the time we get here IF the autoload file exists; // if it doesn't, setup a fallback class loader if ( ! file_exists ( $ composer = $ basepath . '/vendor/autoload.php' ) ) { spl_autoload_register ( function ( $ name ) use ( $ fs , $ basepath ) { $ src = $ basepath . '/src' ; $ files = $ fs -> glob ( $ src . '/**/*.php' ) ; static $ classmap ; // build the classmap if ( $ classmap === null ) { $ classmap = [ ] ; foreach ( $ files as $ file ) { $ contents = $ fs -> get ( $ file ) ; $ namespace = '' ; if ( preg_match ( '/namespace\s+(.*?);/i' , $ contents , $ matches ) ) { $ namespace = $ matches [ 1 ] ; } if ( preg_match_all ( '/class\s+([\w\_]+).*?{/i' , $ contents , $ matches ) ) { foreach ( $ matches [ 1 ] as $ className ) { $ classmap [ "{$namespace}\\{$className}" ] = $ file ; } } } } // if we found a match, load it if ( ! empty ( $ classmap [ $ name ] ) ) { require_once $ classmap [ $ name ] ; } } ) ; } $ plugin = new $ pluginClass ( $ bootstrap ) ; static :: $ plugins [ $ pluginClass ] = $ plugin ; static :: $ plugins [ $ plugin -> getSlug ( ) ] = $ plugin ; return static :: $ plugins [ $ pluginClass ] ; }
Bootstrap a plugin found in the given bootstrap file.
@param string The full path to a Plugin's bootstrap file
@return Plugin
Bootstrap a plugin found in the given bootstrap file .