Comments (2)
Right now this does not work with vanilla PHP. But I'll bring this up internally. Can't provide guarantees however that we'll pursue this sorry. Thanks for your request!
from folio.
Thanks for taking a look @driesvints!
This commit in a demo shows a naive bare minimum of what someone would have to do currently, to get this working on their own:
It would be nice if the Laravel\Folio\Router
simply called something like Folio::pipeline()
(made up method) which by default would just return the array currently being used by the package, and if Folio
exposed a public method, (for the sake of this example called withPipeline()
) where one could (optionally) set a custom array as a property to be traversed in Laravel\Folio\Router::matchAtPath()
:
// Laravel\Folio\Router
/**
* Resolve the given URI via page based routing at the given mount path.
*/
protected function matchAtPath(string $mountPath, Request $request, string $uri): ?MatchedView
{
$state = new State(
uri: $uri,
mountPath: $mountPath,
segments: explode('/', $uri)
);
for ($i = 0; $i < $state->uriSegmentCount(); $i++) {
$value = (new Pipeline)
->send($state->forIteration($i))
- ->through([
- new EnsureNoDirectoryTraversal,
- new TransformModelBindings($request),
- new SetMountPathOnMatchedView,
- // ...
- new MatchRootIndex,
- new MatchDirectoryIndexViews,
- new MatchWildcardViewsThatCaptureMultipleSegments,
- new MatchLiteralDirectories,
- new MatchWildcardDirectories,
- new MatchLiteralViews,
- new MatchWildcardViews,
- ])->then(fn () => new StopIterating);
+ ->through(Folio::pipeline())
+ ->then(fn () => new StopIterating);
if ($value instanceof MatchedView) {
return $value;
} elseif ($value instanceof ContinueIterating) {
$state = $value->state;
continue;
} elseif ($value instanceof StopIterating) {
break;
}
}
return null;
}
//Laravel\Folio\FolioManager
public array $pipeline = [];
public function withPipeline(array $pipeline)
{
$this->pipeline = $pipeline;
return $this;
}
public function pipeline() : array
{
return !empty($this->pipeline) ?
$this->pipeline :
[
// default pipeline array
new EnsureNoDirectoryTraversal,
new TransformModelBindings($request),
new SetMountPathOnMatchedView,
// ...
new MatchRootIndex,
new MatchDirectoryIndexViews,
new MatchWildcardViewsThatCaptureMultipleSegments,
new MatchLiteralDirectories,
new MatchWildcardDirectories,
new MatchLiteralViews,
new MatchWildcardViews,
];
}
which would give the option of passing custom array to the router in the service provider:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Laravel\Folio\Folio;
class FolioServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}
/**
* Bootstrap services.
*/
public function boot(): void
{
Folio::withPipeline([
new EnsureNoDirectoryTraversal,
new TransformModelBindings($request),
new SetMountPathOnMatchedView,
// ...
new \App\MatchPhpOrMarkdownRootIndex, // < --- custom class
new MatchDirectoryIndexViews,
new MatchWildcardViewsThatCaptureMultipleSegments,
new MatchLiteralDirectories,
new MatchWildcardDirectories,
new MatchLiteralViews,
new MatchWildcardViews,
])->route(resource_path('views/pages'), middleware: [
'*' => [
//
],
]);
}
}
from folio.
Related Issues (20)
- The shared variable in the `render` function can not be accessed between `@php` and `@endphp` directives HOT 1
- Default route name HOT 1
- Create paths automatically when not exists HOT 2
- `index` blade file with deeply nested model route binding not working HOT 3
- Support for Other HTTP Methods HOT 8
- Folio should work with other template engines (like Twig) HOT 1
- name route function is not working in folio HOT 1
- Nested model route binding disables views HOT 3
- Nested model route binding keeps disabling views HOT 3
- Empty segments in multi-segment wildcard views are not possible HOT 1
- Wildcard route collision HOT 6
- Route model binding connection HOT 4
- Missing URI prefix when calling `php artisan folio:list` HOT 1
- domain() works with only one domain. HOT 5
- Can't generate url route which starts with "/index" HOT 2
- Problem with subdomain HOT 1
- Session not set in Global Scope HOT 3
- Folio Route Fallback HOT 8
- allow custom route registrar action for volt HOT 2
- Support Fragment directive
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from folio.