简体   繁体   English

是否可以在不使用整个框架的情况下在 PHP 中为 ORM 安装 Kohana 库?

[英]Is it possible to install Kohana libraries for ORM in PHP without using the entire framework?

In a previous question, I asked about various ORM libraries.在上一个问题中,我询问了各种 ORM 库。 It turns out Kohana looks very clean yet functional for the purposes of ORM.事实证明,Kohana 看起来非常干净,但对于 ORM 而言却很实用。 I already have an MVC framework that I am working in though.我已经有一个我正在使用的 MVC 框架。 If I don't want to run it as a framework, what is the right fileset to include to just give me the DB and ORM base class files?如果我不想将它作为框架运行,那么包含什么文件集是为了给我 DB 和 ORM 基类文件?

Update:更新:

I jumped in and started looking at the ORM source code.. One thing was immediately confusing to me.. all the ORM classes have the class name appended with _CORE ie ORM_Core ORM_Iterator_Core, but the code everywhere is extending the ORM class.我跳进去开始查看 ORM 源​​代码.. 一件事让我立即感到困惑.. 所有 ORM 类的类名都附加了 _CORE,即 ORM_Core ORM_Iterator_Core,但到处都是代码扩展 ORM 类。 Problem is, I've searched the whole code base 6 different ways, and I've never seen a plain ORM class def nor an ORM interface def or anything.. Could someone enlighten me on where that magic happens?问题是,我已经用 6 种不同的方式搜索了整个代码库,但我从未见过普通的 ORM 类 def 或 ORM 接口 def 或任何东西..有人能告诉我这种魔法发生在哪里吗?

Why not just have a为什么不只是拥有一个

class ORM extends ORM_Core {} 

somewhere in your code?在您的代码中的某个地方? This removes the need to use any of the loader code.这消除了使用任何加载程序代码的需要。

You'll also need Kohana_Exception, the Database library (and appropraite driver), Kohana::config(), Kohana::auto_load(), Kohana::log() methods (search Database.php for those).您还需要 Kohana_Exception、数据库库(和适当的驱动程序)、Kohana::config()、Kohana::auto_load()、Kohana::log() 方法(在 Database.php 中搜索这些方法)。

Kohana is a great MVC framework, but not really designed to be taken apart in chunks like that. Kohana 是一个很棒的 MVC 框架,但并不是真正设计为像这样拆分成块。 You may want to also investigate Doctrine , another ORM for PHP (that IS designed to be stand-alone)您可能还想研究Doctrine ,另一个用于 PHP 的 ORM(设计为独立的)

It turns out that Kohana uses magic class loading so that if a defined class with an _Core extention doesn't exist as a class事实证明,Kohana 使用魔法类加载,因此如果具有 _Core 扩展名的已定义类不作为类存在

ie ORM_Core exists, but ORM doesn't, so Kohana will magically define an ORM class Since the package uses 100% magic class loading.即 ORM_Core 存在,但 ORM 不存在,因此 Kohana 会神奇地定义一个 ORM 类,因为该包使用 100% 魔术类加载。

In case anyone is interested, I'm documenting my finds here so everyone can find it later:如果有人感兴趣,我在这里记录我的发现,以便每个人以后都能找到它:

From Kohana.php in the system directory:

<-- snip if ($extension = self::find_file($type, self::$configuration['core']['extension_prefix'].$class))
{
// Load the extension
require $extension;
}
elseif ($suffix !== 'Core' AND class_exists($class.'_Core', FALSE))
{
// Class extension to be evaluated
$extension = 'class '.$class.' extends '.$class.'_Core { }';
-->

<-- snip

// Transparent class extensions are handled using eval. This is
// a disgusting hack, but it gets the job done.
eval($extension);

-->

So it does an eval..所以它做一个评估..

Zak, check Maintainable framework's ORM. Zak,检查可维护框架的 ORM。 http://framework.maintainable.com/mvc/3_model.php#c3.7 Read thoroughly, I am sure you'll like it. http://framework.maintainable.com/mvc/3_model.php#c3.7通读一遍,我相信你会喜欢的。 I post this in more detail in: What is the easiest to use ORM framework for PHP?我更详细地发布了这篇文章: PHP 最容易使用的 ORM 框架是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM