FOF30\Factory\Scaffolding\Layout\Builder::make PHP Метод

make() публичный Метод

Make a new scaffolding document
public make ( string $requestedFilename, string $viewName ) : string | null
$requestedFilename string The requested filename, e.g. form.default.xml
$viewName string The name of the view this form will be used to render
Результат string | null The XML source or null if we can't make a scaffolding XML
    public function make($requestedFilename, $viewName)
    {
        // Initialise
        $this->xml = null;
        $this->strings = array();
        // The requested filename should be in the format "form.SOMETHING.xml"
        if (substr($requestedFilename, 0, 5) !== 'form.') {
            return null;
        }
        // Get the requested form type
        $formType = substr($requestedFilename, 5);
        // Make sure the requested form type is supported by this builder
        if (!in_array($formType, array('default', 'form', 'item'))) {
            return null;
        }
        switch ($formType) {
            default:
            case 'default':
                $builderType = 'Browse';
                break;
            case 'form':
                $builderType = 'Form';
                break;
            case 'item':
                $builderType = 'Item';
                break;
        }
        // Get the model
        $model = $this->container->factory->model($viewName);
        // Create the scaffolding object and build the XML file
        $className = 'FOF30\\Factory\\Scaffolding\\Layout\\' . $builderType . 'Erector';
        /** @var ErectorInterface $erector */
        $erector = new $className($this, $model, $viewName);
        $erector->build();
        if ($this->saveScaffolding) {
            $this->saveXml($requestedFilename, $viewName);
            $this->saveStrings();
        }
        $this->applyStrings();
        return $this->xml->asXML();
    }

Usage Example

Пример #1
0
 /**
  * Create the xml file for a give view type
  * @param  string $view      The view name
  * @param  string $viewType  The type of the view (default, form, item)
  * @param  boolean $backend   If it's for the backend
  *
  * @return string            The xml generated
  *
  * @throws \Exception Can throw exceptions. @see LayoutBuilder
  */
 protected function createViewFile($view, $viewType, $backend)
 {
     // Let's force the use of the Magic Factory
     $container = Container::getInstance($this->component, array('factoryClass' => 'FOF30\\Factory\\MagicFactory'));
     $container->factory->setSaveScaffolding(true);
     // plural / singular
     if ($viewType != 'default') {
         $view = $container->inflector->singularize($view);
     }
     // Small trick: being in the CLI, the builder always tries to build in the frontend
     // Let's switch paths :)
     $originalFrontendPath = $container->frontEndPath;
     $originalBackendPath = $container->backEndPath;
     $container->frontEndPath = $backend ? $container->backEndPath : $container->frontEndPath;
     $scaffolding = new LayoutBuilder($container);
     $return = $scaffolding->make('form.' . $viewType, $view);
     // And switch them back!
     $container->frontEndPath = $originalFrontendPath;
     $container->backEndPath = $originalBackendPath;
     return $return;
 }
All Usage Examples Of FOF30\Factory\Scaffolding\Layout\Builder::make