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'
);
}
}
namespace App;
use Stillat\Dagger\Compiler\EnableOptimization;
class MyAwesomeClass
{
#[EnableOptimization]
public static function myHelper()
{
}
}
namespace App;
use Stillat\Dagger\Compiler\EnableOptimization;
#[EnableOptimization]
class MyAwesomeClass
{
public static function myHelper()
{
}
}
namespace App;
use Stillat\Dagger\Compiler\DisableOptimization;
use Stillat\Dagger\Compiler\EnableOptimization;
#[EnableOptimization]
class MyAwesomeClass
{
public static function methodOne()
{
// Optimization allowed.
}
#[DisableOptimization]
public static function methodTwo()
{
// Optimization not allowed.
}
}
use Stillat\Dagger\Facades\Compiler;
Compiler::compileComponent('c:mycomponent', function ($node) {
return 'My Component';
});
use Stillat\Dagger\Facades\Compiler;
Compiler::compileComponent('c:mycomponent', function ($node, $innerContent) {
return '<div class="simple-wrapper">'.$innerContent.'</div>';
});
use Illuminate\Support\Str;
use Stillat\Dagger\Facades\Compiler;
Compiler::compileComponent('c:stack:*', function ($node) {
$stackName = Str::after($node->tagName, ':');
// ...
});