Permalink
Browse files

Default MongoBinData subtype to 0 and create BinDataByteArrayType for BC

Previously, BinDataType used MongoBinData::BYTE_ARRAY. That subtype, 2, is deprecated in the BSON specification. Use 0, the new default, for BinDataType and create BinDataByteArrayType for users that prefer the old subtype.

See: https://jira.mongodb.org/browse/PHP-407
  • Loading branch information...
1 parent 11ffe95 commit 173f4eaea8f010f64cd20f9ac15c15797bf7fcef @jmikola jmikola committed Jan 15, 2014
@@ -0,0 +1,32 @@
+<?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\Types;
+
+/**
+ * The BinDataByteArray type.
+ *
+ * @since 1.0
+ * @author Jonathan H. Wage <jonwage@gmail.com>
+ * @author Roman Borschel <roman@code-factory.org>
+ */
+class BinDataByteArrayType extends BinDataType
+{
+ protected $binDataType = \MongoBinData::BYTE_ARRAY;
+}
@@ -31,10 +31,15 @@ class BinDataType extends Type
/**
* MongoBinData type
*
+ * The default subtype for BSON binary values is 0, but we cannot use a
+ * constant here because it is not available in all versions of the PHP
+ * driver.
+ *
* @var integer
* @see http://php.net/manual/en/mongobindata.construct.php
+ * @see http://bsonspec.org/#/specification
*/
- protected $binDataType = \MongoBinData::BYTE_ARRAY;
+ protected $binDataType = 0;
public function convertToDatabaseValue($value)
{
@@ -42,6 +42,7 @@
const TIMESTAMP = 'timestamp';
const BINDATA = 'bin';
const BINDATAFUNC = 'bin_func';
+ const BINDATABYTEARRAY = 'bin_bytearray';
const BINDATAUUID = 'bin_uuid';
const BINDATAMD5 = 'bin_md5';
const BINDATACUSTOM = 'bin_custom';
@@ -69,6 +70,7 @@
self::TIMESTAMP => 'Doctrine\ODM\MongoDB\Types\TimestampType',
self::BINDATA => 'Doctrine\ODM\MongoDB\Types\BinDataType',
self::BINDATAFUNC => 'Doctrine\ODM\MongoDB\Types\BinDataFuncType',
+ self::BINDATABYTEARRAY => 'Doctrine\ODM\MongoDB\Types\BinDataByteArrayType',
self::BINDATAUUID => 'Doctrine\ODM\MongoDB\Types\BinDataUUIDType',
self::BINDATAMD5 => 'Doctrine\ODM\MongoDB\Types\BinDataMD5Type',
self::BINDATACUSTOM => 'Doctrine\ODM\MongoDB\Types\BinDataCustomType',
@@ -35,10 +35,11 @@ public function provideData()
: -128;
return array(
- array('bin', 'test', \MongoBinData::BYTE_ARRAY),
+ array('bin', 'test', 0),
array('binFunc', 'test', \MongoBinData::FUNC),
- array('BinUUID', 'test', \MongoBinData::UUID),
- array('binMd5', 'test', \MongoBinData::MD5),
+ array('binByteArray', 'test', \MongoBinData::BYTE_ARRAY),
+ array('binUUID', 'test', \MongoBinData::UUID),
+ array('binMD5', 'test', \MongoBinData::MD5),
array('binCustom', 'test', $expectedBinCustom),
);
}
@@ -56,11 +57,14 @@ class BinDataTestUser
/** @ODM\Bin(type="bin_func") */
public $binFunc;
+ /** @ODM\Bin(type="bin_bytearray") */
+ public $binByteArray;
+
/** @ODM\Bin(type="bin_uuid") */
- public $BinUUID;
+ public $binUUID;
/** @ODM\Bin(type="bin_md5") */
- public $binMd5;
+ public $binMD5;
/** @ODM\Bin(type="bin_custom") */
public $binCustom;
@@ -263,6 +263,7 @@ public function getTestIdTypesAndStrategiesData()
array('bin', 'none', 'ABRWTIFGPEeSFf69fISAOA==', 'ABRWTIFGPEeSFf69fISAOA==', 'MongoBinData'),
array('bin', 'uuid', null, null, 'MongoBinData'),
array('bin_func', 'none', 'ABRWTIFGPEeSFf69fISAOA==', 'ABRWTIFGPEeSFf69fISAOA==', 'MongoBinData'),
+ array('bin_bytearray', 'none', 'ABRWTIFGPEeSFf69fISAOA==', 'ABRWTIFGPEeSFf69fISAOA==', 'MongoBinData'),
array('bin_uuid', 'none', 'ABRWTIFGPEeSFf69fISAOA==', 'ABRWTIFGPEeSFf69fISAOA==', 'MongoBinData'),
array('bin_md5', 'none', 'ABRWTIFGPEeSFf69fISAOA==', 'ABRWTIFGPEeSFf69fISAOA==', 'MongoBinData'),
array('bin_custom', 'none', 'ABRWTIFGPEeSFf69fISAOA==', 'ABRWTIFGPEeSFf69fISAOA==', 'MongoBinData'),
@@ -295,8 +296,9 @@ public function testBinIds($type, $expectedMongoBinDataType)
public function getTestBinIdsData()
{
return array(
- array('bin', \MongoBinData::BYTE_ARRAY),
+ array('bin', 0),
array('bin_func', \MongoBinData::FUNC),
+ array('bin_bytearray', \MongoBinData::BYTE_ARRAY),
array('bin_uuid', \MongoBinData::UUID),
array('bin_md5', \MongoBinData::MD5),
array('bin_custom', \MongoBinData::CUSTOM),

0 comments on commit 173f4ea

Please sign in to comment.