Pink-Crab / Perique-Framework

The Perqiue Plugin Framework for WordPress
5 stars 0 forks source link

Components with fully resolved paths still being concatinated #182

Closed gin0115 closed 10 months ago

gin0115 commented 10 months ago

When a component has a defined path using the Alias hook, sometimes this path is added to the base path.

to fix this, update the component() method in PHP Engine to

/**
 * Renders a component.
 *
 * @param Component $component
 * @return string
 */
public function component( Component $component, bool $print = true ): ?string {

    // Throw exception of no compiler passed.
    if ( ! Object_Helper::is_a( $this->component_compiler, Component_Compiler::class ) ) {
        throw new Exception( 'No component compiler passed to PHP_Engine' );
    }

    // Compile the component.
    $compiled = $this->component_compiler->compile( $component ); // @phpstan-ignore-line, checked above.
    $template = $compiled->template();

    $view     = file_exists( $template )
        ? $template
        : sprintf( '%s%s%s.php', $this->base_view_path, \DIRECTORY_SEPARATOR, trim( $this->maybe_resolve_dot_notation( $template ) ) );

    if ( $print ) {
        print( $this->render_buffer( $view, $compiled->data() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        return null;
    } else {
        return $this->render_buffer( $view, $compiled->data() );
    }
}
gin0115 commented 10 months ago

this will check if the path exists, if it does then we do not need to resolve dot notiation either