PHP code example of stillat / dagger
1. Go to this page and download the library: Download stillat/dagger library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stillat / dagger example snippets
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Stillat\Dagger\Facades\Compiler;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Compiler::registerComponentPath(
'c',
resource_path('views/components')
);
}
}
namespace App\Mixins;
class ThemeData
{
public function data(): array
{
return [
'background' => 'bg-indigo-500',
];
}
}
namespace App\Mixins;
class ProfileMixin
{
public function sayHello(string $name): string
{
return "Hello, {$name}.";
}
}
namespace App\Mixins;
use Illuminate\Support\Str;
use Stillat\Dagger\Runtime\Component;
class ComponentMixin
{
protected ?Component $component = null;
public function withComponent(Component $component): void
{
$this->component = $component;
}
public function data(): array
{
return [
'name_upper' => Str::upper($this->component->name),
];
}
}
namespace Your\Package\Namespace;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
use Stillat\Dagger\Facades\Compiler;
class ServiceProvider extends IlluminateServiceProvider
{
public function boot(): void
{
Compiler::registerComponentPath(
'lenz',
__DIR__.'./../path/to/component/views'
);
}
}
blade
<!-- /resources/dagger/views/alert.blade.php -->
@props(['type' => 'info', 'message'])
<div {{ $attributes->merge(['class' => 'alert alert-'.$type]) }}>
{{ $message }}
</div>
blade
<!-- /resources/views/layout.blade.php -->
<c-alert type="error" :message="$message" class="mb-4"/>
bash
php artisan dagger:install
text
/resources/dagger/views/accordion.blade.php
/resources/dagger/views/accordion/item.blade.php
text
/resources/dagger/views/accordion/accordion.blade.php
/resources/dagger/views/accordion/item.blade.php
text
/resources/dagger/views/accordion/index.blade.php
/resources/dagger/views/accordion/item.blade.php
blade
@php
use function Stillat\Dagger\component;
component()->props(['type' => 'info', 'message']);
@endphp
<div {{ $attributes->merge(['class' => 'alert alert-'.$type]) }}>
{{ $message }}
</div>
blade
<!-- /resources/dagger/views/item.blade.php -->
<div {{ $attributes }}>
{{ $slot }}
</div>
blade
<!-- /resources/dagger/views/panel.blade.php -->
<div {{ $slots->header->attributes }}>
{{ $slots->header }}
</div>
{{ $slot }}
<div {{ $slots->footer->attributes }}>
{{ $slots->footer }}
</div>
blade
@php
use function Stillat\Dagger\component;
// Danger zone.
$myCustomVariable = 'the value';
component()->props(['type' => 'info', 'message']);
// Safe zone.
@endphp
<div {{ $attributes->merge(['class' => 'alert alert-'.$type]) }}>
{{ $message ?? $myCustomVariable }}
</div>
blade
@php
use function Stillat\Dagger\component;
component()->props(['type' => 'info', 'message']);
$myCustomVariable = 'the value';
@endphp
<div {{ $attributes->merge(['class' => 'alert alert-'.$type]) }}>
{{ $message ?? $myCustomVariable }}
</div>
blade
@php
use function Stillat\Dagger\component;
$theAlert = component()->props(['type' => 'info', 'message']);
@endphp
<div {{ $attributes->merge(['class' => 'alert alert-'.$theAlert->type]) }}>
{{ $theAlert->message }}
</div>
blade
<!-- /resources/dagger/views/alert.blade.php -->
@props(['type' => 'info', 'message'])
<div {{ $attributes->merge(['class' => 'alert alert-'.$type]) }}>
{{ $message }}
</div>
blade
@php
use function Stillat\Dagger\component;
component()->props(['type' => 'info', 'message']);
@endphp
<div {{ $attributes->merge(['class' => 'alert alert-'.$type]) }}>
{{ $message }}
</div>
blade
<!-- /resources/dagger/views/menu/index.blade.php -->
@props([
'color' => 'gray'
])
<ul {{ $attributes->merge(['class' => 'bg-'.$color.'-200']) }}>
{{ $slot }}
</ul>
blade
<!-- /resources/dagger/views/menu/item.blade.php -->
@aware([
'color' => 'gray'
])
<li {{ $attributes->merge(['class' => 'text-'.$color.'-800']) }}>
{{ $slot }}
</li>
blade
<!-- /resources/dagger/views/menu/item.blade.php -->
@php
Stillat\Dagger\component()->aware(['color' => 'gray']);
@endphp
<li {{ $attributes->merge(['class' => 'text-'.$color.'-800']) }}>
{{ $slot }}
</li>
blade
<!-- /resources/dagger/views/menu/item.blade.php -->
<li {{ $attributes->merge(['class' => 'text-'.$component->parent()->color.'-800']) }}>
{{ $slot }}
</li>
blade
<!-- /resources/dagger/views/menu/index.blade.php -->
@props(['color'])
<ul>
{{ $slot}}
</ul>
blade
<!-- /resources/dagger/views/button.blade.php -->
@php
use function Stillat\Dagger\component;
component()
->props(['title'])
->validateProps([
'title' => '
blade
<!-- /resources/dagger/views/button.blade.php -->
@php
use function Stillat\Dagger\component;
component()
->props(['title|
blade
<!-- /resources/dagger/views/component.blade.php -->
<c-nested.component #id="theNestedComponentName" />
blade
<!-- /resources/dagger/views/component.blade.php -->
<c-nested.component ##id="the-escaped-id-attribute" />
blade
<!-- /resources/dagger/views/button.blade.php -->
{{-- Displays "button" --}}
{{ $component->name }}
blade
<!-- /resources/dagger/views/button.blade.php -->
@php
\Stillat\Dagger\component()
->props(['text'])
->trimOutput();
@endphp
<button {{ $attributes }}>{{ $text }}</button>
blade
<!-- /resources/dagger/views/nested_one.blade.php -->
<c-nested_two #id="nestedTwo" />
blade
<!-- /resources/dagger/views/nested_two.blade.php -->
<c-nested_three #id="nestedThree" />
blade
<!-- /resources/dagger/views/nested_three.blade.php -->
@props(['title'])
{{ $title }}
blade
<!-- /resources/dagger/views/root.blade.php -->
<c-nested_one #id="componentOne" />
blade
<!-- /resources/dagger/views/nested_one.blade.php -->
<div {{ $slots->header->attributes }}>
{{ $slots->header }}
</div>
{{ $slot }}
<div {{ $slots->footer->attributes }}>
{{ $slots->footer }}
</div>
blade
<!-- /resources/dagger/views/root.blade.php -->
<c-nested_one #id="componentOne" />
blade
<!-- /resources/dagger/views/nested_one.blade.php -->
<c-nested_two #id="componentTwo" />
blade
<!-- /resources/dagger/views/nested_two.blade.php -->
<div {{ $slots->header->attributes }}>
{{ $slots->header }}
</div>
{{ $slot }}
<div {{ $slots->footer->attributes }}>
{{ $slots->footer }}
</div>
blade
<!-- /resources/dagger/views/list/index.blade.php -->
@props(['items'])
<ul>
@foreach ($items as $item)
<c-stencil:list_item>
<li>{{ $item }}</li>
</c-stencil:list_item>
@endforeach
</ul>
blade
<!-- /resources/dagger/views/mixin.blade.php -->
@php
\Stillat\Dagger\component()->mixin([
\App\Mixins\ThemeData::class,
])->props(['background']);
@endphp
<div {{ $attributes->merge(['class' => $background]) }}>
...
</div>
blade
<!-- /resources/dagger/views/profile.blade.php -->
@php
\Stillat\Dagger\component()->mixin([
\App\Mixins\ProfileMixin::class,
])->props(['name']);
@endphp
<div>
{{ $sayHello($name) }}
</div>
blade
<!-- /resources/dagger/views/profile.blade.php -->
@php
\Stillat\Dagger\component()->mixin([
\App\Mixins\ProfileMixin::class,
])->props(['name']);
@endphp
<div>
{{ $component->sayHello($name) }}
</div>
blade
<!-- /resources/dagger/views/component.blade.php -->
@php
\Stillat\Dagger\component()->mixin([
\App\Mixins\ComponentMixin::class,
]);
@endphp
<div>
{{ $name_upper }}
</div>
blade
<!-- /resources/dagger/views/cached.blade.php -->
@php
\Stillat\Dagger\component()
->props(['title'])
->cache();
@endphp
{{ $title }}
blade
<!-- /resources/dagger/views/time.blade.php -->
@php
\Stillat\Dagger\component()
->cache();
@endphp
{{ time() }}
blade
<c-time />
<c-time />
<c-time />
html
<!-- /resources/dagger/views/footer.blade.php -->
<footer>
...
</footer>