⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Migrate Laravel View#304

Open
bluehaha wants to merge 50 commits intohypervel:mainfrom
bluehaha:feature/view
Open

Migrate Laravel View#304
bluehaha wants to merge 50 commits intohypervel:mainfrom
bluehaha:feature/view

Conversation

@bluehaha
Copy link
Contributor

@bluehaha bluehaha commented Dec 22, 2025

Breaking Change

- use Hyperf\ViewEngine\Contract\FactoryInterface
+ use Hypervel\View\Contracts\Factory as FactoryInterface
-use Hyperf\ViewEngine\Contract\ViewInterface;
+use Hypervel\View\Contracts\View as ViewInterface

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Laravel View functionality to Hypervel, including comprehensive test coverage for Blade compilation, view components, and the view engine system. The migration includes test fixtures, unit tests for various Blade directives and features, and core source files for the view service provider, view name normalization, and engine implementations.

Key Changes:

  • Added comprehensive test suite covering Blade compilation features (150+ test files)
  • Implemented ViewServiceProvider for dependency injection and service registration
  • Added ViewName class for view name normalization
  • Created ViewFinderInterface defining the view finder contract
  • Implemented ViewException for view-specific error handling
  • Added ShareErrorsFromSession middleware for error handling
  • Implemented FileEngine for raw file rendering

Reviewed changes

Copilot reviewed 150 out of 151 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/View/fixtures/* Test fixture files for view rendering tests
tests/View/ViewTest.php Unit tests for View class functionality
tests/View/ViewPhpEngineTest.php Tests for PHP engine
tests/View/ViewFileViewFinderTest.php Tests for file view finder
tests/View/ViewFactoryTest.php Comprehensive tests for view factory
tests/View/ViewEngineResolverTest.php Tests for engine resolver
tests/View/ViewComponentTest.php Tests for view components
tests/View/ViewComponentAttributeBagTest.php Tests for component attributes
tests/View/ViewCompilerEngineTest.php Tests for compiler engine
tests/View/ViewBladeCompilerTest.php Tests for Blade compiler
tests/View/ComponentTest.php Component integration tests
tests/View/Blade/* Extensive Blade directive compilation tests
src/view/src/ViewServiceProvider.php Service provider for view system
src/view/src/ViewName.php View name normalization utility
src/view/src/ViewFinderInterface.php Interface for view finding
src/view/src/ViewException.php Custom exception for views
src/view/src/Middleware/ShareErrorsFromSession.php Middleware for error sharing
src/view/src/Engines/FileEngine.php File-based rendering engine

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


protected function enableHttpMethodParameterOverride(): bool
{
return $this->container->get(ConfigInterface::class)->get('view.enable_override_http_method', false);
Copy link
Member

@albertcht albertcht Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should cache this value to prevent getting from config instance at each time.

/**
* The Content Security Policy nonce context key.
*/
protected const NONCE_CONTEXT_KEY = 'hypervel.vite.nonce';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if only these three properties should be isolated with context

Copy link
Contributor Author

@bluehaha bluehaha Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yap, the other properties are configuration-related, and all requests should share the same configuration, so there's no need to isolate with content.

{
$id = $id ? $this->stripParentheses($id) : "'" . (string) Str::uuid() . "'";

return '<?php if (! $__env->hasRenderedOnce(' . $id . ')): $__env->markAsRenderedOnce(' . $id . '); ?>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just leave a note for myself to verify everything called from the view factory should be context-isolated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 84 of src/view/src/Factory.php, the __env variable is save a as Factory instance.

$this->share('__env', $this);

Then on line 165 of src/view/src/View.php, all shared data is retrieved.

protected function getContents(): string
{
    return $this->engine->get($this->path, $this->gatherData());
}

/**
 * Get the data bound to the view instance.
 */
public function gatherData(): array
{
    $data = array_merge($this->factory->getShared(), $this->data);

    ...

    return $data;
}

@binaryfire
Copy link
Contributor

Hi guys. It’d be great to include this new PR as well:
laravel/framework#58311

};

$view = Container::getInstance()
->make(ViewFactory::class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use get instead?

return $view->toHtml();
}
return Container::getInstance()
->make(ViewFactory::class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use get instead?

*/
public function guessClassName(string $component): string
{
$namespace = Container::getInstance()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can cache $namespace

// the instance out of the IoC container and call the method on it with the
// given arguments that are passed to the Closure as the composer's data.
return function () use ($class, $method) {
return $this->container->make($class)->{$method}(...func_get_args());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use get here?

*/
public function callCreator(ViewContract $view): void
{
if ($this->getContainer()->get(ConfigInterface::class)->get('view.event.enable', false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache this config valie

*/
public function renderTranslation(): string
{
return $this->container->make('translator')->get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use get here?

- Cache HTTP method override flag in Kernel to avoid repeated config lookups
- Cache ComponentTagCompiler instance in BladeCompiler for reuse
- Cache application namespace in ComponentTagCompiler
- Cache view event enabled flag in ManagesEvents trait
- Replace container->make() with container->get() for singleton resolution
@bluehaha
Copy link
Contributor Author

bluehaha commented Feb 4, 2026

@binaryfire thx for your advice. I will find time to handle it this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants