mongodb-odm-docs-dash/build.docset/Contents/Resources/Documents/reference/architecture.html

271 lines
14 KiB
HTML
Raw Permalink Normal View History

2017-12-02 03:35:11 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Architecture &mdash; Doctrine MongoDB ODM 1.1.5 documentation</title>
<link rel="stylesheet" href="../_static/bootstrap/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/layout.css" type="text/css" />
<link rel="stylesheet" href="../_static/configurationblock.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.1.5',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/configurationblock.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/configurationblock.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/configurationblock.js"></script>
<script src="../_static/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function() {
$("#versions").change(function() {
var docsUrl = $(this).val();
window.location.href = docsUrl;
});
});
-->
</script>
<link rel="shortcut icon" href="../_static/doctrine.ico"/>
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Doctrine MongoDB ODM 1.1.5 documentation" href="../index.html" />
</head>
<body>
<div id="wrapper">
<div id="header">
<h1 id="h1title"></h1>
<div id="logo">
<a href="http://www.doctrine-project.org/">Doctrine - PHP Database Libraries</a>
</div>
</div>
<div id="nav" class="cls">
<div class="tl cls">
<ul>
<li><a target="_top" href="http://www.doctrine-project.org/">Home</a></li>
<li><a target="_top" href="http://www.doctrine-project.org/about.html">About</a></li>
<li><a target="_top" href="http://www.doctrine-project.org/projects.html">Projects</a></li>
<li><a target="_top" href="http://www.doctrine-project.org/contribute.html">Contribute</a></li>
<li><a target="_top" href="http://www.doctrine-project.org/community.html">Community</a></li>
<li><a target="_top" href="http://www.doctrine-project.org/archive.html">Blog</a></li>
<li><a target="_top" href="http://www.doctrine-project.org/jira">Development</a></li>
</ul>
</div>
</div>
<div id="content" class="cls">
<div class="related">
<h3>Navigation</h3>
<ul>
<li><a href="/">Doctrine Homepage</a> &raquo;</li>
<li><a href="../index.html">Doctrine MongoDB ODM 1.1.5 documentation</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" >
<div class="section" id="architecture">
<h1>Architecture<a class="headerlink" href="#architecture" title="Permalink to this headline"></a></h1>
<p>This chapter gives an overview of the overall architecture,
terminology and constraints of Doctrine. It is recommended to
read this chapter carefully.</p>
<div class="section" id="documents">
<h2>Documents<a class="headerlink" href="#documents" title="Permalink to this headline"></a></h2>
<p>A document is a lightweight, persistent domain object. A document can
be any regular PHP class observing the following restrictions:</p>
<ul class="simple">
<li>A document class must not be final or contain final methods.</li>
<li>All persistent properties/field of any document class should
always be private or protected, otherwise lazy-loading might not
work as expected.</li>
<li>A document class must not implement <code class="docutils literal"><span class="pre">__clone</span></code> or
<a class="reference internal" href="../cookbook/implementing-wakeup-or-clone.html"><span class="doc">do so safely</span></a>.</li>
<li>A document class must not implement <code class="docutils literal"><span class="pre">__wakeup</span></code> or
<a class="reference internal" href="../cookbook/implementing-wakeup-or-clone.html"><span class="doc">do so safely</span></a>.
Also consider implementing
<a class="reference external" href="http://de3.php.net/manual/en/class.serializable.php">Serializable</a>
instead.</li>
<li>Any two document classes in a class hierarchy that inherit
directly or indirectly from one another must not have a mapped
property with the same name. That is, if B inherits from A then B
must not have a mapped field with the same name as an already
mapped field that is inherited from A.</li>
</ul>
<p>Documents support inheritance, polymorphic associations, and
polymorphic queries. Both abstract and concrete classes can be
documents. Documents may extend non-document classes as well as document
classes, and non-document classes may extend document classes.</p>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p class="last">The constructor of a document is only ever invoked when
<em>you</em> construct a new instance with the <em>new</em> keyword. Doctrine
never calls document constructors, thus you are free to use them as
you wish and even have it require arguments of any type.</p>
</div>
<div class="section" id="document-states">
<h3>Document states<a class="headerlink" href="#document-states" title="Permalink to this headline"></a></h3>
<p>A document instance can be characterized as being NEW, MANAGED, DETACHED or REMOVED.</p>
<ul class="simple">
<li>A NEW document instance has no persistent identity, and is not yet
associated with a DocumentManager and a UnitOfWork (i.e. those just
created with the &quot;new&quot; operator).</li>
<li>A MANAGED document instance is an instance with a persistent
identity that is associated with a DocumentManager and whose
persistence is thus managed.</li>
<li>A DETACHED document instance is an instance with a persistent
identity that is not (or no longer) associated with a
DocumentManager and a UnitOfWork.</li>
<li>A REMOVED document instance is an instance with a persistent
identity, associated with a DocumentManager, that will be removed
from the database upon transaction commit.</li>
</ul>
</div>
<div class="section" id="persistent-fields">
<h3>Persistent fields<a class="headerlink" href="#persistent-fields" title="Permalink to this headline"></a></h3>
<p>The persistent state of a document is represented by instance
variables. An instance variable must be directly accessed only from
within the methods of the document by the document instance itself.
Instance variables must not be accessed by clients of the document.
The state of the document is available to clients only through the
document's methods, i.e. accessor methods (getter/setter methods) or
other business methods.</p>
<p>Collection-valued persistent fields and properties must be defined
in terms of the <code class="docutils literal"><span class="pre">Doctrine\Common\Collections\Collection</span></code>
interface. The collection implementation type may be used by the
application to initialize fields or properties before the document is
made persistent. Once the document becomes managed (or detached),
subsequent access must be through the interface type.</p>
</div>
<div class="section" id="serializing-documents">
<h3>Serializing documents<a class="headerlink" href="#serializing-documents" title="Permalink to this headline"></a></h3>
<p>Serializing documents can be problematic and is not really
recommended, at least not as long as a document instance still holds
references to proxy objects or is still managed by an
DocumentManager. If you intend to serialize (and unserialize) document
instances that still hold references to proxy objects you may run
into problems with private properties because of technical
limitations. Proxy objects implement <code class="docutils literal"><span class="pre">__sleep</span></code> and it is not
possible for <code class="docutils literal"><span class="pre">__sleep</span></code> to return names of private properties in
parent classes. On the other hand it is not a solution for proxy
objects to implement <code class="docutils literal"><span class="pre">Serializable</span></code> because Serializable does not
work well with any potential cyclic object references (at least we
did not find a way yet, if you did, please contact us).</p>
</div>
</div>
<div class="section" id="the-documentmanager">
<h2>The DocumentManager<a class="headerlink" href="#the-documentmanager" title="Permalink to this headline"></a></h2>
<p>The <code class="docutils literal"><span class="pre">DocumentManager</span></code> class is a central access point to the ODM
functionality provided by Doctrine. The <code class="docutils literal"><span class="pre">DocumentManager</span></code> API is
used to manage the persistence of your objects and to query for
persistent objects.</p>
<div class="section" id="transactional-write-behind">
<h3>Transactional write-behind<a class="headerlink" href="#transactional-write-behind" title="Permalink to this headline"></a></h3>
<p>An <code class="docutils literal"><span class="pre">DocumentManager</span></code> and the underlying <code class="docutils literal"><span class="pre">UnitOfWork</span></code> employ a
strategy called &quot;transactional write-behind&quot; that delays the
execution of query statements in order to execute them in the most
efficient way and to execute them at the end of a transaction so
that all write locks are quickly released. You should see Doctrine
as a tool to synchronize your in-memory objects with the database
in well defined units of work. Work with your objects and modify
them as usual and when you're done call <code class="docutils literal"><span class="pre">DocumentManager#flush()</span></code>
to make your changes persistent.</p>
</div>
<div class="section" id="the-unit-of-work">
<h3>The Unit of Work<a class="headerlink" href="#the-unit-of-work" title="Permalink to this headline"></a></h3>
<p>Internally an <code class="docutils literal"><span class="pre">DocumentManager</span></code> uses a <code class="docutils literal"><span class="pre">UnitOfWork</span></code>, which is a
typical implementation of the
<a class="reference external" href="http://martinfowler.com/eaaCatalog/unitOfWork.html">Unit of Work pattern</a>,
to keep track of all the things that need to be done the next time
<code class="docutils literal"><span class="pre">flush</span></code> is invoked. You usually do not directly interact with a
<code class="docutils literal"><span class="pre">UnitOfWork</span></code> but with the <code class="docutils literal"><span class="pre">DocumentManager</span></code> instead.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="">
<h3>Search</h3>
<form class="search" action="http://readthedocs.org/search/project/" method="get">
<input type="text" name="q" size="18">
<input type="submit" value="Go">
<input type="hidden" name="selected_facets" value="project:">
</form>
</div>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Architecture</a><ul>
<li><a class="reference internal" href="#documents">Documents</a><ul>
<li><a class="reference internal" href="#document-states">Document states</a></li>
<li><a class="reference internal" href="#persistent-fields">Persistent fields</a></li>
<li><a class="reference internal" href="#serializing-documents">Serializing documents</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-documentmanager">The DocumentManager</a><ul>
<li><a class="reference internal" href="#transactional-write-behind">Transactional write-behind</a></li>
<li><a class="reference internal" href="#the-unit-of-work">The Unit of Work</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/reference/architecture.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy; Copyright 2013, Doctrine Project Team.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.6.2.
<br/>
<a target="_BLANK" href="http://www.servergrove.com"><img src="http://www.doctrine-project.org/_static/servergrove.jpg" /></a> <br/><br/>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="BAE2E3XANQ77Y" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" />
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>
</div>
</div>
<div id="bot-rcnr">
<div class="tl"><!-- corner --></div>
</div>
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-288343-7";
urchinTracker();
</script>
<a class="githublink" href="http://github.com/doctrine"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
</body>
</html>