bleicker/framework-base

该软件包最新版本(1.2.0)没有可用的许可证信息。

1.2.0 2015-04-30 06:48 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:55:37 UTC


README

此软件目前尚未准备好投入生产!它只是我的个人游乐场:)

安装

通过 composer create-project

composer create-project bleicker/framework-base

设置

SQL 设置

cp Configuration/Secrets.Example.php Configuration/Secrets.php

运行 CLI 命令以创建数据库和所需表

vendor/bin/doctrine orm:schema-tool:update --force --dump-sql

启动开发或生产环境中的 PHP 服务器进程

生产

CONTEXT=production nohup php -S localhost:8001 -t Public >> /dev/null 2>&1 &

开发

nohup php -S localhost:8000 -t Public >> /dev/null 2>&1 &

打开浏览器并访问开发服务器生产服务器

切换到 MySQL

如果您想使用 MySQL 而不是 SQLite,请在 Secrets.php 中调整驱动程序,例如:

['url' => 'mysql://user:secret@localhost/mydb']

然后运行

vendor/bin/doctrine orm:schema-tool:update --force --dump-sql

Doctrine 映射

为了持久化,使用了 Doctrine。默认情况下,我正在使用它的 yml 配置来绑定模型和映射信息。只需将您的 yaml 配置添加到 Configuration/Schema/Persistence/ 文件夹中。然后使用 doctrine 命令行刷新您的数据库。

vendor/bin/doctrine orm:schema-tool:update --force --dump-sql

查看 Doctrine 文档

路由

查看 Configuration/Routing.php 以获取一些引入新路由的小示例。

查看 FastRoute 文档

模板

我引入了 namelesscoder 的无命名分离版本作为默认模板引擎。模板位于 "Templates" 文件夹中,并由调用的 Controller::Action 的命名空间解析。 查看 Fluid 文档

您的应用内容

您的 Controllers/Services/DomainModels 等内容的好位置是 "App" 文件夹

注册表

添加一些内容

Registry::add('foo.bar.baz', 'Hello World');

在您的代码的任何地方获取注册表条目

Registry::get('foo.bar.baz');

对象管理器

添加对象

ObjectManager::register(MyClassInterface::class, new MyClass('foo', 'bar'));

使用以下方式在您的代码的任何地方获取对象

ObjectManager::get(MyClassInterface::class);
将闭包注册为工厂

添加闭包

ObjectManager::register(MyClassInterface::class, function(){new MyClass()});

要使其成为单例,只需将其注册为

ObjectManager::makeSingleton(MyClassInterface::class);

使用以下方式在您的代码的任何地方获取对象

ObjectManager::get(MyClassInterface::class);

类型转换器

类型转换器可用于将一些源转换为定义的目标类型。

注册类型转换器

Converter::register('registrationFormDto', new RegistrationFormDtoConverter());

转换源

Converter::convert($postData, RegistrationFormDtoConverter::class);

控制器安全

要保护 Controller::Action,您可以向 AccessVoter 对象添加投票。投票接收一个闭包,可以是您想要的任何内容。控制器的参数将被传递给这个闭包。因此,如果您需要它们,请使用它们。 查看此示例