Overview

Namespaces

  • Charcoal
    • App
      • Action
      • Config
      • Handler
      • Middleware
      • Module
      • Route
      • Script
      • ServiceProvider
      • Template

Classes

  • Charcoal\App\Action\AbstractAction
  • Charcoal\App\App
  • Charcoal\App\AppConfig
  • Charcoal\App\AppContainer
  • Charcoal\App\Config\CacheConfig
  • Charcoal\App\Config\DatabaseConfig
  • Charcoal\App\Config\FilesystemConfig
  • Charcoal\App\Config\LoggerConfig
  • Charcoal\App\Config\MemcacheCacheConfig
  • Charcoal\App\Config\MemcacheCacheServerConfig
  • Charcoal\App\Handler\AbstractHandler
  • Charcoal\App\Handler\Error
  • Charcoal\App\Handler\HandlerConfig
  • Charcoal\App\Handler\NotAllowed
  • Charcoal\App\Handler\NotFound
  • Charcoal\App\Handler\PhpError
  • Charcoal\App\Handler\Shutdown
  • Charcoal\App\Middleware\CacheMiddleware
  • Charcoal\App\Module\AbstractModule
  • Charcoal\App\Module\ModuleConfig
  • Charcoal\App\Module\ModuleManager
  • Charcoal\App\Route\ActionRoute
  • Charcoal\App\Route\ActionRouteConfig
  • Charcoal\App\Route\RouteConfig
  • Charcoal\App\Route\RouteManager
  • Charcoal\App\Route\ScriptRoute
  • Charcoal\App\Route\ScriptRouteConfig
  • Charcoal\App\Route\TemplateRoute
  • Charcoal\App\Route\TemplateRouteConfig
  • Charcoal\App\Script\AbstractScript
  • Charcoal\App\ServiceProvider\AppServiceProvider
  • Charcoal\App\ServiceProvider\CacheServiceProvider
  • Charcoal\App\ServiceProvider\DatabaseServiceProvider
  • Charcoal\App\ServiceProvider\FilesystemServiceProvider
  • Charcoal\App\ServiceProvider\LoggerServiceProvider
  • Charcoal\App\ServiceProvider\ViewServiceProvider
  • Charcoal\App\Template\AbstractTemplate
  • Charcoal\App\Template\AbstractWidget
  • Charcoal\App\Template\WidgetBuilder

Interfaces

  • Charcoal\App\Action\ActionInterface
  • Charcoal\App\AppAwareInterface
  • Charcoal\App\Handler\HandlerInterface
  • Charcoal\App\Module\ModuleInterface
  • Charcoal\App\Route\RouteInterface
  • Charcoal\App\Script\CronScriptInterface
  • Charcoal\App\Script\ScriptInterface
  • Charcoal\App\Template\TemplateInterface
  • Charcoal\App\Template\WidgetInterface

Traits

  • Charcoal\App\AppAwareTrait
  • Charcoal\App\CallableResolverAwareTrait
  • Charcoal\App\Script\ArgScriptTrait
  • Charcoal\App\Script\CronScriptTrait
  • Charcoal\App\Script\PathScriptTrait
  • Overview
  • Namespace
  • Class
 1: <?php
 2: 
 3: namespace Charcoal\App\Template;
 4: 
 5: use InvalidArgumentException;
 6: 
 7: // From Pimple
 8: use Pimple\Container;
 9: 
10: // From 'charcoal-factory'
11: use Charcoal\Factory\FactoryInterface;
12: 
13: /**
14:  * Build widgets from config, with a WidgetFactory
15:  */
16: class WidgetBuilder
17: {
18:     /**
19:      * @var FactoryInterface $factory
20:      */
21:     protected $factory;
22: 
23:     /**
24:      * A Pimple dependency-injection container to fulfill the required services.
25:      * @var Container $container
26:      */
27:     protected $container;
28: 
29:     /**
30:      * @param FactoryInterface $factory   An object factory.
31:      * @param Container        $container The DI container.
32:      */
33:     public function __construct(FactoryInterface $factory, Container $container)
34:     {
35:         $this->factory = $factory;
36:         $this->container = $container;
37:     }
38: 
39:     /**
40:      * @param  array|\ArrayAccess $options The form group build options / config.
41:      * @throws InvalidArgumentException If the widget is invalid.
42:      * @return WidgetInterface The "built" widget object.
43:      */
44:     public function build($options)
45:     {
46:         if (isset($options['controller'])) {
47:             $objType = $options['controller'];
48:         } elseif (isset($options['type'])) {
49:             $objType = $options['type'];
50:         } else {
51:             throw new InvalidArgumentException('Undefined widget type');
52:         }
53: 
54:         $obj = $this->factory->create($objType);
55:         $obj->setData($options);
56: 
57:         return $obj;
58:     }
59: }
60: 
API documentation generated by ApiGen