• herbert-dev

  • This is the framework, it is meant to be installed outside of the WP install via Composer.

    • app/

    • resources/

    • vendor/

    • getherbert/

    • framework/

    • bootstrap/

    • herbert/

    • autoload.php

    • helpers.php

    • API.php #API::

      The #API:: class uses #Exception::

    • Application.php #Application::

      Extends \Illuminate\Container\Container
      implements \Illuminate\Contracts\Foundation\Application
    • base/

    • models/

    • providers/

      • checks for / Defines HERBERT_AUTOLOAD to check if the framework is loaded (a form of singuarton pattern).
      • requires the helpers.php
      • runs Herbert\Framework\Application::getInstance()
      • loads all instances of herbert.config.php in wp the plugins directory
      • Uses:
        #getInstance()
        #boot()
    • <?php
      /**
       * Ensure this is only ran once.
       */
      if (defined('HERBERT_AUTOLOAD'))
      {
          return;
      }
      define('HERBERT_AUTOLOAD', microtime(true));
      @require 'helpers.php';
      /**
       * Load the WP plugin system.
       */
      if (array_search(ABSPATH . 'wp-admin/includes/plugin.php', get_included_files()) === false)
      {
          require_once ABSPATH . 'wp-admin/includes/plugin.php';
      }
      /**
       * Get Herbert.
       */
      $herbert = Herbert\Framework\Application::getInstance();
      /**
       * Load all herbert.php files in plugin roots.
       */
      $iterator = new DirectoryIterator(plugin_directory());
      foreach ($iterator as $directory)
      {
          if ( ! $directory->valid() || $directory->isDot() || ! $directory->isDir())
          {
              continue;
          }
          $root = $directory->getPath() . '/' . $directory->getFilename();
      if ( ! file_exists($root . '/herbert.config.php'))
      {
          continue;
      }
      $config = $herbert->getPluginConfig($root);
      $plugin = substr($root . '/plugin.php', strlen(plugin_directory()));
      $plugin = ltrim($plugin, '/');
      register_activation_hook($plugin, function () use ($herbert, $config, $root)
      {
          if ( ! $herbert->pluginMatches($config))
          {
              $herbert->pluginMismatched($root);
          }
          $herbert->pluginMatched($root);
          $herbert->loadPlugin($config);
          $herbert->activatePlugin($root);
      });
      register_deactivation_hook($plugin, function () use ($herbert, $root)
      {
          $herbert->deactivatePlugin($root);
      });
      // Ugly hack to make the install hook work correctly
      // as WP doesn't allow closures to be passed here
      register_uninstall_hook($plugin, create_function('', 'herbert()->deletePlugin(\'' . $root . '\');'));
      if ( ! is_plugin_active($plugin))
      {
          continue;
      }
      if ( ! $herbert->pluginMatches($config))
      {
          $herbert->pluginMismatched($root);
          continue;
      }
          $herbert->pluginMatched($root);
          @require_once $root.'/plugin.php';
          $herbert->loadPlugin($config);
      }
      /**
       * Boot Herbert.
       */
      $herbert->boot();
      • Checks for the existence of, and then loads a suite of helper functions.

      • There must be a concern that this file could be loaded twice, hence the checks. But if we are truly following a singleton pattern, then this shouldn’t matter.

      • These are being loaded at a global scope, and not in a helper class as public static functions - why not?

    • #dd()


      if ( ! function_exists('dd'))
      {
          /**
           * Dies and dumps.
           *
           * @return string
           */
          function dd()
          {
              call_user_func_array('dump', func_get_args());
      
              die;
          }
      }
    • #content_directory()


      if ( ! function_exists('content_directory'))
      {
          /**
           * Gets the content directory.
           *
           * @return string
           */
          function content_directory()
          {
              return WP_CONTENT_DIR;
          }
      }
    • #plugin_directory()


          if ( ! function_exists('plugin_directory'))
          {
              /**
               * Gets the plugin directory.
               *
               * @return string
               */
              function plugin_directory()
              {
                  return WP_PLUGIN_DIR;
              }
          }
    • #response() ($body, $status = 200, $headers = null)


      if ( ! function_exists('response'))
          {
              /**
               * Generates a response.
               *
               * @param  string  $body
               * @param  integer $status
               * @param  array   $headers
               * @return \Herbert\Framework\Response
               */
              function response($body, $status = 200, $headers = null)
              {
                  return new Herbert\Framework\Response($body, $status, $headers);
              }
          }
    • #json_response() ($jsonable, $status = 200, $headers = null)


          if ( ! function_exists('json_response'))
          {
              /**
               * Generates a json response.
               *
               * @param  mixed   $jsonable
               * @param  integer $status
               * @param  array   $headers
               * @return \Herbert\Framework\Response
               */
              function json_response($jsonable, $status = 200, $headers = null)
              {
                  return new Herbert\Framework\JsonResponse($jsonable, $status, $headers);
              }
          }
    • #json_response() ($jsonable, $status = 200, $headers = null)


      if ( ! function_exists('json_response'))
      {
          /**
           * Generates a json response.
           *
           * @param  mixed   $jsonable
           * @param  integer $status
           * @param  array   $headers
           * @return \Herbert\Framework\Response
           */
          function json_response($jsonable, $status = 200, $headers = null)
          {
              return new Herbert\Framework\JsonResponse($jsonable, $status, $headers);
          }
      }
    • #redirect_response() ($url, $status = 302, $headers = null)


          if ( ! function_exists('redirect_response'))
          {
              /**
               * Generates a redirect response.
               *
               * @param  string  $url
               * @param  integer $status
               * @param  array   $headers
               * @return \Herbert\Framework\Response
               */
              function redirect_response($url, $status = 302, $headers = null)
              {
                  return new Herbert\Framework\RedirectResponse($url, $status, $headers);
              }
          }
    • #herbert() ($binding = null)


      if ( ! function_exists('herbert'))
          {
              /**
               * Gets the herbert container.
               *
               * @param  string $binding
               * @return string
               */
              function herbert($binding = null)
              {
                  $instance = Herbert\Framework\Application::getInstance();
      
                  if ( ! $binding)
                  {
                      return $instance;
                  }
      
                  return $instance[$binding];
              }
          }
    • #errors() ($key = null)


       if ( ! function_exists('errors'))
          {
              /**
               * Get the errors.
               *
               * @param string key
               * @return array
               */
              function errors($key = null)
              {
                  $errors = herbert('errors');
                  $errors = isset($errors[0]) ? $errors[0] : $errors;
      
                  if (!$key)
                  {
                      return $errors;
                  }
      
                  return array_get($errors, $key);
              }
          }
    • #session() ($key = null, $default = null)


      if ( ! function_exists('session'))
          {
              /**
               * Gets the session or a key from the session.
               *
               * @param  string $key
               * @param  mixed  $default
               * @return \Illuminate\Session\Store|mixed
               */
              function session($key = null, $default = null)
              {
                  if ($key === null)
                  {
                      return herbert('session');
                  }
      
                  return herbert('session')->get($key, $default);
              }
          }
    • #session_flashed() ($key = null, $default = [])


      if ( ! function_exists('session_flashed'))
          {
              /**
               * Gets the session flashbag or a key from the session flashbag.
               *
               * @param  string $key
               * @param  mixed  $default
               * @return \Illuminate\Session\Store|mixed
               */
              function session_flashed($key = null, $default = [])
              {
                  if ($key === null)
                  {
                      return herbert('session')->getFlashBag();
                  }
      
                  return herbert('session')->getFlashBag()->get($key, $default);
              }
          }
    • #view() ($name, $context = [])


          if ( ! function_exists('view'))
          {
              /**
               * Renders a twig view.
               *
               * @param  string $name
               * @param  array  $context
               * @return string
               */
              function view($name, $context = [])
              {
                  return response(herbert('Twig_Environment')->render($name, $context));
              }
          }
    • #panel_url() ($name, $query = [])


          if ( ! function_exists('panel_url'))
          {
              /**
               * Gets the url to a panel.
               *
               * @param  string $name
               * @param  array  $query
               * @return string
               */
              function panel_url($name, $query = [])
              {
                  return add_query_arg($query, herbert('panel')->url($name));
              }
          }
    • #route_url() ($name, $args = [], $query = [])


      if ( ! function_exists('route_url'))
          {
              /**
               * Gets the url to a route.
               *
               * @param  string $name
               * @param  array  $args
               * @param  array  $query
               * @return string
               */
              function route_url($name, $args = [], $query = [])
              {
                  return add_query_arg($query, herbert('router')->url($name, $args));
              }
          }
    •     <?php namespace Herbert\Framework;
      
          use Exception;
      
          /**
           * @see http://getherbert.com
           */
          class API {
      
              /**
               * @var array
               */
              protected $methods = [];
      
              /**
               * @var \Herbert\Framework\Application
               */
              protected $app;
      
              /**
               * @param \Herbert\Framework\Application $app
               */
              public function __construct(Application $app)
              {
                  $this->app = $app;
              }
      
              /**
               * Add a method.
               *
               * @param $method
               * @param $fn
               */
              public function add($method, $fn)
              {
                  $this->methods[$method] = $fn;
              }
      
              /**
               * Gets a method.
               *
               * @param  string $method
               * @return Callable
               */
              public function get($method)
              {
                  return array_get($this->methods, $method);
              }
      
              /**
               * Magic call from the function collection.
               *
               * @param $method
               * @param $params
               * @return mixed
               * @throws \WP_Error
               */
              public function __call($method, $params)
              {
                  if ( ! isset($this->methods[$method]))
                  {
                      throw new Exception("Method '{$method}' not set!");
                  }
      
                  return $this->app->call(
                      $this->methods[$method], $params
                  );
              }
      
          }
    • #Application:: #__construct#


      public function __construct()
          {
              static::$instance = $this;
      
              $this->version = new SemVersion(self::VERSION);
      
              $this->instance('app', $this);
              $this->instance('Illuminate\Container\Container', $this);
      
              $this->registerBaseProviders();
              $this->registerCoreContainerAliases();
              $this->registerConfiguredProviders();
          }
    • #Application:: #basePath()


      /**
           *  Added to satisfy interface
           *
           *  @return string
           */
          public function basePath()
          {
              return content_directory() . '/herbert-cache';
          }
    • #Application:: #getPlugins()


      /**
           * Get all loaded plugins.
           *
           * @return array
           */
          public function getPlugins()
          {
              return $this->plugins;
          }
    • #Application:: #getPlugins()


       /**
          * Gets a plugin's configuration.
          *
          * @param  string $root
          * @return array
          */
          public function getPluginConfig($root)
          {
              if ( ! isset($this->configurations[$root]))
              {
                  $this->configurations[$root] = @require_once "$root/herbert.config.php" ?: [];
              }
      
              return $this->configurations[$root];
          }
    • #Application:: #getPluginConfig() ($root)


       /**
         * Gets a plugin's configuration.
         *
         * @param  string $root        
         * @return array
         */
          public function getPluginConfig($root)
          {
              if ( ! isset($this->configurations[$root]))
              {
                  $this->configurations[$root] = @require_once "$root/herbert.config.php" ?: [];
              }
      
              return $this->configurations[$root];
          }
    • #Application:: #pluginMatches() ($config)


          /**
           * Checks if a plugin version is matches.
           *
           * @param  array $config
           * @return bool
           */
          public function pluginMatches($config)
          {
              $constraint = array_get($config, 'constraint', self::VERSION);
      
              return $this->version->satisfies(new SemVersionExpression($constraint));
          }
    • #Application:: #pluginMismatched() ($root)


          /**
           * Logs a plugin as incompatible.
           *
           * @param  string $root
           * @return void
           */
          public function pluginMismatched($root)
          {
              $this->mismatched[] = $root;
          }
    • #Application:: #pluginMatched() ($root)


          /**
           * Logs a plugin as compatible.
           *
           * @param  string $root
           * @return void
           */
          public function pluginMatched($root)
          {
              $this->matched[] = $root;
          }
    • #Application:: #notifyMismatched()


          /**
           * Notifies the user of mismatched plugins.
           *
           * @return void
           */
          protected function notifyMismatched()
          {
              $matched = array_map(function ($value)
              {
                  return basename($value);
              }, $this->matched);
      
              $mismatched = array_map(function ($value)
              {
                  return basename($value);
              }, $this->mismatched);
      
              $message = 'Unfortunately plugin(s) '
                      . implode(', ', $mismatched)
                      . ' can’t work with the following plugin(s) '
                      . implode(', ', $matched)
                      . '. Please disable and try updating all of the above plugins before reactivating.';
      
              Notifier::error($message);
          }
    • #Application:: #loadPlugin() ($config)


         /**
           * Loads a plugin.
           *
           * @param  array $config
           * @return void
           */
          public function loadPlugin($config)
          {
              $this->loadPluginRequires(
                  array_get($config, 'requires', [])
              );
      
              $this->loadPluginRoutes(
                  'router',
                  array_get($config, 'routes', [])
              );
      
              $this->loadPluginPanels(
                  'panel',
                  array_get($config, 'panels', [])
              );
      
              $this->loadPluginX(
                  'enqueue',
                  array_get($config, 'enqueue', [])
              );
      
              $this->loadPluginX(
                  'shortcode',
                  array_get($config, 'shortcodes', [])
              );
      
              $this->loadPluginX(
                  'widget',
                  array_get($config, 'widgets', [])
              );
      
              $this->loadPluginAPIs(
                  array_get($config, 'apis', [])
              );
      
              $this->addPluginTwigNamespaces(
                  array_get($config, 'views', [])
              );
      
              $this->addPluginViewGlobals(
                  array_get($config, 'viewGlobals', [])
              );
      
              $this->addPluginComposers(
                  array_get($config, 'viewComposers', [])
              );
          }
    • #Application:: #loadPluginRequires() ($requires = [])


        /**
           * Load all a plugin's requires.
           *
           * @param array $requires
           * @return void
           */
          protected function loadPluginRequires($requires = [])
          {
              $container = $this;
      
              foreach ($requires as $require)
              {
                  @require_once "$require";
              }
          }
    • #Application::

          <?php namespace Herbert\Framework;
      
          use Illuminate\Support\ServiceProvider;
          use vierbergenlars\SemVer\version as SemVersion;
          use vierbergenlars\SemVer\expression as SemVersionExpression;
          use Illuminate\Database\Capsule\Manager as CapsuleManager;
          use Illuminate\Database\Schema\Blueprint as SchemaBlueprint;
      
          /**
           * @see http://getherbert.com
           */
          class Application extends \Illuminate\Container\Container implements \Illuminate\Contracts\Foundation\Application {
      
              /**
               * The application's version.
               */
              const VERSION = '0.9.13';
      
              /**
               * The application's version.
               *
               * @var \vierbergenlars\SemVer\version
               */
              protected $version;
      
              /**
               * @var \Herbert\Framework\Application
               */
              protected static $instance;
      
              /**
               * Indicates if the application has "booted".
               *
               * @var bool
               */
              protected $booted = false;
      
              /**
               * The array of booting callbacks.
               *
               * @var array
               */
              protected $bootingCallbacks = array();
      
              /**
               * The array of booted callbacks.
               *
               * @var array
               */
              protected $bootedCallbacks = array();
      
              /**
               * The array of terminating callbacks.
               *
               * @var array
               */
              protected $terminatingCallbacks = array();
      
              /**
               * All of the registered service providers.
               *
               * @var array
               */
              protected $serviceProviders = array();
      
              /**
               * The names of the loaded service providers.
               *
               * @var array
               */
              protected $loadedProviders = array();
      
              /**
               * The deferred services and their providers.
               *
               * @var array
               */
              protected $deferredServices = array();
      
              /**
               * The registered plugins.
               *
               * @var array
               */
              protected $plugins = [];
      
              /**
               * The mismatched plugins.
               *
               * @var array
               */
              protected $mismatched = [];
      
              /**
               * The matched plugins.
               *
               * @var array
               */
              protected $matched = [];
      
              /**
               * The plugin apis.
               *
               * @var array
               */
              protected $apis = [];
      
              /**
               * The plugin configurations.
               *
               * @var array
               */
              protected $configurations = [];
      
              /**
               * The view composers.
               *
               * @var array
               */
              protected $viewComposers = [];
      
              /**
               * The view globals.
               *
               * @var array
               */
              protected $viewGlobals = [];
      
              /**
               * The built view globals.
               *
               * @var array
               */
              protected $builtViewGlobals = null;
      
              /**
               * Constructs the application and ensures it's correctly setup.
               */
              public function __construct()
              {
                  static::$instance = $this;
      
                  $this->version = new SemVersion(self::VERSION);
      
                  $this->instance('app', $this);
                  $this->instance('Illuminate\Container\Container', $this);
      
                  $this->registerBaseProviders();
                  $this->registerCoreContainerAliases();
                  $this->registerConfiguredProviders();
              }
      
              /**
               *  Added to satisfy interface
               *
               *  @return string
               */
              public function basePath()
              {
                  return content_directory() . '/herbert-cache';
              }
      
              /**
               * Get all loaded plugins.
               *
               * @return array
               */
              public function getPlugins()
              {
                  return $this->plugins;
              }
      
              /**
               * Gets a plugin's configuration.
               *
               * @param  string $root
               * @return array
               */
              public function getPluginConfig($root)
              {
                  if ( ! isset($this->configurations[$root]))
                  {
                      $this->configurations[$root] = @require_once "$root/herbert.config.php" ?: [];
                  }
      
                  return $this->configurations[$root];
              }
      
              /**
               * Checks if a plugin version is matches.
               *
               * @param  array $config
               * @return bool
               */
              public function pluginMatches($config)
              {
                  $constraint = array_get($config, 'constraint', self::VERSION);
      
                  return $this->version->satisfies(new SemVersionExpression($constraint));
              }
      
              /**
               * Logs a plugin as incompatable.
               *
               * @param  string $root
               * @return void
               */
              public function pluginMismatched($root)
              {
                  $this->mismatched[] = $root;
              }
      
              /**
               * Logs a plugin as compatable.
               *
               * @param  string $root
               * @return void
               */
              public function pluginMatched($root)
              {
                  $this->matched[] = $root;
              }
      
              /**
               * Notifies the user of mismatched plugins.
               *
               * @return void
               */
              protected function notifyMismatched()
              {
                  $matched = array_map(function ($value)
                  {
                      return basename($value);
                  }, $this->matched);
      
                  $mismatched = array_map(function ($value)
                  {
                      return basename($value);
                  }, $this->mismatched);
      
                  $message = 'Unfortunately plugin(s) '
                          . implode(', ', $mismatched)
                          . ' can’t work with the following plugin(s) '
                          . implode(', ', $matched)
                          . '. Please disable and try updating all of the above plugins before reactivating.';
      
                  Notifier::error($message);
              }
      
              /**
               * Loads a plugin.
               *
               * @param  array $config
               * @return void
               */
              public function loadPlugin($config)
              {
                  $this->loadPluginRequires(
                      array_get($config, 'requires', [])
                  );
      
                  $this->loadPluginRoutes(
                      'router',
                      array_get($config, 'routes', [])
                  );
      
                  $this->loadPluginPanels(
                      'panel',
                      array_get($config, 'panels', [])
                  );
      
                  $this->loadPluginX(
                      'enqueue',
                      array_get($config, 'enqueue', [])
                  );
      
                  $this->loadPluginX(
                      'shortcode',
                      array_get($config, 'shortcodes', [])
                  );
      
                  $this->loadPluginX(
                      'widget',
                      array_get($config, 'widgets', [])
                  );
      
                  $this->loadPluginAPIs(
                      array_get($config, 'apis', [])
                  );
      
                  $this->addPluginTwigNamespaces(
                      array_get($config, 'views', [])
                  );
      
                  $this->addPluginViewGlobals(
                      array_get($config, 'viewGlobals', [])
                  );
      
                  $this->addPluginComposers(
                      array_get($config, 'viewComposers', [])
                  );
              }
      
              /**
               * Load all a plugin's requires.
               *
               * @param array $requires
               * @return void
               */
              protected function loadPluginRequires($requires = [])
              {
                  $container = $this;
      
                  foreach ($requires as $require)
                  {
                      @require_once "$require";
                  }
              }
      
              /**
               * Load all a plugin's routes.
               *
               * @param array $routes
               * @return void
               */
              protected function loadPluginRoutes($x, $routes = [])
              {
                  $container = $this;
                  $router = $this['router'];
      
                  foreach ($routes as $namespace => $requires)
                  {
                      $router->setNamespace($namespace);
      
                      foreach ((array) $requires as $require)
                      {
                          @require_once "$require";
                      }
      
                      $router->unsetNamespace();
                  }
              }
      
              /**
               * Load all a plugin's panels.
               *
               * @param array $panels
               * @return void
               */
              protected function loadPluginPanels($x, $panels = [])
              {
                  $container = $this;
                  $panel = $this['panel'];
      
                  foreach ($panels as $namespace => $requires)
                  {
                      $panel->setNamespace($namespace);
      
                      foreach ((array) $requires as $require)
                      {
                          @require_once "$require";
                      }
      
                      $panel->unsetNamespace();
                  }
              }
      
              /**
               * Load all a plugin's :x.
               *
               * @param array $requires
               * @return void
               */
              protected function loadPluginX($x, $requires = [])
              {
                  $container = $this;
                  $$x = $this[$x];
      
                  foreach ($requires as $require)
                  {
                      @require_once "$require";
                  }
              }
      
              /**
               * Add all a plugin's twig namespaces.
               *
               * @param array $namespaces
               * @return void
               */
              protected function addPluginTwigNamespaces($namespaces = [])
              {
                  $loader = $this['twig.loader'];
      
                  foreach ($namespaces as $namespace => $paths)
                  {
                      foreach ((array) $paths as $path)
                      {
                          $loader->addPath($path, $namespace);
                      }
                  }
              }
      
              /**
               * Add all a plugin's view globals.
               *
               * @param array $globals
               * @return void
               */
              protected function addPluginViewGlobals($globals = [])
              {
                  foreach ($globals as $key => $_globals)
                  {
                      if (is_numeric($key))
                      {
                          $key = null;
                      }
      
                      $this->viewGlobals[] = [$key, $_globals];
                  }
      
                  $this->builtViewGlobals = null;
              }
      
              /**
               * Add all a plugin's view composers.
               *
               * @param array $composers
               * @return void
               */
              protected function addPluginComposers($composers = [])
              {
                  foreach ($composers as $match => $_composers)
                  {
                      $this->viewComposers[] = [$match, (array) $_composers];
                  }
              }
      
              /**
               * Load the plugin's apis.
               *
               * @param array $requires
               * @return void
               */
              protected function loadPluginAPIs($requires = [])
              {
                  $container = $this;
      
                  foreach ($requires as $name => $require)
                  {
                      global $$name;
                      $api = $$name = new API($this);
                      $this->apis[] = [$name, $api];
      
                      require "$require";
                  }
              }
      
              /**
               * Register a plugin.
               *
               * @param \Herbert\Framework\Plugin $plugin
               */
              public function registerPlugin(Plugin $plugin)
              {
                  $plugin->setContainer($this);
      
                  $this->plugins[] = $plugin;
      
                  $this->registerPluginProviders($plugin);
                  $this->registerPluginAliases($plugin);
              }
      
              /**
               * Deactivates a plugin.
               *
               * @see register_activation_hook()
               * @param $root
               */
              public function activatePlugin($root)
              {
                  $plugins = array_filter($this->plugins, function (Plugin $plugin) use ($root)
                  {
                      return $plugin->getBasePath() === $root;
                  });
      
                  foreach ($plugins as $plugin)
                  {
                      $plugin->activate();
                  }
      
                  $config = $this->getPluginConfig($root);
      
                  foreach (array_get($config, 'tables', []) as $table => $class)
                  {
                      if ( ! class_exists($class))
                      {
                          continue;
                      }
      
                      if (CapsuleManager::schema()->hasTable($table))
                      {
                          continue;
                      }
      
                      CapsuleManager::schema()->create($table, function (SchemaBlueprint $table) use ($class)
                      {
                          $this->call($class . '@activate', ['table' => $table, 'app' => $this]);
                      });
                  }
      
                  foreach (array_get($config, 'activators', []) as $activator)
                  {
                      if ( ! file_exists($activator))
                      {
                          continue;
                      }
      
                      $this->loadWith($activator, [
                          'http',
                          'router',
                          'enqueue',
                          'panel',
                          'shortcode',
                          'widget'
                      ]);
                  }
              }
      
              /**
               * Deactivates a plugin.
               *
               * @see register_deactivation_hook()
               * @param $root
               */
              public function deactivatePlugin($root)
              {
                  $plugins = array_filter($this->plugins, function (Plugin $plugin) use ($root)
                  {
                      return $plugin->getBasePath() === $root;
                  });
      
                  foreach ($plugins as $plugin)
                  {
                      $plugin->deactivate();
                  }
      
                  $config = $this->getPluginConfig($root);
      
                  foreach (array_get($config, 'deactivators', []) as $deactivator)
                  {
                      if ( ! file_exists($deactivator))
                      {
                          continue;
                      }
      
                      $this->loadWith($deactivator, [
                          'http',
                          'router',
                          'enqueue',
                          'panel',
                          'shortcode',
                          'widget'
                      ]);
                  }
      
                  foreach (array_get($config, 'tables', []) as $table => $class)
                  {
                      if ( ! class_exists($class))
                      {
                          continue;
                      }
      
                      if ( ! CapsuleManager::schema()->hasTable($table))
                      {
                          continue;
                      }
      
                      CapsuleManager::schema()->table($table, function (SchemaBlueprint $table) use ($class)
                      {
                          $this->call($class . '@deactivate', ['table' => $table, 'app' => $this]);
                      });
                  }
              }
      
              /**
               * Deletes a plugin.
               *
               * @see register_uninstall_hook
               * @param $root
               */
              public function deletePlugin($root)
              {
                  $plugins = array_filter($this->plugins, function (Plugin $plugin) use ($root)
                  {
                      return $plugin->getBasePath() === $root;
                  });
      
                  foreach ($plugins as $plugin)
                  {
                      if ( ! method_exists($plugin, 'delete'))
                      {
                          continue;
                      }
      
                      $plugin->deactivate();
                  }
      
                  $config = $this->getPluginConfig($root);
      
                  foreach (array_get($config, 'deleters', []) as $deleter)
                  {
                      if ( ! file_exists($deleter))
                      {
                          continue;
                      }
      
                      $this->loadWith($deleter, [
                          'http',
                          'router',
                          'enqueue',
                          'panel',
                          'shortcode',
                          'widget'
                      ]);
                  }
      
                  foreach (array_get($config, 'tables', []) as $table => $class)
                  {
                      if ( ! class_exists($class))
                      {
                          continue;
                      }
      
                      if ( ! CapsuleManager::schema()->hasTable($table))
                      {
                          continue;
                      }
      
                      CapsuleManager::schema()->table($table, function (SchemaBlueprint $table) use ($class)
                      {
                          $this->call($class . '@delete', ['table' => $table, 'app' => $this]);
                      });
                  }
              }
      
              /**
               * Loads a file with variables in scope.
               *
               * @param  string $file
               * @param  array  $refs
               * @return void
               */
              protected function loadWith($file, $refs = [])
              {
                  $container = $this;
      
                  foreach ($refs as $ref)
                  {
                      $$ref = $this[$ref];
                  }
      
                  @require $file;
              }
      
              /**
               * Register all of the plugin's providers.
               *
               * @param \Herbert\Framework\Plugin $plugin
               * @return void
               */
              protected function registerPluginProviders(Plugin $plugin)
              {
                  $providers = array_get($plugin->getConfig(), 'providers', []);
      
                  foreach ($providers as $provider)
                  {
                      $this->register(
                          $this->resolveProviderClass($provider)
                      );
                  }
              }
      
              /**
               * Register all of the plugin's aliases.
               *
               * @param \Herbert\Framework\Plugin $plugin
               * @return void
               */
              protected function registerPluginAliases(Plugin $plugin)
              {
                  $aliases = array_get($plugin->getConfig(), 'aliases', []);
      
                  foreach ($aliases as $key => $aliases)
                  {
                      foreach ((array) $aliases as $alias)
                      {
                          $this->alias($key, $alias);
                      }
                  }
              }
      
          //    /**
          //     * Register the plugin's configured requires.
          //     *
          //     * @param \Herbert\Framework\Plugin $plugin
          //     */
          //    protected function registerPluginRequires(Plugin $plugin)
          //    {
          //        $requires = array_get($plugin->getConfig(), 'requires', []);
          //        $container = $this;
          //
          //        foreach ($requires as $require)
          //        {
          //            require "$require";
          //        }
          //    }
      
          //    /**
          //     * Register the plugin's configured routes.
          //     *
          //     * @param \Herbert\Framework\Plugin $plugin
          //     */
          //    protected function registerPluginRoutes(Plugin $plugin)
          //    {
          //        $requires = array_get($plugin->getConfig(), 'routes', []);
          //        $router = $this['router'];
          //
          //        foreach ($requires as $require)
          //        {
          //            require "$require";
          //        }
          //    }
      
          //    /**
          //     * Register the plugin's configured shortcodes.
          //     *
          //     * @param \Herbert\Framework\Plugin $plugin
          //     */
          //    protected function registerPluginShortcodes(Plugin $plugin)
          //    {
          //        $requires = array_get($plugin->getConfig(), 'shortcodes', []);
          //        $shortcode = $this['shortcode'];
          //
          //        foreach ($requires as $require)
          //        {
          //            require "$require";
          //        }
          //    }
      
              /**
               * Register the base providers.
               *
               * @return void
               */
              protected function registerBaseProviders()
              {
                  $this->register($this->resolveProviderClass(
                      'Herbert\Framework\Providers\HerbertServiceProvider'
                  ));
      
                  $this->register($this->resolveProviderClass(
                      'Herbert\Framework\Providers\TwigServiceProvider'
                  ));
              }
      
              /**
               * Register the core aliases.
               *
               * @return void
               */
              protected function registerCoreContainerAliases()
              {
                  $aliases = [
                      'app' => [
                          'Illuminate\Foundation\Application',
                          'Illuminate\Contracts\Container\Container',
                          'Illuminate\Contracts\Foundation\Application'
                      ]
                  ];
      
                  foreach ($aliases as $key => $aliases)
                  {
                      foreach ((array) $aliases as $alias)
                      {
                          $this->alias($key, $alias);
                      }
                  }
              }
      
              /**
               * Register all of the configured providers.
               *
               * @todo
               * @return void
               */
              public function registerConfiguredProviders()
              {
                  //
              }
      
              /**
               * Register a service provider with the application.
               *
               * @param  \Illuminate\Support\ServiceProvider|string $provider
               * @param  array                                      $options
               * @param  bool                                       $force
               * @return \Illuminate\Support\ServiceProvider
               */
              public function register($provider, $options = array(), $force = false)
              {
                  if ($registered = $this->getProvider($provider) && ! $force)
                  {
                      return $registered;
                  }
      
                  // If the given "provider" is a string, we will resolve it, passing in the
                  // application instance automatically for the developer. This is simply
                  // a more convenient way of specifying your service provider classes.
                  if (is_string($provider))
                  {
                      $provider = $this->resolveProviderClass($provider);
                  }
      
                  $provider->register();
      
                  // Once we have registered the service we will iterate through the options
                  // and set each of them on the application so they will be available on
                  // the actual loading of the service objects and for developer usage.
                  foreach ($options as $key => $value)
                  {
                      $this[$key] = $value;
                  }
      
                  $this->markAsRegistered($provider);
      
                  // If the application has already booted, we will call this boot method on
                  // the provider class so it has an opportunity to do its boot logic and
                  // will be ready for any usage by the developer's application logics.
                  if ($this->booted)
                  {
                      $this->bootProvider($provider);
                  }
      
                  return $provider;
              }
      
      
              /**
               * Get the registered service provider instance if it exists.
               *
               * @param  \Illuminate\Support\ServiceProvider|string  $provider
               * @return \Illuminate\Support\ServiceProvider|null
               */
              public function getProvider($provider)
              {
                  $name = is_string($provider) ? $provider : get_class($provider);
      
                  return array_first($this->serviceProviders, function($key, $value) use ($name)
                  {
                      return $value instanceof $name;
                  });
              }
      
              /**
               * Resolve a service provider instance from the class name.
               *
               * @param  string  $provider
               * @return \Illuminate\Support\ServiceProvider
               */
              public function resolveProviderClass($provider)
              {
                  return $this->make($provider, ['app' => $this]);
              }
      
              /**
               * Mark the given provider as registered.
               *
               * @param  \Illuminate\Support\ServiceProvider
               * @return void
               */
              protected function markAsRegistered($provider)
              {
                  $this->serviceProviders[] = $provider;
      
                  $this->loadedProviders[get_class($provider)] = true;
              }
      
              /**
               * Load and boot all of the remaining deferred providers.
               *
               * @return void
               */
              public function loadDeferredProviders()
              {
                  // We will simply spin through each of the deferred providers and register each
                  // one and boot them if the application has booted. This should make each of
                  // the remaining services available to this application for immediate use.
                  foreach ($this->deferredServices as $service => $provider)
                  {
                      $this->loadDeferredProvider($service);
                  }
      
                  $this->deferredServices = array();
              }
      
              /**
               * Load the provider for a deferred service.
               *
               * @param  string  $service
               * @return void
               */
              public function loadDeferredProvider($service)
              {
                  if ( ! isset($this->deferredServices[$service]))
                  {
                      return;
                  }
      
                  $provider = $this->deferredServices[$service];
      
                  // If the service provider has not already been loaded and registered we can
                  // register it with the application and remove the service from this list
                  // of deferred services, since it will already be loaded on subsequent.
                  if ( ! isset($this->loadedProviders[$provider]))
                  {
                      $this->registerDeferredProvider($provider, $service);
                  }
              }
      
              /**
               * Register a deferred provider and service.
               *
               * @param  string $provider
               * @param  string $service
               * @return void
               */
              public function registerDeferredProvider($provider, $service = null)
              {
                  // Once the provider that provides the deferred service has been registered we
                  // will remove it from our local list of the deferred services with related
                  // providers so that this container does not try to resolve it out again.
                  if ($service) unset($this->deferredServices[$service]);
      
                  $this->register($instance = new $provider($this));
      
                  if ( ! $this->booted)
                  {
                      $this->booting(function() use ($instance)
                      {
                          $this->bootProvider($instance);
                      });
                  }
              }
      
              /**
               * Resolve the given type from the container.
               *
               * (Overriding Container::make)
               *
               * @param  string  $abstract
               * @param  array   $parameters
               * @return mixed
               */
              public function make($abstract, Array $parameters = array())
              {
                  $abstract = $this->getAlias($abstract);
      
                  if (isset($this->deferredServices[$abstract]))
                  {
                      $this->loadDeferredProvider($abstract);
                  }
      
                  return parent::make($abstract, $parameters);
              }
      
              /**
               * Determine if the given abstract type has been bound.
               *
               * (Overriding Container::bound)
               *
               * @param  string  $abstract
               * @return bool
               */
              public function bound($abstract)
              {
                  return isset($this->deferredServices[$abstract]) || parent::bound($abstract);
              }
      
              /**
               * Determine if the application has booted.
               *
               * @return bool
               */
              public function isBooted()
              {
                  return $this->booted;
              }
      
              /**
               * Boot the application's service providers.
               *
               * @return void
               */
              public function boot()
              {
                  if ($this->booted) return;
      
                  // Once the application has booted we will also fire some "booted" callbacks
                  // for any listeners that need to do work after this initial booting gets
                  // finished. This is useful when ordering the boot-up processes we run.
                  $this->fireAppCallbacks($this->bootingCallbacks);
      
                  array_walk($this->serviceProviders, function ($p)
                  {
                      $this->bootProvider($p);
                  });
      
                  array_walk($this->plugins, function ($p)
                  {
                      if ( ! method_exists($p, 'boot'))
                      {
                          return;
                      }
      
                      $this->call([$p, 'boot'], ['app' => $this]);
                  });
      
                  if (count($this->mismatched) !== 0)
                  {
                      $this->notifyMismatched();
                  }
      
                  $this->booted = true;
      
                  $this->fireAppCallbacks($this->bootedCallbacks);
              }
      
              /**
               * Boot the given service provider.
               *
               * @param  \Illuminate\Support\ServiceProvider  $provider
               * @return mixed
               */
              protected function bootProvider(ServiceProvider $provider)
              {
                  if (method_exists($provider, 'boot'))
                  {
                      return $this->call([$provider, 'boot']);
                  }
      
                  return null;
              }
      
              /**
               * Register a new boot listener.
               *
               * @param  mixed  $callback
               * @return void
               */
              public function booting($callback)
              {
                  $this->bootingCallbacks[] = $callback;
              }
      
              /**
               * Register a new "booted" listener.
               *
               * @param  mixed  $callback
               * @return void
               */
              public function booted($callback)
              {
                  $this->bootedCallbacks[] = $callback;
      
                  if ($this->isBooted()) $this->fireAppCallbacks(array($callback));
              }
      
              /**
               * Call the booting callbacks for the application.
               *
               * @param  array  $callbacks
               * @return void
               */
              protected function fireAppCallbacks(array $callbacks)
              {
                  foreach ($callbacks as $callback)
                  {
                      call_user_func($callback, $this);
                  }
              }
      
              /**
               * Get all the view globals.
               *
               * @return array
               */
              public function getViewGlobals()
              {
                  if ($this->builtViewGlobals === null)
                  {
                      $this->buildViewGlobals();
                  }
      
                  return $this->builtViewGlobals;
              }
      
              /**
               * Builds the view globals.
               *
               * @return void
               */
              protected function buildViewGlobals()
              {
                  $globals = [];
      
                  foreach ($this->viewGlobals as $global)
                  {
                      list($key, $val) = $global;
      
                      try {
                          $val = $this->call($val, ['app' => $this]);
                      }
                      catch (\Exception $e)
                      {
                          if ((is_numeric($key) || $key === null) && is_string($val))
                          {
                              continue;
                          }
                      }
      
                      if ($key !== null)
                      {
                          $val = [$key => $val];
                      }
      
                      $val = (array) $val;
      
                      $globals = array_merge($globals, $val);
                  }
      
                  foreach ($this->apis as $api)
                  {
                      list($name, $instance) = $api;
      
                      $globals[$name] = $instance;
                  }
      
                  $this->builtViewGlobals = $globals;
              }
      
              /**
               * Get the view globals.
               *
               * @param  string $view
               * @return array
               */
              public function getViewsGlobals($view)
              {
                  $globals = [];
      
                  foreach ($this->viewComposers as $match => $composers)
                  {
                      if ( ! str_is($match, $view))
                      {
                          continue;
                      }
      
                      foreach ($composers as $composer)
                      {
                          if (is_array($composer))
                          {
                              $globals = array_merge($globals, $composer);
      
                              continue;
                          }
      
                          $globals = array_merge((array) $this->call($composer, ['app' => $this, 'view' => $view]));
                      }
                  }
      
                  return $globals;
              }
      
              /**
               * Sets the view globals.
               *
               * @param array $globals
               */
              public function setViewGlobals($globals)
              {
                  $this->viewGlobals = $globals;
              }
      
              /**
               * Get the version number of the application.
               *
               * @return string
               */
              public function version()
              {
                  return static::VERSION;
              }
      
              /**
               * Get or check the current application environment.
               *
               * @param  mixed
               * @return string
               */
              public function environment()
              {
                  if (func_num_args() > 0)
                  {
                      $patterns = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
      
                      foreach ($patterns as $pattern)
                      {
                          if (str_is($pattern, $this['env']))
                          {
                              return true;
                          }
                      }
      
                      return false;
                  }
      
                  return $this['env'];
              }
      
              /**
               * Determine if the application is currently down for maintenance.
               *
               * @todo
               * @return bool
               */
              public function isDownForMaintenance()
              {
                  return false;
              }
      
              /**
               * Get the global container instance.
               *
               * @return static
               */
              public static function getInstance()
              {
                  if (is_null(static::$instance))
                  {
                      static::$instance = new static;
                  }
      
                  return static::$instance;
              }
      
              /**
               * Get the path to the cached "compiled.php" file.
               *
               * @return string
               */
              public function getCachedCompilePath()
              {
                  return $this->basePath() . '/vendor/compiled.php';
              }
      
              /**
               * Get the path to the cached services.json file.
               *
               * @return string
               */
              public function getCachedServicesPath()
              {
                  return $this->basePath() . '/vendor/services.json';
              }
      
          }
      • #add() ($method, $fn)


        /**
          * Add a method.
          *
          * @param $method
          * @param $fn
          */
          public function add($method, $fn)
          {
            $this->methods[$method] = $fn;
          }
      • #get() ($method)


        /**
          * Gets a method.
          *
          * @param  string $method
          * @return Callable
          */
         public function get($method)
         {
             return array_get($this->methods, $method);
         }
      • #__call() ($method, $params)


         /**
             * Magic call from the function collection.
             *
             * @param $method
             * @param $params
             * @return mixed
             * @throws \WP_Error
             */
            public function __call($method, $params)
            {
                if ( ! isset($this->methods[$method]))
                {
                    throw new Exception("Method '{$method}' not set!");
                }
        
                return $this->app->call(
                    $this->methods[$method], $params
                );
            }
      {"cards":[{"_id":"6afda7dc02bef4c8ff000464","treeId":"6afda28602bef4c8ff000461","seq":7851445,"position":1,"parentId":null,"content":"herbert-dev"},{"_id":"6afec6ae02bef4c8ff000471","treeId":"6afda28602bef4c8ff000461","seq":7850837,"position":2,"parentId":null,"content":"This is the framework, it is meant to be installed outside of the WP install via Composer."},{"_id":"6aff3a1002bef4c8ff000473","treeId":"6afda28602bef4c8ff000461","seq":7851451,"position":1,"parentId":"6afec6ae02bef4c8ff000471","content":"`app/`"},{"_id":"6aff445302bef4c8ff000474","treeId":"6afda28602bef4c8ff000461","seq":7851462,"position":2,"parentId":"6afec6ae02bef4c8ff000471","content":"`resources/`"},{"_id":"6aff44f102bef4c8ff000475","treeId":"6afda28602bef4c8ff000461","seq":7851464,"position":3,"parentId":"6afec6ae02bef4c8ff000471","content":"`vendor/`"},{"_id":"6aff464002bef4c8ff000476","treeId":"6afda28602bef4c8ff000461","seq":7851465,"position":1,"parentId":"6aff44f102bef4c8ff000475","content":"`getherbert/`"},{"_id":"6aff46b302bef4c8ff000477","treeId":"6afda28602bef4c8ff000461","seq":7851466,"position":1,"parentId":"6aff464002bef4c8ff000476","content":"`framework/`"},{"_id":"6afdabdb02bef4c8ff000467","treeId":"6afda28602bef4c8ff000461","seq":7851468,"position":1,"parentId":"6aff46b302bef4c8ff000477","content":"`bootstrap/`\n"},{"_id":"6afdceb102bef4c8ff00046c","treeId":"6afda28602bef4c8ff000461","seq":7850288,"position":1,"parentId":"6afdabdb02bef4c8ff000467","content":"`autoload.php`"},{"_id":"6afdf09d02bef4c8ff000470","treeId":"6afda28602bef4c8ff000461","seq":7851886,"position":0.5,"parentId":"6afdceb102bef4c8ff00046c","content":"- checks for / Defines `HERBERT_AUTOLOAD` to check if the framework is loaded (a form of singuarton pattern).\n- requires the `helpers.php`\n- runs `Herbert\\Framework\\Application::getInstance()`\n- loads all instances of `herbert.config.php` in wp the plugins directory \n- \nUses:\n #getInstance()\n #boot()\n"},{"_id":"6afdcfc002bef4c8ff00046e","treeId":"6afda28602bef4c8ff000461","seq":7850762,"position":1,"parentId":"6afdceb102bef4c8ff00046c","content":" <?php\n /**\n * Ensure this is only ran once.\n */\n if (defined('HERBERT_AUTOLOAD'))\n {\n return;\n }\n define('HERBERT_AUTOLOAD', microtime(true));\n @require 'helpers.php';\n /**\n * Load the WP plugin system.\n */\n if (array_search(ABSPATH . 'wp-admin/includes/plugin.php', get_included_files()) === false)\n {\n require_once ABSPATH . 'wp-admin/includes/plugin.php';\n }\n /**\n * Get Herbert.\n */\n $herbert = Herbert\\Framework\\Application::getInstance();\n /**\n * Load all herbert.php files in plugin roots.\n */\n $iterator = new DirectoryIterator(plugin_directory());\n foreach ($iterator as $directory)\n {\n if ( ! $directory->valid() || $directory->isDot() || ! $directory->isDir())\n {\n continue;\n }\n $root = $directory->getPath() . '/' . $directory->getFilename();\n if ( ! file_exists($root . '/herbert.config.php'))\n {\n continue;\n }\n $config = $herbert->getPluginConfig($root);\n $plugin = substr($root . '/plugin.php', strlen(plugin_directory()));\n $plugin = ltrim($plugin, '/');\n register_activation_hook($plugin, function () use ($herbert, $config, $root)\n {\n if ( ! $herbert->pluginMatches($config))\n {\n $herbert->pluginMismatched($root);\n }\n $herbert->pluginMatched($root);\n $herbert->loadPlugin($config);\n $herbert->activatePlugin($root);\n });\n register_deactivation_hook($plugin, function () use ($herbert, $root)\n {\n $herbert->deactivatePlugin($root);\n });\n // Ugly hack to make the install hook work correctly\n // as WP doesn't allow closures to be passed here\n register_uninstall_hook($plugin, create_function('', 'herbert()->deletePlugin(\\'' . $root . '\\');'));\n if ( ! is_plugin_active($plugin))\n {\n continue;\n }\n if ( ! $herbert->pluginMatches($config))\n {\n $herbert->pluginMismatched($root);\n continue;\n }\n $herbert->pluginMatched($root);\n @require_once $root.'/plugin.php';\n $herbert->loadPlugin($config);\n }\n /**\n * Boot Herbert.\n */\n $herbert->boot();"},{"_id":"6afdcf6b02bef4c8ff00046d","treeId":"6afda28602bef4c8ff000461","seq":7850289,"position":2,"parentId":"6afdabdb02bef4c8ff000467","content":"`helpers.php`"},{"_id":"6aff716875244ca22a0000f7","treeId":"6afda28602bef4c8ff000461","seq":7851717,"position":0.5,"parentId":"6afdcf6b02bef4c8ff00046d","content":"- Checks for the existence of, and then loads a suite of helper functions. \n\n- There must be a concern that this file could be loaded twice, hence the checks. But if we are truly following a singleton pattern, then this shouldn't matter. \n\n- These are being loaded at a global scope, and not in a helper class as `public static functions` - __why not?__\n\n"},{"_id":"6aff526d75244ca22a0000ea","treeId":"6afda28602bef4c8ff000461","seq":7851679,"position":1,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#dd()\n\n----\n\n if ( ! function_exists('dd'))\n {\n /**\n * Dies and dumps.\n *\n * @return string\n */\n function dd()\n {\n call_user_func_array('dump', func_get_args());\n\n die;\n }\n }"},{"_id":"6aff55a475244ca22a0000eb","treeId":"6afda28602bef4c8ff000461","seq":7851680,"position":2,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#content_directory()\n\n---\n\n if ( ! function_exists('content_directory'))\n {\n /**\n * Gets the content directory.\n *\n * @return string\n */\n function content_directory()\n {\n return WP_CONTENT_DIR;\n }\n }"},{"_id":"6aff571075244ca22a0000ec","treeId":"6afda28602bef4c8ff000461","seq":7851681,"position":3,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#plugin_directory()\n\n---\n\n if ( ! function_exists('plugin_directory'))\n {\n /**\n * Gets the plugin directory.\n *\n * @return string\n */\n function plugin_directory()\n {\n return WP_PLUGIN_DIR;\n }\n }\n"},{"_id":"6aff583a75244ca22a0000ed","treeId":"6afda28602bef4c8ff000461","seq":7851683,"position":4,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#response() `($body, $status = 200, $headers = null)`\n\n---\n\n if ( ! function_exists('response'))\n {\n /**\n * Generates a response.\n *\n * @param string $body\n * @param integer $status\n * @param array $headers\n * @return \\Herbert\\Framework\\Response\n */\n function response($body, $status = 200, $headers = null)\n {\n return new Herbert\\Framework\\Response($body, $status, $headers);\n }\n }"},{"_id":"6aff5a0d75244ca22a0000ee","treeId":"6afda28602bef4c8ff000461","seq":7851684,"position":5,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#json_response() `($jsonable, $status = 200, $headers = null)`\n\n---\n\n if ( ! function_exists('json_response'))\n {\n /**\n * Generates a json response.\n *\n * @param mixed $jsonable\n * @param integer $status\n * @param array $headers\n * @return \\Herbert\\Framework\\Response\n */\n function json_response($jsonable, $status = 200, $headers = null)\n {\n return new Herbert\\Framework\\JsonResponse($jsonable, $status, $headers);\n }\n }"},{"_id":"6aff5b8775244ca22a0000ef","treeId":"6afda28602bef4c8ff000461","seq":7851685,"position":6,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#json_response() `($jsonable, $status = 200, $headers = null)`\n\n---\n\n if ( ! function_exists('json_response'))\n {\n /**\n * Generates a json response.\n *\n * @param mixed $jsonable\n * @param integer $status\n * @param array $headers\n * @return \\Herbert\\Framework\\Response\n */\n function json_response($jsonable, $status = 200, $headers = null)\n {\n return new Herbert\\Framework\\JsonResponse($jsonable, $status, $headers);\n }\n }"},{"_id":"6aff5cf975244ca22a0000f0","treeId":"6afda28602bef4c8ff000461","seq":7851687,"position":7,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#redirect_response() `($url, $status = 302, $headers = null)`\n\n---\n\n if ( ! function_exists('redirect_response'))\n {\n /**\n * Generates a redirect response.\n *\n * @param string $url\n * @param integer $status\n * @param array $headers\n * @return \\Herbert\\Framework\\Response\n */\n function redirect_response($url, $status = 302, $headers = null)\n {\n return new Herbert\\Framework\\RedirectResponse($url, $status, $headers);\n }\n }"},{"_id":"6aff5e2175244ca22a0000f1","treeId":"6afda28602bef4c8ff000461","seq":7851688,"position":8,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#herbert() `($binding = null)`\n\n---\n\n if ( ! function_exists('herbert'))\n {\n /**\n * Gets the herbert container.\n *\n * @param string $binding\n * @return string\n */\n function herbert($binding = null)\n {\n $instance = Herbert\\Framework\\Application::getInstance();\n\n if ( ! $binding)\n {\n return $instance;\n }\n\n return $instance[$binding];\n }\n }"},{"_id":"6aff5fea75244ca22a0000f2","treeId":"6afda28602bef4c8ff000461","seq":7851690,"position":9,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#errors() `($key = null)`\n\n---\n if ( ! function_exists('errors'))\n {\n /**\n * Get the errors.\n *\n * @param string key\n * @return array\n */\n function errors($key = null)\n {\n $errors = herbert('errors');\n $errors = isset($errors[0]) ? $errors[0] : $errors;\n\n if (!$key)\n {\n return $errors;\n }\n\n return array_get($errors, $key);\n }\n }"},{"_id":"6aff616b75244ca22a0000f3","treeId":"6afda28602bef4c8ff000461","seq":7851691,"position":10,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#session() `($key = null, $default = null)`\n\n---\n\n if ( ! function_exists('session'))\n {\n /**\n * Gets the session or a key from the session.\n *\n * @param string $key\n * @param mixed $default\n * @return \\Illuminate\\Session\\Store|mixed\n */\n function session($key = null, $default = null)\n {\n if ($key === null)\n {\n return herbert('session');\n }\n\n return herbert('session')->get($key, $default);\n }\n }"},{"_id":"6aff633675244ca22a0000f4","treeId":"6afda28602bef4c8ff000461","seq":7851693,"position":11,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#session_flashed() `($key = null, $default = [])`\n\n---\n\n if ( ! function_exists('session_flashed'))\n {\n /**\n * Gets the session flashbag or a key from the session flashbag.\n *\n * @param string $key\n * @param mixed $default\n * @return \\Illuminate\\Session\\Store|mixed\n */\n function session_flashed($key = null, $default = [])\n {\n if ($key === null)\n {\n return herbert('session')->getFlashBag();\n }\n\n return herbert('session')->getFlashBag()->get($key, $default);\n }\n }"},{"_id":"6aff65b675244ca22a0000f5","treeId":"6afda28602bef4c8ff000461","seq":7851694,"position":12,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#view() `($name, $context = [])`\n\n---\n\n if ( ! function_exists('view'))\n {\n /**\n * Renders a twig view.\n *\n * @param string $name\n * @param array $context\n * @return string\n */\n function view($name, $context = [])\n {\n return response(herbert('Twig_Environment')->render($name, $context));\n }\n }\n"},{"_id":"6aff675975244ca22a0000f6","treeId":"6afda28602bef4c8ff000461","seq":7851695,"position":13,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#panel_url() `($name, $query = [])`\n\n---\n if ( ! function_exists('panel_url'))\n {\n /**\n * Gets the url to a panel.\n *\n * @param string $name\n * @param array $query\n * @return string\n */\n function panel_url($name, $query = [])\n {\n return add_query_arg($query, herbert('panel')->url($name));\n }\n }\n"},{"_id":"6aff4b5e02bef4c8ff00047a","treeId":"6afda28602bef4c8ff000461","seq":7851696,"position":14,"parentId":"6afdcf6b02bef4c8ff00046d","content":"#route_url() `($name, $args = [], $query = [])`\n\n---\n if ( ! function_exists('route_url'))\n {\n /**\n * Gets the url to a route.\n *\n * @param string $name\n * @param array $args\n * @param array $query\n * @return string\n */\n function route_url($name, $args = [], $query = [])\n {\n return add_query_arg($query, herbert('router')->url($name, $args));\n }\n }\n"},{"_id":"6aff499302bef4c8ff000478","treeId":"6afda28602bef4c8ff000461","seq":7851479,"position":2,"parentId":"6aff46b302bef4c8ff000477","content":"`herbert/`"},{"_id":"6aff7efb75244ca22a0000fb","treeId":"6afda28602bef4c8ff000461","seq":7856883,"position":0.5,"parentId":"6aff499302bef4c8ff000478","content":"`API.php` #API::\n\nThe #API:: class uses #Exception::"},{"_id":"6aff8aee75244ca22a0000ff","treeId":"6afda28602bef4c8ff000461","seq":7851765,"position":0.625,"parentId":"6aff7efb75244ca22a0000fb","content":"#API:: #add()"},{"_id":"6aff944475244ca22a000104","treeId":"6afda28602bef4c8ff000461","seq":7851880,"position":2,"parentId":"6aff8aee75244ca22a0000ff","content":"#add() `($method, $fn)`\n\n---\n\n /**\n * Add a method.\n *\n * @param $method\n * @param $fn\n */\n public function add($method, $fn)\n {\n $this->methods[$method] = $fn;\n }"},{"_id":"6aff8d5275244ca22a000101","treeId":"6afda28602bef4c8ff000461","seq":7851779,"position":0.6875,"parentId":"6aff7efb75244ca22a0000fb","content":" #API:: #get()"},{"_id":"6aff8dc675244ca22a000102","treeId":"6afda28602bef4c8ff000461","seq":7851878,"position":1,"parentId":"6aff8d5275244ca22a000101","content":"#get() `($method)`\n\n---\n\n /**\n * Gets a method.\n *\n * @param string $method\n * @return Callable\n */\n public function get($method)\n {\n return array_get($this->methods, $method);\n }"},{"_id":"6aff938075244ca22a000103","treeId":"6afda28602bef4c8ff000461","seq":7851851,"position":0.71875,"parentId":"6aff7efb75244ca22a0000fb","content":"#API:: #fn()"},{"_id":"6aff887f75244ca22a0000fe","treeId":"6afda28602bef4c8ff000461","seq":7851888,"position":0.75,"parentId":"6aff7efb75244ca22a0000fb","content":"#API:: #__call()"},{"_id":"6aff9d8e75244ca22a000105","treeId":"6afda28602bef4c8ff000461","seq":7851889,"position":1,"parentId":"6aff887f75244ca22a0000fe","content":"#__call() `($method, $params)`\n\n---\n\n /**\n * Magic call from the function collection.\n *\n * @param $method\n * @param $params\n * @return mixed\n * @throws \\WP_Error\n */\n public function __call($method, $params)\n {\n if ( ! isset($this->methods[$method]))\n {\n throw new Exception(\"Method '{$method}' not set!\");\n }\n\n return $this->app->call(\n $this->methods[$method], $params\n );\n }\n"},{"_id":"6aff7f5c75244ca22a0000fc","treeId":"6afda28602bef4c8ff000461","seq":7856881,"position":1,"parentId":"6aff7efb75244ca22a0000fb","content":" <?php namespace Herbert\\Framework;\n\n use Exception;\n\n /**\n * @see http://getherbert.com\n */\n class API {\n\n /**\n * @var array\n */\n protected $methods = [];\n\n /**\n * @var \\Herbert\\Framework\\Application\n */\n protected $app;\n\n /**\n * @param \\Herbert\\Framework\\Application $app\n */\n public function __construct(Application $app)\n {\n $this->app = $app;\n }\n\n /**\n * Add a method.\n *\n * @param $method\n * @param $fn\n */\n public function add($method, $fn)\n {\n $this->methods[$method] = $fn;\n }\n\n /**\n * Gets a method.\n *\n * @param string $method\n * @return Callable\n */\n public function get($method)\n {\n return array_get($this->methods, $method);\n }\n\n /**\n * Magic call from the function collection.\n *\n * @param $method\n * @param $params\n * @return mixed\n * @throws \\WP_Error\n */\n public function __call($method, $params)\n {\n if ( ! isset($this->methods[$method]))\n {\n throw new Exception(\"Method '{$method}' not set!\");\n }\n\n return $this->app->call(\n $this->methods[$method], $params\n );\n }\n\n }\n"},{"_id":"6affa1dd75244ca22a000106","treeId":"6afda28602bef4c8ff000461","seq":7864304,"position":0.75,"parentId":"6aff499302bef4c8ff000478","content":"`Application.php` #Application::\n\n Extends \\Illuminate\\Container\\Container\n implements \\Illuminate\\Contracts\\Foundation\\Application\n\n"},{"_id":"6b02dc0575244ca22a000108","treeId":"6afda28602bef4c8ff000461","seq":7853573,"position":0.5,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #__construct#\n\n---\n\n public function __construct()\n {\n static::$instance = $this;\n\n $this->version = new SemVersion(self::VERSION);\n\n $this->instance('app', $this);\n $this->instance('Illuminate\\Container\\Container', $this);\n\n $this->registerBaseProviders();\n $this->registerCoreContainerAliases();\n $this->registerConfiguredProviders();\n }"},{"_id":"6b02e10c75244ca22a000109","treeId":"6afda28602bef4c8ff000461","seq":7853574,"position":0.75,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #basePath()\n\n---\n\n /**\n * Added to satisfy interface\n *\n * @return string\n */\n public function basePath()\n {\n return content_directory() . '/herbert-cache';\n }"},{"_id":"6b02e41175244ca22a00010a","treeId":"6afda28602bef4c8ff000461","seq":7853577,"position":0.875,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #getPlugins()\n\n---\n\n /**\n * Get all loaded plugins.\n *\n * @return array\n */\n public function getPlugins()\n {\n return $this->plugins;\n }\n"},{"_id":"6b02e61b75244ca22a00010b","treeId":"6afda28602bef4c8ff000461","seq":7853580,"position":0.9375,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #getPlugins()\n\n---\n\n /**\n * Gets a plugin's configuration.\n *\n * @param string $root\n * @return array\n */\n public function getPluginConfig($root)\n {\n if ( ! isset($this->configurations[$root]))\n {\n $this->configurations[$root] = @require_once \"$root/herbert.config.php\" ?: [];\n }\n\n return $this->configurations[$root];\n }"},{"_id":"6b02e82575244ca22a00010c","treeId":"6afda28602bef4c8ff000461","seq":7853590,"position":0.96875,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #getPluginConfig() `($root)`\n\n---\n\n /**\n * Gets a plugin's configuration.\n *\n * @param string $root \n * @return array\n */\n public function getPluginConfig($root)\n {\n if ( ! isset($this->configurations[$root]))\n {\n $this->configurations[$root] = @require_once \"$root/herbert.config.php\" ?: [];\n }\n\n return $this->configurations[$root];\n }\n"},{"_id":"6b02e86775244ca22a00010d","treeId":"6afda28602bef4c8ff000461","seq":7853593,"position":0.984375,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #pluginMatches() `($config)`\n\n---\n\n /**\n * Checks if a plugin version is matches.\n *\n * @param array $config\n * @return bool\n */\n public function pluginMatches($config)\n {\n $constraint = array_get($config, 'constraint', self::VERSION);\n\n return $this->version->satisfies(new SemVersionExpression($constraint));\n }"},{"_id":"6b02e88775244ca22a00010e","treeId":"6afda28602bef4c8ff000461","seq":7853606,"position":0.9921875,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #pluginMismatched() `($root)`\n\n---\n\n /**\n * Logs a plugin as incompatible.\n *\n * @param string $root\n * @return void\n */\n public function pluginMismatched($root)\n {\n $this->mismatched[] = $root;\n }\n"},{"_id":"6b02e8a275244ca22a00010f","treeId":"6afda28602bef4c8ff000461","seq":7853612,"position":0.99609375,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #pluginMatched() `($root)`\n\n---\n\n /**\n * Logs a plugin as compatible.\n *\n * @param string $root\n * @return void\n */\n public function pluginMatched($root)\n {\n $this->matched[] = $root;\n }"},{"_id":"6b02f2ba75244ca22a000110","treeId":"6afda28602bef4c8ff000461","seq":7853623,"position":0.998046875,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #notifyMismatched()\n\n---\n\n /**\n * Notifies the user of mismatched plugins.\n *\n * @return void\n */\n protected function notifyMismatched()\n {\n $matched = array_map(function ($value)\n {\n return basename($value);\n }, $this->matched);\n\n $mismatched = array_map(function ($value)\n {\n return basename($value);\n }, $this->mismatched);\n\n $message = 'Unfortunately plugin(s) '\n . implode(', ', $mismatched)\n . ' can’t work with the following plugin(s) '\n . implode(', ', $matched)\n . '. Please disable and try updating all of the above plugins before reactivating.';\n\n Notifier::error($message);\n }\n"},{"_id":"6b02f32275244ca22a000111","treeId":"6afda28602bef4c8ff000461","seq":7853626,"position":0.9990234375,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #loadPlugin() `($config)`\n\n---\n\n /**\n * Loads a plugin.\n *\n * @param array $config\n * @return void\n */\n public function loadPlugin($config)\n {\n $this->loadPluginRequires(\n array_get($config, 'requires', [])\n );\n\n $this->loadPluginRoutes(\n 'router',\n array_get($config, 'routes', [])\n );\n\n $this->loadPluginPanels(\n 'panel',\n array_get($config, 'panels', [])\n );\n\n $this->loadPluginX(\n 'enqueue',\n array_get($config, 'enqueue', [])\n );\n\n $this->loadPluginX(\n 'shortcode',\n array_get($config, 'shortcodes', [])\n );\n\n $this->loadPluginX(\n 'widget',\n array_get($config, 'widgets', [])\n );\n\n $this->loadPluginAPIs(\n array_get($config, 'apis', [])\n );\n\n $this->addPluginTwigNamespaces(\n array_get($config, 'views', [])\n );\n\n $this->addPluginViewGlobals(\n array_get($config, 'viewGlobals', [])\n );\n\n $this->addPluginComposers(\n array_get($config, 'viewComposers', [])\n );\n }"},{"_id":"6b02f34275244ca22a000112","treeId":"6afda28602bef4c8ff000461","seq":7853628,"position":0.99951171875,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #loadPluginRequires() `($requires = [])`\n\n---\n\n /**\n * Load all a plugin's requires.\n *\n * @param array $requires\n * @return void\n */\n protected function loadPluginRequires($requires = [])\n {\n $container = $this;\n\n foreach ($requires as $require)\n {\n @require_once \"$require\";\n }\n }\n"},{"_id":"6b02facf75244ca22a000113","treeId":"6afda28602bef4c8ff000461","seq":7853629,"position":0.999755859375,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #loadPluginRequires() `($requires = [])`\n\n---\n"},{"_id":"6b02fae975244ca22a000114","treeId":"6afda28602bef4c8ff000461","seq":7853633,"position":0.9998779296875,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #loadPluginRequires() `($requires = [])`\n\n---\n"},{"_id":"6b02fafa75244ca22a000115","treeId":"6afda28602bef4c8ff000461","seq":7853637,"position":0.99993896484375,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #loadPluginRequires() `($requires = [])`\n\n---\n"},{"_id":"6b02fb0b75244ca22a000116","treeId":"6afda28602bef4c8ff000461","seq":7853635,"position":0.999969482421875,"parentId":"6affa1dd75244ca22a000106","content":"#Application:: #loadPluginRequires() `($requires = [])`\n\n---\n"},{"_id":"6affa3e275244ca22a000107","treeId":"6afda28602bef4c8ff000461","seq":7853613,"position":1,"parentId":"6affa1dd75244ca22a000106","content":"#Application::\n\n\n\n <?php namespace Herbert\\Framework;\n\n use Illuminate\\Support\\ServiceProvider;\n use vierbergenlars\\SemVer\\version as SemVersion;\n use vierbergenlars\\SemVer\\expression as SemVersionExpression;\n use Illuminate\\Database\\Capsule\\Manager as CapsuleManager;\n use Illuminate\\Database\\Schema\\Blueprint as SchemaBlueprint;\n\n /**\n * @see http://getherbert.com\n */\n class Application extends \\Illuminate\\Container\\Container implements \\Illuminate\\Contracts\\Foundation\\Application {\n\n /**\n * The application's version.\n */\n const VERSION = '0.9.13';\n\n /**\n * The application's version.\n *\n * @var \\vierbergenlars\\SemVer\\version\n */\n protected $version;\n\n /**\n * @var \\Herbert\\Framework\\Application\n */\n protected static $instance;\n\n /**\n * Indicates if the application has \"booted\".\n *\n * @var bool\n */\n protected $booted = false;\n\n /**\n * The array of booting callbacks.\n *\n * @var array\n */\n protected $bootingCallbacks = array();\n\n /**\n * The array of booted callbacks.\n *\n * @var array\n */\n protected $bootedCallbacks = array();\n\n /**\n * The array of terminating callbacks.\n *\n * @var array\n */\n protected $terminatingCallbacks = array();\n\n /**\n * All of the registered service providers.\n *\n * @var array\n */\n protected $serviceProviders = array();\n\n /**\n * The names of the loaded service providers.\n *\n * @var array\n */\n protected $loadedProviders = array();\n\n /**\n * The deferred services and their providers.\n *\n * @var array\n */\n protected $deferredServices = array();\n\n /**\n * The registered plugins.\n *\n * @var array\n */\n protected $plugins = [];\n\n /**\n * The mismatched plugins.\n *\n * @var array\n */\n protected $mismatched = [];\n\n /**\n * The matched plugins.\n *\n * @var array\n */\n protected $matched = [];\n\n /**\n * The plugin apis.\n *\n * @var array\n */\n protected $apis = [];\n\n /**\n * The plugin configurations.\n *\n * @var array\n */\n protected $configurations = [];\n\n /**\n * The view composers.\n *\n * @var array\n */\n protected $viewComposers = [];\n\n /**\n * The view globals.\n *\n * @var array\n */\n protected $viewGlobals = [];\n\n /**\n * The built view globals.\n *\n * @var array\n */\n protected $builtViewGlobals = null;\n\n /**\n * Constructs the application and ensures it's correctly setup.\n */\n public function __construct()\n {\n static::$instance = $this;\n\n $this->version = new SemVersion(self::VERSION);\n\n $this->instance('app', $this);\n $this->instance('Illuminate\\Container\\Container', $this);\n\n $this->registerBaseProviders();\n $this->registerCoreContainerAliases();\n $this->registerConfiguredProviders();\n }\n\n /**\n * Added to satisfy interface\n *\n * @return string\n */\n public function basePath()\n {\n return content_directory() . '/herbert-cache';\n }\n\n /**\n * Get all loaded plugins.\n *\n * @return array\n */\n public function getPlugins()\n {\n return $this->plugins;\n }\n\n /**\n * Gets a plugin's configuration.\n *\n * @param string $root\n * @return array\n */\n public function getPluginConfig($root)\n {\n if ( ! isset($this->configurations[$root]))\n {\n $this->configurations[$root] = @require_once \"$root/herbert.config.php\" ?: [];\n }\n\n return $this->configurations[$root];\n }\n\n /**\n * Checks if a plugin version is matches.\n *\n * @param array $config\n * @return bool\n */\n public function pluginMatches($config)\n {\n $constraint = array_get($config, 'constraint', self::VERSION);\n\n return $this->version->satisfies(new SemVersionExpression($constraint));\n }\n\n /**\n * Logs a plugin as incompatable.\n *\n * @param string $root\n * @return void\n */\n public function pluginMismatched($root)\n {\n $this->mismatched[] = $root;\n }\n\n /**\n * Logs a plugin as compatable.\n *\n * @param string $root\n * @return void\n */\n public function pluginMatched($root)\n {\n $this->matched[] = $root;\n }\n\n /**\n * Notifies the user of mismatched plugins.\n *\n * @return void\n */\n protected function notifyMismatched()\n {\n $matched = array_map(function ($value)\n {\n return basename($value);\n }, $this->matched);\n\n $mismatched = array_map(function ($value)\n {\n return basename($value);\n }, $this->mismatched);\n\n $message = 'Unfortunately plugin(s) '\n . implode(', ', $mismatched)\n . ' can’t work with the following plugin(s) '\n . implode(', ', $matched)\n . '. Please disable and try updating all of the above plugins before reactivating.';\n\n Notifier::error($message);\n }\n\n /**\n * Loads a plugin.\n *\n * @param array $config\n * @return void\n */\n public function loadPlugin($config)\n {\n $this->loadPluginRequires(\n array_get($config, 'requires', [])\n );\n\n $this->loadPluginRoutes(\n 'router',\n array_get($config, 'routes', [])\n );\n\n $this->loadPluginPanels(\n 'panel',\n array_get($config, 'panels', [])\n );\n\n $this->loadPluginX(\n 'enqueue',\n array_get($config, 'enqueue', [])\n );\n\n $this->loadPluginX(\n 'shortcode',\n array_get($config, 'shortcodes', [])\n );\n\n $this->loadPluginX(\n 'widget',\n array_get($config, 'widgets', [])\n );\n\n $this->loadPluginAPIs(\n array_get($config, 'apis', [])\n );\n\n $this->addPluginTwigNamespaces(\n array_get($config, 'views', [])\n );\n\n $this->addPluginViewGlobals(\n array_get($config, 'viewGlobals', [])\n );\n\n $this->addPluginComposers(\n array_get($config, 'viewComposers', [])\n );\n }\n\n /**\n * Load all a plugin's requires.\n *\n * @param array $requires\n * @return void\n */\n protected function loadPluginRequires($requires = [])\n {\n $container = $this;\n\n foreach ($requires as $require)\n {\n @require_once \"$require\";\n }\n }\n\n /**\n * Load all a plugin's routes.\n *\n * @param array $routes\n * @return void\n */\n protected function loadPluginRoutes($x, $routes = [])\n {\n $container = $this;\n $router = $this['router'];\n\n foreach ($routes as $namespace => $requires)\n {\n $router->setNamespace($namespace);\n\n foreach ((array) $requires as $require)\n {\n @require_once \"$require\";\n }\n\n $router->unsetNamespace();\n }\n }\n\n /**\n * Load all a plugin's panels.\n *\n * @param array $panels\n * @return void\n */\n protected function loadPluginPanels($x, $panels = [])\n {\n $container = $this;\n $panel = $this['panel'];\n\n foreach ($panels as $namespace => $requires)\n {\n $panel->setNamespace($namespace);\n\n foreach ((array) $requires as $require)\n {\n @require_once \"$require\";\n }\n\n $panel->unsetNamespace();\n }\n }\n\n /**\n * Load all a plugin's :x.\n *\n * @param array $requires\n * @return void\n */\n protected function loadPluginX($x, $requires = [])\n {\n $container = $this;\n $$x = $this[$x];\n\n foreach ($requires as $require)\n {\n @require_once \"$require\";\n }\n }\n\n /**\n * Add all a plugin's twig namespaces.\n *\n * @param array $namespaces\n * @return void\n */\n protected function addPluginTwigNamespaces($namespaces = [])\n {\n $loader = $this['twig.loader'];\n\n foreach ($namespaces as $namespace => $paths)\n {\n foreach ((array) $paths as $path)\n {\n $loader->addPath($path, $namespace);\n }\n }\n }\n\n /**\n * Add all a plugin's view globals.\n *\n * @param array $globals\n * @return void\n */\n protected function addPluginViewGlobals($globals = [])\n {\n foreach ($globals as $key => $_globals)\n {\n if (is_numeric($key))\n {\n $key = null;\n }\n\n $this->viewGlobals[] = [$key, $_globals];\n }\n\n $this->builtViewGlobals = null;\n }\n\n /**\n * Add all a plugin's view composers.\n *\n * @param array $composers\n * @return void\n */\n protected function addPluginComposers($composers = [])\n {\n foreach ($composers as $match => $_composers)\n {\n $this->viewComposers[] = [$match, (array) $_composers];\n }\n }\n\n /**\n * Load the plugin's apis.\n *\n * @param array $requires\n * @return void\n */\n protected function loadPluginAPIs($requires = [])\n {\n $container = $this;\n\n foreach ($requires as $name => $require)\n {\n global $$name;\n $api = $$name = new API($this);\n $this->apis[] = [$name, $api];\n\n require \"$require\";\n }\n }\n\n /**\n * Register a plugin.\n *\n * @param \\Herbert\\Framework\\Plugin $plugin\n */\n public function registerPlugin(Plugin $plugin)\n {\n $plugin->setContainer($this);\n\n $this->plugins[] = $plugin;\n\n $this->registerPluginProviders($plugin);\n $this->registerPluginAliases($plugin);\n }\n\n /**\n * Deactivates a plugin.\n *\n * @see register_activation_hook()\n * @param $root\n */\n public function activatePlugin($root)\n {\n $plugins = array_filter($this->plugins, function (Plugin $plugin) use ($root)\n {\n return $plugin->getBasePath() === $root;\n });\n\n foreach ($plugins as $plugin)\n {\n $plugin->activate();\n }\n\n $config = $this->getPluginConfig($root);\n\n foreach (array_get($config, 'tables', []) as $table => $class)\n {\n if ( ! class_exists($class))\n {\n continue;\n }\n\n if (CapsuleManager::schema()->hasTable($table))\n {\n continue;\n }\n\n CapsuleManager::schema()->create($table, function (SchemaBlueprint $table) use ($class)\n {\n $this->call($class . '@activate', ['table' => $table, 'app' => $this]);\n });\n }\n\n foreach (array_get($config, 'activators', []) as $activator)\n {\n if ( ! file_exists($activator))\n {\n continue;\n }\n\n $this->loadWith($activator, [\n 'http',\n 'router',\n 'enqueue',\n 'panel',\n 'shortcode',\n 'widget'\n ]);\n }\n }\n\n /**\n * Deactivates a plugin.\n *\n * @see register_deactivation_hook()\n * @param $root\n */\n public function deactivatePlugin($root)\n {\n $plugins = array_filter($this->plugins, function (Plugin $plugin) use ($root)\n {\n return $plugin->getBasePath() === $root;\n });\n\n foreach ($plugins as $plugin)\n {\n $plugin->deactivate();\n }\n\n $config = $this->getPluginConfig($root);\n\n foreach (array_get($config, 'deactivators', []) as $deactivator)\n {\n if ( ! file_exists($deactivator))\n {\n continue;\n }\n\n $this->loadWith($deactivator, [\n 'http',\n 'router',\n 'enqueue',\n 'panel',\n 'shortcode',\n 'widget'\n ]);\n }\n\n foreach (array_get($config, 'tables', []) as $table => $class)\n {\n if ( ! class_exists($class))\n {\n continue;\n }\n\n if ( ! CapsuleManager::schema()->hasTable($table))\n {\n continue;\n }\n\n CapsuleManager::schema()->table($table, function (SchemaBlueprint $table) use ($class)\n {\n $this->call($class . '@deactivate', ['table' => $table, 'app' => $this]);\n });\n }\n }\n\n /**\n * Deletes a plugin.\n *\n * @see register_uninstall_hook\n * @param $root\n */\n public function deletePlugin($root)\n {\n $plugins = array_filter($this->plugins, function (Plugin $plugin) use ($root)\n {\n return $plugin->getBasePath() === $root;\n });\n\n foreach ($plugins as $plugin)\n {\n if ( ! method_exists($plugin, 'delete'))\n {\n continue;\n }\n\n $plugin->deactivate();\n }\n\n $config = $this->getPluginConfig($root);\n\n foreach (array_get($config, 'deleters', []) as $deleter)\n {\n if ( ! file_exists($deleter))\n {\n continue;\n }\n\n $this->loadWith($deleter, [\n 'http',\n 'router',\n 'enqueue',\n 'panel',\n 'shortcode',\n 'widget'\n ]);\n }\n\n foreach (array_get($config, 'tables', []) as $table => $class)\n {\n if ( ! class_exists($class))\n {\n continue;\n }\n\n if ( ! CapsuleManager::schema()->hasTable($table))\n {\n continue;\n }\n\n CapsuleManager::schema()->table($table, function (SchemaBlueprint $table) use ($class)\n {\n $this->call($class . '@delete', ['table' => $table, 'app' => $this]);\n });\n }\n }\n\n /**\n * Loads a file with variables in scope.\n *\n * @param string $file\n * @param array $refs\n * @return void\n */\n protected function loadWith($file, $refs = [])\n {\n $container = $this;\n\n foreach ($refs as $ref)\n {\n $$ref = $this[$ref];\n }\n\n @require $file;\n }\n\n /**\n * Register all of the plugin's providers.\n *\n * @param \\Herbert\\Framework\\Plugin $plugin\n * @return void\n */\n protected function registerPluginProviders(Plugin $plugin)\n {\n $providers = array_get($plugin->getConfig(), 'providers', []);\n\n foreach ($providers as $provider)\n {\n $this->register(\n $this->resolveProviderClass($provider)\n );\n }\n }\n\n /**\n * Register all of the plugin's aliases.\n *\n * @param \\Herbert\\Framework\\Plugin $plugin\n * @return void\n */\n protected function registerPluginAliases(Plugin $plugin)\n {\n $aliases = array_get($plugin->getConfig(), 'aliases', []);\n\n foreach ($aliases as $key => $aliases)\n {\n foreach ((array) $aliases as $alias)\n {\n $this->alias($key, $alias);\n }\n }\n }\n\n // /**\n // * Register the plugin's configured requires.\n // *\n // * @param \\Herbert\\Framework\\Plugin $plugin\n // */\n // protected function registerPluginRequires(Plugin $plugin)\n // {\n // $requires = array_get($plugin->getConfig(), 'requires', []);\n // $container = $this;\n //\n // foreach ($requires as $require)\n // {\n // require \"$require\";\n // }\n // }\n\n // /**\n // * Register the plugin's configured routes.\n // *\n // * @param \\Herbert\\Framework\\Plugin $plugin\n // */\n // protected function registerPluginRoutes(Plugin $plugin)\n // {\n // $requires = array_get($plugin->getConfig(), 'routes', []);\n // $router = $this['router'];\n //\n // foreach ($requires as $require)\n // {\n // require \"$require\";\n // }\n // }\n\n // /**\n // * Register the plugin's configured shortcodes.\n // *\n // * @param \\Herbert\\Framework\\Plugin $plugin\n // */\n // protected function registerPluginShortcodes(Plugin $plugin)\n // {\n // $requires = array_get($plugin->getConfig(), 'shortcodes', []);\n // $shortcode = $this['shortcode'];\n //\n // foreach ($requires as $require)\n // {\n // require \"$require\";\n // }\n // }\n\n /**\n * Register the base providers.\n *\n * @return void\n */\n protected function registerBaseProviders()\n {\n $this->register($this->resolveProviderClass(\n 'Herbert\\Framework\\Providers\\HerbertServiceProvider'\n ));\n\n $this->register($this->resolveProviderClass(\n 'Herbert\\Framework\\Providers\\TwigServiceProvider'\n ));\n }\n\n /**\n * Register the core aliases.\n *\n * @return void\n */\n protected function registerCoreContainerAliases()\n {\n $aliases = [\n 'app' => [\n 'Illuminate\\Foundation\\Application',\n 'Illuminate\\Contracts\\Container\\Container',\n 'Illuminate\\Contracts\\Foundation\\Application'\n ]\n ];\n\n foreach ($aliases as $key => $aliases)\n {\n foreach ((array) $aliases as $alias)\n {\n $this->alias($key, $alias);\n }\n }\n }\n\n /**\n * Register all of the configured providers.\n *\n * @todo\n * @return void\n */\n public function registerConfiguredProviders()\n {\n //\n }\n\n /**\n * Register a service provider with the application.\n *\n * @param \\Illuminate\\Support\\ServiceProvider|string $provider\n * @param array $options\n * @param bool $force\n * @return \\Illuminate\\Support\\ServiceProvider\n */\n public function register($provider, $options = array(), $force = false)\n {\n if ($registered = $this->getProvider($provider) && ! $force)\n {\n return $registered;\n }\n\n // If the given \"provider\" is a string, we will resolve it, passing in the\n // application instance automatically for the developer. This is simply\n // a more convenient way of specifying your service provider classes.\n if (is_string($provider))\n {\n $provider = $this->resolveProviderClass($provider);\n }\n\n $provider->register();\n\n // Once we have registered the service we will iterate through the options\n // and set each of them on the application so they will be available on\n // the actual loading of the service objects and for developer usage.\n foreach ($options as $key => $value)\n {\n $this[$key] = $value;\n }\n\n $this->markAsRegistered($provider);\n\n // If the application has already booted, we will call this boot method on\n // the provider class so it has an opportunity to do its boot logic and\n // will be ready for any usage by the developer's application logics.\n if ($this->booted)\n {\n $this->bootProvider($provider);\n }\n\n return $provider;\n }\n\n\n /**\n * Get the registered service provider instance if it exists.\n *\n * @param \\Illuminate\\Support\\ServiceProvider|string $provider\n * @return \\Illuminate\\Support\\ServiceProvider|null\n */\n public function getProvider($provider)\n {\n $name = is_string($provider) ? $provider : get_class($provider);\n\n return array_first($this->serviceProviders, function($key, $value) use ($name)\n {\n return $value instanceof $name;\n });\n }\n\n /**\n * Resolve a service provider instance from the class name.\n *\n * @param string $provider\n * @return \\Illuminate\\Support\\ServiceProvider\n */\n public function resolveProviderClass($provider)\n {\n return $this->make($provider, ['app' => $this]);\n }\n\n /**\n * Mark the given provider as registered.\n *\n * @param \\Illuminate\\Support\\ServiceProvider\n * @return void\n */\n protected function markAsRegistered($provider)\n {\n $this->serviceProviders[] = $provider;\n\n $this->loadedProviders[get_class($provider)] = true;\n }\n\n /**\n * Load and boot all of the remaining deferred providers.\n *\n * @return void\n */\n public function loadDeferredProviders()\n {\n // We will simply spin through each of the deferred providers and register each\n // one and boot them if the application has booted. This should make each of\n // the remaining services available to this application for immediate use.\n foreach ($this->deferredServices as $service => $provider)\n {\n $this->loadDeferredProvider($service);\n }\n\n $this->deferredServices = array();\n }\n\n /**\n * Load the provider for a deferred service.\n *\n * @param string $service\n * @return void\n */\n public function loadDeferredProvider($service)\n {\n if ( ! isset($this->deferredServices[$service]))\n {\n return;\n }\n\n $provider = $this->deferredServices[$service];\n\n // If the service provider has not already been loaded and registered we can\n // register it with the application and remove the service from this list\n // of deferred services, since it will already be loaded on subsequent.\n if ( ! isset($this->loadedProviders[$provider]))\n {\n $this->registerDeferredProvider($provider, $service);\n }\n }\n\n /**\n * Register a deferred provider and service.\n *\n * @param string $provider\n * @param string $service\n * @return void\n */\n public function registerDeferredProvider($provider, $service = null)\n {\n // Once the provider that provides the deferred service has been registered we\n // will remove it from our local list of the deferred services with related\n // providers so that this container does not try to resolve it out again.\n if ($service) unset($this->deferredServices[$service]);\n\n $this->register($instance = new $provider($this));\n\n if ( ! $this->booted)\n {\n $this->booting(function() use ($instance)\n {\n $this->bootProvider($instance);\n });\n }\n }\n\n /**\n * Resolve the given type from the container.\n *\n * (Overriding Container::make)\n *\n * @param string $abstract\n * @param array $parameters\n * @return mixed\n */\n public function make($abstract, Array $parameters = array())\n {\n $abstract = $this->getAlias($abstract);\n\n if (isset($this->deferredServices[$abstract]))\n {\n $this->loadDeferredProvider($abstract);\n }\n\n return parent::make($abstract, $parameters);\n }\n\n /**\n * Determine if the given abstract type has been bound.\n *\n * (Overriding Container::bound)\n *\n * @param string $abstract\n * @return bool\n */\n public function bound($abstract)\n {\n return isset($this->deferredServices[$abstract]) || parent::bound($abstract);\n }\n\n /**\n * Determine if the application has booted.\n *\n * @return bool\n */\n public function isBooted()\n {\n return $this->booted;\n }\n\n /**\n * Boot the application's service providers.\n *\n * @return void\n */\n public function boot()\n {\n if ($this->booted) return;\n\n // Once the application has booted we will also fire some \"booted\" callbacks\n // for any listeners that need to do work after this initial booting gets\n // finished. This is useful when ordering the boot-up processes we run.\n $this->fireAppCallbacks($this->bootingCallbacks);\n\n array_walk($this->serviceProviders, function ($p)\n {\n $this->bootProvider($p);\n });\n\n array_walk($this->plugins, function ($p)\n {\n if ( ! method_exists($p, 'boot'))\n {\n return;\n }\n\n $this->call([$p, 'boot'], ['app' => $this]);\n });\n\n if (count($this->mismatched) !== 0)\n {\n $this->notifyMismatched();\n }\n\n $this->booted = true;\n\n $this->fireAppCallbacks($this->bootedCallbacks);\n }\n\n /**\n * Boot the given service provider.\n *\n * @param \\Illuminate\\Support\\ServiceProvider $provider\n * @return mixed\n */\n protected function bootProvider(ServiceProvider $provider)\n {\n if (method_exists($provider, 'boot'))\n {\n return $this->call([$provider, 'boot']);\n }\n\n return null;\n }\n\n /**\n * Register a new boot listener.\n *\n * @param mixed $callback\n * @return void\n */\n public function booting($callback)\n {\n $this->bootingCallbacks[] = $callback;\n }\n\n /**\n * Register a new \"booted\" listener.\n *\n * @param mixed $callback\n * @return void\n */\n public function booted($callback)\n {\n $this->bootedCallbacks[] = $callback;\n\n if ($this->isBooted()) $this->fireAppCallbacks(array($callback));\n }\n\n /**\n * Call the booting callbacks for the application.\n *\n * @param array $callbacks\n * @return void\n */\n protected function fireAppCallbacks(array $callbacks)\n {\n foreach ($callbacks as $callback)\n {\n call_user_func($callback, $this);\n }\n }\n\n /**\n * Get all the view globals.\n *\n * @return array\n */\n public function getViewGlobals()\n {\n if ($this->builtViewGlobals === null)\n {\n $this->buildViewGlobals();\n }\n\n return $this->builtViewGlobals;\n }\n\n /**\n * Builds the view globals.\n *\n * @return void\n */\n protected function buildViewGlobals()\n {\n $globals = [];\n\n foreach ($this->viewGlobals as $global)\n {\n list($key, $val) = $global;\n\n try {\n $val = $this->call($val, ['app' => $this]);\n }\n catch (\\Exception $e)\n {\n if ((is_numeric($key) || $key === null) && is_string($val))\n {\n continue;\n }\n }\n\n if ($key !== null)\n {\n $val = [$key => $val];\n }\n\n $val = (array) $val;\n\n $globals = array_merge($globals, $val);\n }\n\n foreach ($this->apis as $api)\n {\n list($name, $instance) = $api;\n\n $globals[$name] = $instance;\n }\n\n $this->builtViewGlobals = $globals;\n }\n\n /**\n * Get the view globals.\n *\n * @param string $view\n * @return array\n */\n public function getViewsGlobals($view)\n {\n $globals = [];\n\n foreach ($this->viewComposers as $match => $composers)\n {\n if ( ! str_is($match, $view))\n {\n continue;\n }\n\n foreach ($composers as $composer)\n {\n if (is_array($composer))\n {\n $globals = array_merge($globals, $composer);\n\n continue;\n }\n\n $globals = array_merge((array) $this->call($composer, ['app' => $this, 'view' => $view]));\n }\n }\n\n return $globals;\n }\n\n /**\n * Sets the view globals.\n *\n * @param array $globals\n */\n public function setViewGlobals($globals)\n {\n $this->viewGlobals = $globals;\n }\n\n /**\n * Get the version number of the application.\n *\n * @return string\n */\n public function version()\n {\n return static::VERSION;\n }\n\n /**\n * Get or check the current application environment.\n *\n * @param mixed\n * @return string\n */\n public function environment()\n {\n if (func_num_args() > 0)\n {\n $patterns = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();\n\n foreach ($patterns as $pattern)\n {\n if (str_is($pattern, $this['env']))\n {\n return true;\n }\n }\n\n return false;\n }\n\n return $this['env'];\n }\n\n /**\n * Determine if the application is currently down for maintenance.\n *\n * @todo\n * @return bool\n */\n public function isDownForMaintenance()\n {\n return false;\n }\n\n /**\n * Get the global container instance.\n *\n * @return static\n */\n public static function getInstance()\n {\n if (is_null(static::$instance))\n {\n static::$instance = new static;\n }\n\n return static::$instance;\n }\n\n /**\n * Get the path to the cached \"compiled.php\" file.\n *\n * @return string\n */\n public function getCachedCompilePath()\n {\n return $this->basePath() . '/vendor/compiled.php';\n }\n\n /**\n * Get the path to the cached services.json file.\n *\n * @return string\n */\n public function getCachedServicesPath()\n {\n return $this->basePath() . '/vendor/services.json';\n }\n\n }\n"},{"_id":"6aff7d1375244ca22a0000f8","treeId":"6afda28602bef4c8ff000461","seq":7851720,"position":1,"parentId":"6aff499302bef4c8ff000478","content":"`base/`"},{"_id":"6aff7d6d75244ca22a0000f9","treeId":"6afda28602bef4c8ff000461","seq":7851722,"position":2,"parentId":"6aff499302bef4c8ff000478","content":"`models/`"},{"_id":"6aff7dde75244ca22a0000fa","treeId":"6afda28602bef4c8ff000461","seq":7851724,"position":3,"parentId":"6aff499302bef4c8ff000478","content":"`providers/`"}],"tree":{"_id":"6afda28602bef4c8ff000461","name":"Herbert","publicUrl":"6afda28602bef4c8ff000461"}}