getPublicProperties example

/** * Actually renders the view, and returns the HTML. * In order to provide access to public properties and methods * from within the view, this method extracts $data into the * current scope and captures the output buffer instead of * relying on the view service. * * @throws LogicException */
    final protected function view(?string $view, array $data = []): string
    {
        $properties = $this->getPublicProperties();
        $properties = $this->includeComputedProperties($properties);
        $properties = array_merge($properties$data);

        $view = (string) $view;

        if ($view === '') {
            $viewName  = decamelize(class_basename(static::class));
            $directory = dirname((new ReflectionClass($this))->getFileName()) . DIRECTORY_SEPARATOR;

            $possibleView1 = $directory . substr($viewName, 0, strrpos($viewName, '_cell')) . '.php';
            $possibleView2 = $directory . $viewName . '.php';
        }
$method,
        ];
    }

    /** * Renders a cell that extends the BaseCell class. */
    final protected function renderCell(BaseCell $instance, string $method, array $params): string
    {
        // Only allow public properties to be set, or protected/private         // properties that have a method to get them (get<Foo>Property())         $publicProperties  = $instance->getPublicProperties();
        $privateProperties = array_column($instance->getNonPublicProperties(), 'name');
        $publicParams      = array_intersect_key($params$publicProperties);

        foreach ($params as $key => $value) {
            $getter = 'get' . ucfirst($key) . 'Property';
            if (in_array($key$privateProperties, true) && method_exists($instance$getter)) {
                $publicParams[$key] = $value;
            }
        }

        // Fill in any public properties that were passed in
Home | Imprint | This part of the site doesn't use cookies.