Inheritance: extends Illuminate\Container\Container
コード例 #1
0
ファイル: AssetFactory.php プロジェクト: themosis/framework
 /**
  * Add an asset to the application.
  *
  * NOTE : By default the path is relative to one of the registered
  * paths. Make sure your asset is unique by handle and paths/url.
  * You can also pass an external url.
  *
  * @param string      $handle  The asset handle name.
  * @param string      $path    The URI to the asset or the absolute URL.
  * @param array|bool  $deps    An array with asset dependencies or false.
  * @param string      $version The version of your asset.
  * @param bool|string $mixed   Boolean if javascript file | String if stylesheet file.
  * @param string      $type    'script' or 'style'.
  *
  * @return Asset|\WP_Error
  *
  * @throws AssetException
  */
 public function add($handle, $path, $deps = [], $version = '1.0', $mixed = null, $type = '')
 {
     if (!is_string($handle) && !is_string($path)) {
         throw new AssetException('Invalid parameters for [Asset::add] method.');
     }
     // Init type.
     $t = '';
     // Get full URL for the asset.
     $path = $this->finder->find($path);
     // Group arguments.
     $args = compact('handle', 'path', 'deps', 'version', 'mixed');
     // Get file extension.
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     // Define the asset type.
     if (!empty($type) && in_array($type, $this->allowedAssets)) {
         $t = $type;
     } elseif ($ext) {
         $t = $ext === 'css' ? 'style' : 'script';
     }
     /*
      * Check the asset type is defined.
      */
     if (empty($t)) {
         return new \WP_Error('asset', sprintf('%s: %s. %s', __("Can't load your asset", THEMOSIS_FRAMEWORK_TEXTDOMAIN), $handle, __('If your asset has no file extension, please provide the type parameter.', THEMOSIS_FRAMEWORK_TEXTDOMAIN)));
     }
     // Register the asset into the service container
     // and return it for chaining.
     // Assets are shared, so only one instance of each is available
     // into the container.
     // Assets are registered using the 'asset' prefix followed
     // by their unique asset handle: 'asset.unique-handle'
     $asset = new Asset($t, $args, $this->container['action'], $this->container['html'], $this->container['filter']);
     $this->container->instance($this->aliasPrefix . '.' . $handle, $asset);
     return $asset;
 }
コード例 #2
0
ファイル: themosis.php プロジェクト: themosis/framework
 /**
  * Register core framework service providers.
  */
 protected function registerProviders()
 {
     /*
      * Service providers.
      */
     $providers = apply_filters('themosis_service_providers', [Themosis\Ajax\AjaxServiceProvider::class, Themosis\Asset\AssetServiceProvider::class, Themosis\Config\ConfigServiceProvider::class, Themosis\Database\DatabaseServiceProvider::class, Themosis\Field\FieldServiceProvider::class, Themosis\Finder\FinderServiceProvider::class, Themosis\Hook\HookServiceProvider::class, Themosis\Html\FormServiceProvider::class, Themosis\Html\HtmlServiceProvider::class, Themosis\Load\LoaderServiceProvider::class, Themosis\Metabox\MetaboxServiceProvider::class, Themosis\Page\PageServiceProvider::class, Themosis\Page\Sections\SectionServiceProvider::class, Themosis\PostType\PostTypeServiceProvider::class, Themosis\Route\RouteServiceProvider::class, Themosis\Taxonomy\TaxonomyServiceProvider::class, Themosis\User\UserServiceProvider::class, Themosis\Validation\ValidationServiceProvider::class, Themosis\View\ViewServiceProvider::class]);
     foreach ($providers as $provider) {
         $this->container->register($provider);
     }
 }
コード例 #3
0
 /**
  * Set the custom taxonomy. A user can also override the
  * arguments by passing an array of taxonomy arguments.
  *
  * @link http://codex.wordpress.org/Function_Reference/register_taxonomy
  *
  * @param array $params Taxonomy arguments to override defaults.
  *
  * @return \Themosis\Taxonomy\TaxonomyBuilder
  */
 public function set(array $params = [])
 {
     // Override custom taxonomy arguments if given.
     $this->datas['args'] = array_replace_recursive($this->datas['args'], $params);
     // Trigger the 'init' event in order to register the custom taxonomy.
     // Check if we are not already called by a method attached to the `init` hook.
     $current = current_filter();
     if ('init' === $current) {
         // If inside an `init` action, simply call the register method.
         $this->register();
     } else {
         // Out of an `init` action, call the hook.
         $this->action->add('init', [$this, 'register']);
     }
     // Register each custom taxonomy instance into the container.
     $this->container->instance($this->prefix . '.' . $this->datas['name'], $this);
     return $this;
 }
コード例 #4
0
ファイル: Hook.php プロジェクト: themosis/framework
 /**
  * Build the array in order to call a class method.
  *
  * @param string $class
  * @param string $hook
  *
  * @return array
  */
 protected function buildClassEventCallback($class, $hook)
 {
     list($class, $method) = $this->parseClassEvent($class, $hook);
     $instance = $this->container->make($class);
     return [$instance, $method];
 }
コード例 #5
0
ファイル: helpers.php プロジェクト: themosis/framework
 /**
  * Helper function to quickly retrieve an instance.
  *
  * @param null  $abstract   The abstract instance name.
  * @param array $parameters
  *
  * @return mixed
  */
 function app($abstract = null, array $parameters = [])
 {
     if (is_null($abstract)) {
         return Application::getInstance();
     }
     return Application::getInstance()->make($abstract, $parameters);
 }