/**
  * Bootstrap any application services.
  * @return void
  */
 public function boot()
 {
     /**
      * <component name="App\HTMLComponentClass">Content</component>
      */
     HTMLProcessor::register('component', function ($node, $processor) {
         $class = null;
         $name = $node->name;
         $possibilities = [$name, "App\\Components\\{$name}", "Birdmin\\Components\\{$name}"];
         foreach ($possibilities as $className) {
             if (class_exists($className)) {
                 $class = $className;
                 break;
             }
         }
         if (!$class) {
             throw new \Exception("Component class '{$name}' does not exist");
         }
         if (!has_contract($class, HTMLComponent::class)) {
             throw new \Exception("Component class '{$class}' does not implement the HTMLComponent contract");
         }
         $component = $class::create($processor->getModel(), $node);
         // Replace the contents of the node with the component view.
         $node->innertext = $component->render();
     });
 }
Ejemplo n.º 2
0
 /**
  * Use an action handle to quickly set up this button with common properties.
  * @param $name string action name
  * @return $this|null
  */
 protected function setupAction($name)
 {
     if (!$name || !array_key_exists($name, $this->actions)) {
         return null;
     }
     list($label, $url, $icon) = $this->actions[$name];
     $this->label = stringf($label, $this->parentAttributes);
     $this->attribute('href', cms_url(stringf($url, $this->parentAttributes)));
     $this->icon = stringf($icon, $this->parentAttributes);
     // Check if the specific action has a CSS class it normally uses.
     if (isset($this->actionClass[$name])) {
         $this->classes($this->actionClass[$name]);
     }
     // If the parent doesn't adhere to the contract, don't render it.
     if (isset($this->contracts[$name])) {
         $this->canRender = has_contract($this->parent, $this->contracts[$name]);
     }
     return $this;
 }