クラス
VueComponentLoader
ソース ソース
ファイル: src/Components/VueComponentLoader.php
class VueComponentLoader implements JsonSerializable
{
    /**
     * Vue component object
     *
     * @var VueComponent
     */
    private $component;
    /**
     * Whether to load the component or not
     *
     * @var bool
     */
    private $load;
    /**
     * Constructs a loader object
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @param VueComponent $component
     * @param bool         $load
     * @return void
     */
    public function __construct(VueComponent $component, $load) {
        $this->component = $component;
        $this->load = $load;
        if ($this->load === true) {
            $this->component->init();
        }
    }
    /**
     * Returns `true` if component should be loaded, `false` otherwise.
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @return bool
     */
    public function shouldLoad() {
        return $this->load;
    }
    /**
     * Returns `VueComponent` instance.
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @return VueComponent
     */
    public function getComponent() {
        return $this->component;
    }
    /**
     * Displays component template if `load` is true
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @return void
     */
    public function templateIfLoad() {
        if ($this->load === true) {
            $this->component->template();
        }
    }
    /**
     * Returns JSON representation of this object
     *
     * Useful for passing component meta data to JavaScript
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @return array
     */
    public function jsonSerialize() {
        return [
            'name' => $this->component->getComponentName(),
            'load' => $this->load,
        ];
    }
}
- __construct — Constructs a loader object
 - getComponent — Returns `VueComponent` instance.
 - jsonSerialize — Returns JSON representation of this object
 - shouldLoad — Returns `true` if component should be loaded, `false` otherwise.
 - templateIfLoad — Displays component template if `load` is true