精华内容
下载资源
问答
  • Doctrine

    2015-08-26 08:59:00
    Doctrine 未完待续。。。 转载于:https://my.oschina.net/maczhao/blog/497131

    Doctrine

    未完待续。。。

    转载于:https://my.oschina.net/maczhao/blog/497131

    展开全文
  • 其主要功能之一是可以选择以专有的面向对象 SQL 方言编写数据库查询,该方言称为 Doctrine 查询语言 (DQL),其灵感来自 Hibernate 的 HQL。 这为开发人员提供了一种强大的 SQL 替代方案,可以保持灵活性而无需不必...
  • Doctrine 数据库抽象和访问层 (DBAL) 围绕类似 PDO 的 API 提供了一个轻量级和精简的运行时层,以及许多附加的横向功能,例如通过 OO API 进行的数据库模式自省和操作。 Doctrine DBAL 通过使用与现有 PDO API 非常...
  • 它从类型提示中读取大多数信息,从现有的Doctrine注释中完成一些操作,并允许使用专门的注释进行进一步的自定义。 然后它将创建和实例,并分别具有在Doctrine实体上找到的所有getter和setter的字段。 它不会构建...
  • phpstan-doctrine, PHPStan的Doctrine 扩展 PHPStan的Doctrine 扩展 PHPStanDoctrine这里扩展提供以下功能:提供 DoctrineORMEntityManager::find 。getReference 和 getPartial
  • ramsey / uuid-doctrine软件包提供了将用作。 该项目遵守《 。 通过参与该项目及其社区,您应该遵守此代码。 安装 首选的安装方法是通过和 。 运行以下命令以安装软件包并将其作为要求添加到项目的composer.json ...
  • PHPStan的学说扩展 此扩展提供以下功能: 用于解析错误,未知实体类和未知持久字段的DQL验证。 还支持QueryBuilder验证。 识别EntityRepository上的魔术findBy* , findOneBy... 为Doctrine\ORM\EntityManager::getRe
  • <div><p>When agavi connects to database, unable to load all the Doctrine 1.2 generated models The first test: <pre><code> xml <parameter name="load_models">%core.lib_dir%/doctrine<...
  • Doctrine ORM

    2011-12-01 13:04:29
    介绍doctrine的相关知识 想了解更多关于doctrine的内容吗,选择他准没错,呵呵……
  • 然后将li3_doctrine2添加为必需的包(以及Doctrine和迁移): { " config " : { " vendor-dir " : " libraries " }, " require " : { " doctrine/orm " : " >=2.1 " , " doctrine/migrations " : " dev-...
  • Doctrine Annotations

    2019-09-15 13:53:14
    Doctrine Annotations The Doctrine Common annotations library was born from a need in theDoctrine2 ORMto allow the mapping information to be s...

    Doctrine Annotations

    The Doctrine Common annotations library was born from a need in the Doctrine2 ORM to allow the mapping information to be specified as metadata embedded in the class files, on properties and methods. The library is independent and can be used in your own libraries to implement doc block annotations.

    2.1. Introduction

    There are several different approaches to handling annotations in PHP. Doctrine Annotations maps docblock annotations to PHP classes. Because not all docblock annotations are used for metadata purposes a filter is applied to ignore or skip classes that are not Doctrine annotations.

    Take a look at the following code snippet:

    <?php namespace MyProject\Entities; use Doctrine\ORM\Mapping AS ORM; use Symfony\Component\Validation\Constraints AS Assert; /**  * @author Benjamin Eberlei  * @ORM\Entity  * @MyProject\Annotations\Foobarable  */ class User { /**  * @ORM\Id @ORM\Column @ORM\GeneratedValue  * @dummy  * @var int  */ private $id; /**  * @ORM\Column(type="string")  * @Assert\NotEmpty  * @Assert\Email  * @var string  */ private $email; }

    In this snippet you can see a variety of different docblock annotations:

    • Documentation annotations such as @var and @author. These annotations are on a blacklist and never considered for throwing an exception due to wrongly used annotations.
    • Annotations imported through use statements. The statement “use DoctrineORMMapping AS ORM” makes all classes under that namespace available as @ORMClassName. Same goes for the import of “Assert”.
    • The @dummy annotation. It is not a documentation annotation and not blacklisted. For Doctrine Annotations it is not entirely clear how to handle this annotation. Depending on the configuration an exception (unknown annotation) will be thrown when parsing this annotation.
    • The fully qualified annotation @MyProjectAnnotationsFoobarable. This is transformed directly into the given class name.

    How are these annotations loaded? From looking at the code you could guess that the ORM Mapping, Assert Validation and the fully qualified annotation can just be loaded using the defined PHP autoloaders. This is not the case however: For error handling reasons every check for class existence inside the AnnotationReader sets the second parameter $autoload of class_exists($name, $autoload) to false. To work flawlessly the AnnotationReader requires silent autoloaders which many autoloaders are not. Silent autoloading is NOT part of the PSR-0 specification for autoloading.

    This is why Doctrine Annotations uses its own autoloading mechanism through a global registry. If you are wondering about the annotation registry being global, there is no other way to solve the architectural problems of autoloading annotation classes in a straightforward fashion. Additionally if you think about PHP autoloading then you recognize it is a global as well.

    To anticipate the configuration section, making the above PHP class work with Doctrine Annotations requires this setup:

    <?php use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationRegistry; AnnotationRegistry::registerFile("/path/to/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); AnnotationRegistry::registerAutoloadNamespace("Symfony\Component\Validator\Constraint", "/path/to/symfony/src"); AnnotationRegistry::registerAutoloadNamespace("MyProject\Annotations", "/path/to/myproject/src"); $reader = new AnnotationReader(); AnnotationReader::addGlobalIgnoredName('dummy');

    The second block with the annotation registry calls registers all the three different annotation namespaces that are used. Doctrine saves all its annotations in a single file, that is why AnnotationRegistry#registerFile is used in contrast to AnnotationRegistry#registerAutoloadNamespace which creates a PSR-0 compatible loading mechanism for class to file names.

    In the third block, we create the actual AnnotationReader instance. Note that we also add “dummy” to the global list of annotations for which we do not throw exceptions. Setting this is necessary in our example case, otherwise @dummy would trigger an exception to be thrown during the parsing of the docblock ofMyProject\Entities\User#id.

    2.2. Setup and Configuration

    To use the annotations library is simple, you just need to create a new AnnotationReader instance:

    <?php $reader = new \Doctrine\Common\Annotations\AnnotationReader();

    This creates a simple annotation reader with no caching other than in memory (in php arrays). Since parsing docblocks can be expensive you should cache this process by using a caching reader.

    You can use a file caching reader:

    <?php use Doctrine\Common\Annotations\FileCacheReader; use Doctrine\Common\Annotations\AnnotationReader; $reader = new FileCacheReader( new AnnotationReader(), "/path/to/cache", $debug = true );

    If you set the debug flag to true the cache reader will check for changes in the original files, which is very important during development. If you don’t set it to true you have to delete the directory to clear the cache. This gives faster performance, however should only be used in production, because of its inconvenience during development.

    You can also use one of the Doctrine\Common\Cache\Cache cache implementations to cache the annotations:

    <?php use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\CachedReader; use Doctrine\Common\Cache\ApcCache; $reader = new CachedReader( new AnnotationReader(), new ApcCache(), $debug = true );

    The debug flag is used here as well to invalidate the cache files when the PHP class with annotations changed and should be used during development.

    The AnnotationReader works and caches under the assumption that all annotations of a doc-block are processed at once. That means that annotation classes that do not exist and aren’t loaded and cannot be autoloaded (using the AnnotationRegistry) would never be visible and not accessible if a cache is used unless the cache is cleared and the annotations requested again, this time with all annotations defined.

    By default the annotation reader returns a list of annotations with numeric indexes. If you want your annotations to be indexed by their class name you can wrap the reader in an IndexedReader:

    <?php use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\IndexedReader; $reader = new IndexedReader(new AnnotationReader());

    You should never wrap the indexed reader inside a cached reader only the other way around. This way you can re-use the cache with indexed or numeric keys, otherwise your code may experience failures due to caching in an numerical or indexed format.

    2.2.1. Registering Annotations

    As explained in the Introduction Doctrine Annotations uses its own autoloading mechanism to determine if a given annotation has a corresponding PHP class that can be autoloaded. For Annotation Autoloading you have to configure the Doctrine\Common\Annotations\AnnotationRegistry. There are three different mechanisms to configure annotation autoloading:

    • Calling AnnotationRegistry#registerFile($file) to register a file that contains one or more Annotation classes.
    • Calling AnnotationRegistry#registerNamespace($namespace, $dirs = null) to register that the given namespace contains annotations and that their base directory is located at the given $dirs or in the include path if NULL is passed. The given directories should NOT be the directory where classes of the namespace are in, but the base directory of the root namespace. The AnnotationRegistry uses a namespace to directory separator approach to resolve the correct path.
    • Calling AnnotationRegistry#registerLoader($callable) to register an autoloader callback. The callback accepts the class as first and only parameter and has to return true if the corresponding file was found and included.

    Loaders have to fail silently, if a class is not found even if it matches for example the namespace prefix of that loader. Never is a loader to throw a warning or exception if the loading failed otherwise parsing doc block annotations will become a huge pain.

    A sample loader callback could look like:

    <?php use Doctrine\Common\Annotations\AnnotationRegistry; use Symfony\Component\ClassLoader\UniversalClassLoader; AnnotationRegistry::registerLoader(function($class) { $file = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php"; if (file_exists("/my/base/path/" . $file)) { // file exists makes sure that the loader fails silently require "/my/base/path/" . $file; } }); $loader = new UniversalClassLoader(); AnnotationRegistry::registerLoader(array($loader, "loadClass"));

    2.2.2. Default Namespace

    If you don’t want to specify the fully qualified class name or import classes with the use statement you can set the default annotation namespace using the setDefaultAnnotationNamespace() method. The following is an example where we specify the fully qualified class name for the annotation:

    <?php /** @MyCompany\Annotations\Foo */ class Test { }

    To shorten the above code you can configure the default namespace to be MyCompany\Annotations:

    <?php $reader->setDefaultAnnotationNamespace('MyCompany\Annotations\\');

    Now it can look something like:

    <?php /** @Foo */ class Test { }

    A little nicer looking!

    You should only use this feature if you work in an isolated context where you have full control over all available annotations.

    2.2.3. Ignoring missing exceptions

    By default an exception is thrown from the AnnotationReader if an annotation was found that:

    • Is not part of the blacklist of ignored “documentation annotations”.
    • Was not imported through a use statement
    • Is not a fully qualified class that exists

    You can disable this behavior for specific names if your docblocks do not follow strict requirements:

    <?php $reader = new \Doctrine\Common\Annotations\AnnotationReader(); AnnotationReader::addGlobalIgnoredName('foo');

    2.2.4. PHP Imports

    By default the annotation reader parses the use-statement of a php file to gain access to the import rules and register them for the annotation processing. Only if you are using PHP Imports you can validate the correct usage of annotations and throw exceptions if you misspelled an annotation. This mechanism is enabled by default.

    To ease the upgrade path, we still allow you to disable this mechanism. Note however that we will remove this in future versions:

    <?php $reader = new \Doctrine\Common\Annotations\AnnotationReader(); $reader->setEnabledPhpImports(false);

    2.3. Annotation Classes

    If you want to define your own annotations you just have to group them in a namespace and register this namespace in the AnnotationRegistry. Annotation classes have to contain a class-level docblock with the text @Annotation:

    <?php namespace MyCompany\Annotations; /** @Annotation */ class Bar { //some code }

    2.4. Inject annotation values

    The annotation parser check if the annotation constructor has arguments, if so then we will pass the value array, otherwise will try to inject values into public properties directly:

    <?php namespace MyCompany\Annotations; /** * @Annotation * * Some Annotation using a constructor */ class Bar { private $foo; public function __construct(array $values) { $this->foo = $values['foo']; } } /** * @Annotation * * Some Annotation without a constructor */ class Foo { public $bar; }

    2.5. Annotation Target

    @Target  indicates the kinds of class element to which an annotation type is applicable. Then you could define one or more targets :

    • CLASS Allowed in the class docblock
    • PROPERTY Allowed in the property docblock
    • METHOD Allowed in the method docblock
    • ALL Allowed in the class, property and method docblock
    • ANNOTATION Allowed inside other annotations

    If the annotations is not allowed in the current context you got an AnnotationException

    <?php namespace MyCompany\Annotations; /** * @Annotation * @Target({"METHOD","PROPERTY"}) */ class Bar { //some code } /** * @Annotation * @Target("CLASS") */ class Foo { //some code }

    2.6. Attribute types

    Annotation parser check the given parameters using the phpdoc annotation @var , The data type could be validated using the @var  annotation on the annotation properties or using the annotations @Attributes and@Attribute.

    If the data type not match you got an AnnotationException

    <?php namespace MyCompany\Annotations; /** * @Annotation * @Target({"METHOD","PROPERTY"}) */ class Bar { /** @var mixed */ public $mixed; /** @var boolean */ public $boolean; /** @var bool */ public $bool; /** @var float */ public $float; /** @var string */ public $string; /** @var integer */ public $integer; /** @var array */ public $array; /** @var SomeAnnotationClass */ public $annotation; /** @var array<integer> */ public $arrayOfIntegers; /** @var array<SomeAnnotationClass> */ public $arrayOfAnnotations; } /** * @Annotation * @Target({"METHOD","PROPERTY"}) * @Attributes({ *   @Attribute("stringProperty", type = "string"), *   @Attribute("annotProperty",  type = "SomeAnnotationClass"), * }) */ class Foo { public function __construct(array $values) { $this->stringProperty = $values['stringProperty']; $this->annotProperty = $values['annotProperty']; } // some code }

    2.7. Constants

    The use of constants and class constants are available on the annotations parser.

    The following usage are allowed :

    <?php namespace MyCompany\Entity; use MyCompany\Annotations\Foo; use MyCompany\Annotations\Bar; use MyCompany\Entity\SomeClass; /** * @Foo(PHP_EOL) * @Bar(Bar::FOO) * @Foo({SomeClass::FOO, SomeClass::BAR}) * @Bar({SomeClass::FOO_KEY = SomeClass::BAR_VALUE}) */ class User { }

    Be careful with constants and the cache !

    The cached reader will not re-evaluate each time an annotation is loaded from cache. When a constant is changed the cache must be cleaned.

    2.8. Usage

    Using the library API is simple. Using the annotations described in the previous section you can now annotate other classes with your annotations:

    <?php namespace MyCompany\Entity; use MyCompany\Annotations\Foo; use MyCompany\Annotations\Bar; /**  * @Foo(bar="foo")  * @Bar(foo="bar")  */ class User { }

    Now we can write a script to get the annotations above:

    <?php $reflClass = new ReflectionClass('MyCompany\Entity\User'); $classAnnotations = $reader->getClassAnnotations($reflClass); foreach ($classAnnotations AS $annot) { if ($annot instanceof \MyCompany\Annotations\Foo) { echo $annot->bar; // prints "foo"; } else if ($annot instanceof \MyCompany\Annotations\Bar) { echo $annot->foo; // prints "bar"; } }

    You have a complete API for retrieving annotation class instances from a class, property or method docblock:

    • AnnotationReader#getClassAnnotations(ReflectionClass $class)
    • AnnotationReader#getClassAnnotation(ReflectionClass $class, $annotation)
    • AnnotationReader#getPropertyAnnotations(ReflectionProperty $property)
    • AnnotationReader#getPropertyAnnotation(ReflectionProperty $property, $annotation)
    • AnnotationReader#getMethodAnnotations(ReflectionMethod $method)
    • AnnotationReader#getMethodAnnotation(ReflectionMethod $method, $annotation)

    2.9. IDE Support

    Some IDEs already provide support for annotations:

    转载于:https://my.oschina.net/Qm3KQvXRq/blog/123153

    展开全文
  • zf2-doctrine1 Laminas模块与Doctrine 1.x集成
  • 克比/教义 安装 安装Kdyby / Doctrine的最佳方法是使用 : $ composer require kdyby/doctrine 文献资料 在了解更多。 主页和存储库 。
  • Doctrine浅析

    2019-05-15 10:36:29
    1.使用框架操作数据库的...Doctrine简介 06年成立项目 代码开源,开发过程透明 良好的架构 可以独立使用 也能结合框架使用 功能强大,速度快 为何选择Doctrine 一些历史原因 获得Symfony的第三方bundle的支持 ...

    1.使用框架操作数据库的几个需求

    1. 性能

      • ORM(Object-Relational Mapper)
        用操作类的方式操作数据库
      • 支持多种数据库
      • 支持多种第三方插件
    2. Doctrine简介

      1. 06年成立项目
      2. 代码开源,开发过程透明
      3. 良好的架构
        1. 可以独立使用
        2. 也能结合框架使用
      4. 功能强大,速度快
    3. 为何选择Doctrine

      1. 一些历史原因
      2. 获得Symfony的第三方bundle的支持
    4. Symfony2可不可以使用别的数据库操作软件

      1. Propel
      2. Zend DB
      3. 其他的(不推荐)

    5.代码操作数据库demo

    取得对象
    	$user=$em->getRepository('User')->find(array('id'=>1))
    		findOneBy()获取一条
    	$user->setName('name');修改name字段值为name
    	实例化数据库
    	$em->presist($user);
    	对比生成Updata语句
    	$em->flush
    一对多
    	foreach($user->getAddressBooks() as $addressBook){
    		$addressBooks->getName()
    	}
    

    6.Doctrine2的基本概念

    1. 实体对象-entitiy
      1. 字段
      2. 关系

    2. 对象操作集合-Repository

    3. Proxy Class

    4. DQL数据库查寻语言

      1. $query=$em->createQuery(
      	select u fromDataBundle:User p where u.name=:name
      )->setParameter('name','scourgen')
      
      2. $query2=$em->getRepository('User')->createQueryBuilder('U')
      	->where('u.name = :name')
      	->setParameter('name','scourgen')
      	->getQuery();
      

    7.事件监听机制
    8.进行数据库设计

    1. 实际数据库关系和主要字段
    2. 配置Symfony2数据库连接
    3. 配置Entity
    4. 生成get/set/repository
    5. 生成真实数据库
    展开全文
  • LdcZfOAuth2Doctrine 什么? LdcZfOAuth2Doctrine 将zf-oauth2表实现为 Doctrine ORM 实体。 轻松链接任何 ZfcUser 兼容的帐户实体和宾果游戏,他们现在可以通过 OAuth2 进行身份验证。 警告:此代码尚未经过测试...
  • 用于代码接收的Doctrine 2模块。 安装 composer require "codeception/module-doctrine2" --dev 文献资料 请参阅。 执照 Codeception Module Doctrine2是根据许可证获得许可的开源软件。 :copyright:Codeception ...
  • Doctrine DateInterval 类型 支持 Doctrine DBAL 和 ORM 中的 DateInterval。 概括 DateInterval库 向dateinterval添加dateinterval类型 向 ORM 添加DATE_INTERVAL DQL 函数 库使这成为可能。 安装 将其添加到 ...
  • 1C-Bitrix - Doctrine 2 模块 安装 假设您已经安装了 composer.phar 或 composer binary,只需运行: $ php composer.phar require citfact/doctrine dev-master
  • 该组件使您可以使用Doctrine 组件管理某些本机数据类型,运算符和函数。 用法 添加到composer.json php composer.phar require opsway/doctrine-dbal-postgresql: ~ 0.1 要使用新类型,您应该使用“ 功能注册它们...
  • 学说缓存 Nice 应用程序和 Doctrine Cache 组件之间的桥梁。 。
  • SwissEngine\Tools\Doctrine\Extension 这个小模块旨在提供一种简单的方法来(无缝地)向学说 CLI 工具 (ZF2) 添加一些功能,例如能够指定我们想要选择使用的实体管理器。 ...
  • Doctrine2 ORM 集成到 1C-Bitrix 该模块是 Doctrine2 集成到 Bitrix 中的一层,设计为一个模块。 要求 任何版本的 1C-Bitrix Php version> = 5.3.2 (php 5.5 版本需要设置 opcache.save_comments = 1) 安装 ...
  • 安装doctrine

    2016-03-01 12:33:24
    安装doctrine首先要安装pear,见我上一篇文章 1. 添加doctrine初始化通道 pear channel-discover pear.symfony.com//这个是doctrine所依赖的 pear channel-discover pear.doctrine-project.org 2. 安装...

    安装doctrine首先要安装pear,见我上一篇文章

    1. 添加doctrine初始化通道

    pear channel-discover pear.symfony.com//这个是doctrine所依赖的
    pear channel-discover pear.doctrine-project.org

    2. 安装doctrine核心包

    pear install pear.doctrine-project.org/DoctrineORM

    //此时会安装一下5个包
    install ok: channel://pear.doctrine-project.org/DoctrineCommon-2.3.0
    install ok: channel://pear.symfony.com/Console-2.4.4
    install ok: channel://pear.symfony.com/Yaml-2.4.4
    install ok: channel://pear.doctrine-project.org/DoctrineDBAL-2.3.4
    install ok: channel://pear.doctrine-project.org/DoctrineORM-2.3.3



    展开全文
  • symfony doctrine orm

    2017-11-02 08:00:44
    One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernates HQL. This provides developers...
  • Doctrine Migrations 的独立运行器 这个项目提供了vendor/bin/migrations.php ,它允许在没有任何框架集成的情况下运行 docrine/migrations 。 安装 $ composer require doctrine/migrations:dev-master $ composer...
  • doctrine的demo

    2015-10-09 11:19:49
    一个简单的数据库对象关系映射框架doctrine的使用demo
  • zendframework1-doctrine2, Zend框架和 Doctrine的集成 框架 1. X + Doctrine 2. X 集成ZF1-D2是一个集成工具,允许你在 Zend Framework 1的顶部使用 Doctrine 2.安装使用编辑器安装 ZF1-D2创建你的composer.json-...
  • 橄榄石学说插件 轻松将 Doctrine ORM 测试与 Peridot BDD 集成。 安装 通过: composer require peridot-php/peridot-doctrine-plugin

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 8,133
精华内容 3,253
关键字:

doctrine