Skip to content

Commit

Permalink
[DX] Adding bool and integer types and annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Apr 4, 2015
1 parent f04de2e commit e9beedc
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 7 deletions.
33 changes: 33 additions & 0 deletions docs/en/reference/annotations-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ value to `MongoBinData`_ with ``MongoBinData::UUID_RFC4122`` sub-type.
RFC 4122 UUIDs must be 16 bytes. The PHP driver will throw an exception if
the binary data's size is invalid.

@Bool
--------

Alias of `@Field`_, with "type" attribute set to "bool". Internally it uses
exactly same logic as `@Boolean`_ annotation and "boolean" type.

.. code-block:: php
<?php
/** @Bool */
private $active;
@Boolean
--------

Expand Down Expand Up @@ -742,6 +755,26 @@ Examples:

Alias of `@Field`_, with "type" attribute set to "int".

.. code-block:: php
<?php
/** @Int */
private $columns;
@Integer
--------

Alias of `@Field`_, with "type" attribute set to "integer". Internally it uses
exactly same logic as `@Int`_ annotation and "int" type.

.. code-block:: php
<?php
/** @Integer */
private $columns;
@Key
----

Expand Down
26 changes: 26 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Bool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

/** @Annotation */
final class Bool extends AbstractField
{
public $type = 'bool';
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
require_once __DIR__ . '/Field.php';
require_once __DIR__ . '/Id.php';
require_once __DIR__ . '/Hash.php';
require_once __DIR__ . '/Bool.php';
require_once __DIR__ . '/Boolean.php';
require_once __DIR__ . '/Int.php';
require_once __DIR__ . '/Integer.php';
require_once __DIR__ . '/Float.php';
require_once __DIR__ . '/String.php';
require_once __DIR__ . '/Date.php';
Expand Down
26 changes: 26 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Integer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

/** @Annotation */
final class Integer extends AbstractField
{
public $type = 'integer';
}
6 changes: 5 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Types/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ abstract class Type
const ID = 'id';
const INTID = 'int_id';
const CUSTOMID = 'custom_id';
const BOOL = 'bool';
const BOOLEAN = 'boolean';
const INTEGER = 'int';
const INT = 'int';
const INTEGER = 'integer';
const FLOAT = 'float';
const STRING = 'string';
const DATE = 'date';
Expand Down Expand Up @@ -62,7 +64,9 @@ abstract class Type
self::ID => 'Doctrine\ODM\MongoDB\Types\IdType',
self::INTID => 'Doctrine\ODM\MongoDB\Types\IntIdType',
self::CUSTOMID => 'Doctrine\ODM\MongoDB\Types\CustomIdType',
self::BOOL => 'Doctrine\ODM\MongoDB\Types\BooleanType',
self::BOOLEAN => 'Doctrine\ODM\MongoDB\Types\BooleanType',
self::INT => 'Doctrine\ODM\MongoDB\Types\IntType',
self::INTEGER => 'Doctrine\ODM\MongoDB\Types\IntType',
self::FLOAT => 'Doctrine\ODM\MongoDB\Types\FloatType',
self::STRING => 'Doctrine\ODM\MongoDB\Types\StringType',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class GH611Document
/** @ODM\EmbeddedDocument */
class GH611EmbeddedDocument
{
/** @ODM\Int */
/** @ODM\Integer */
public $id;

/** @ODM\String(name="n") */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ class MODM67EmbeddedObject
/** @ODM\Int */
public $numAccesses = 0;

/** @ODM\Boolean */
/** @ODM\Bool */
public $prePersist = false;

/** @ODM\Boolean */
/** @ODM\Bool */
public $postPersist = false;

/** @ODM\Boolean */
/** @ODM\Bool */
public $preUpdate = false;

/** @ODM\Boolean */
/** @ODM\Bool */
public $postUpdate = false;
}
}

0 comments on commit e9beedc

Please sign in to comment.