phpalchemy/propel-service-provider

PhpAlchemy的Propel集成。

dev-master / 1.0.x-dev 2014-03-24 14:33 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:10:13 UTC


README

PropelServiceProvider 提供了与 Propel2 的集成。

参数

  • propel.path(可选):Propel.php 将被找到的路径。通常,对于 PEAR 安装,它是 propel,而对于 Git 安装,它是 vendor/propel/runtime/lib。默认是 /full/project/path/vendor/propel/propel1/runtime/lib

  • propel.config_file(可选):包含完整路径的 Propel 配置文件名称。默认是 /full/project/path/build/conf/projectname-conf.php

  • propel.model_path(可选):模型类所在的路径。默认是 /full/project/path/build/classes

强烈建议为上述选项使用 绝对路径

服务

不提供任何服务。

Propel 通过使用静态方法来自我配置和管理,因此没有服务被注册到 Application 中。实际上,PropelServiceProvider 类以更 "PhpAlchemy" 的方式初始化 Propel。

注册

确保您在 vendor/propel 中放置了 Propel 的副本,或者通过 PEAR 或 Composer 安装它。

有关更多信息,请参阅 Propel 文档

<?php

$app['propel.config_file'] = __DIR__.'/path/to/myproject-conf.php';
$app['propel.model_path'] = __DIR__.'/path/to/model/classes';
$app->register(new Propel\Silex\PropelServiceProvider());

或者,如果您在 vendor/propel 中通过 Git 安装了 Propel 并使用默认的 Propel 生成器选项构建了您的模型

<?php

$app->register(new Propel\Silex\PropelServiceProvider());

我们可以考虑 "默认" Propel 生成器选项

  • build.propertiesschema.xml 文件放入主目录项目,通常位于 index.php 文件所在的目录。

  • build.properties 文件中,仅定义 propel.databasepropel.projectpropel.namespace.autopackage 属性。

用法

您将需要自己构建模型。根据 Propel 文档,您需要三个文件

  • schema.xml 包含您的数据库模式;

  • build.properties 更多的信息见下文;

  • runtime-conf.xml 包含数据库配置。

使用 propel-gen 脚本创建所有文件(SQL、配置、模型类)。

默认情况下,PropelServiceProvider 依赖于您已配置的 PhpAlchemy 自动加载器以加载模型类。当然,Silex 自动加载器需要使用命名空间构建的模型,因此请确保在 build.properties 文件中设置此属性

propel.namespace.autopackage = true

The recommended configuration for your `build.properties` file is:

propel.project      = <project_name>

propel.namespace.autoPackage = true
propel.packageObjectModel    = true

# Enable full use of the DateTime class.
# Setting this to true means that getter methods for date/time/timestamp
# columns will return a DateTime object when the default format is empty.
propel.useDateTimeClass = true

# Specify a custom DateTime subclass that you wish to have Propel use
# for temporal values.
propel.dateTimeClass = DateTime

# These are the default formats that will be used when fetching values from
# temporal columns in Propel. You can always specify these when calling the
# methods directly, but for methods like getByName() it is nice to change
# the defaults.
# To have these methods return DateTime objects instead, you should set these
# to empty values
propel.defaultTimeStampFormat =
propel.defaultTimeFormat =
propel.defaultDateFormat =

如果您计划不使用命名空间构建模型,则需要强制 Propel 使用其内部自动加载器。通过将选项 propel.internal_autoload 设置为 true 来执行此操作。

有关更多信息,请参阅 Propel 文档