FIX: Minimal data-model changes to support PHP7.

The tidiest fix for this will be to update the namespace/naming of all
field types to follow this pattern. I’ve broken out the minimum
necessary to support PHP7 as its own commit, in case anyone needs to
backport that (e.g. if someone wanted to patch a SS 3 system to get
PHP7 support).

Rather than introduce a new API for fieldtype namespace simplification,
I’ve just used Injector. We may come up with a new configuration tool
that is better, but this has the advantage of existing now, and as such
I think is a good first step.
This commit is contained in:
Sam Minnee 2015-08-28 09:07:55 +12:00
parent 12a83d70ae
commit 083799ec03
7 changed files with 38 additions and 7 deletions

5
_config/model.yml Normal file
View File

@ -0,0 +1,5 @@
Injector:
Int:
class: SilverStripe\Model\FieldType\DBInt
Float:
class: SilverStripe\Model\FieldType\DBFloat

View File

@ -1,10 +1,13 @@
<?php
use SilverStripe\Model\FieldType\DBFloat;
/**
*
* @package framework
* @subpackage model
*/
class Double extends Float {
class Double extends DBFloat {
public function requireField() {
// HACK: MSSQL does not support double so we're using float instead

View File

@ -1,11 +1,18 @@
<?php
namespace SilverStripe\Model\FieldType;
use DB;
use DBField;
use NumericField;
/**
* Represents a floating point field.
*
* @package framework
* @subpackage model
*/
class Float extends DBField {
class DBFloat extends DBField {
public function __construct($name = null, $defaultVal = 0) {
$this->defaultVal = is_float($defaultVal) ? $defaultVal : (float) 0;

View File

@ -1,4 +1,7 @@
<?php
use SilverStripe\Model\FieldType\DBInt;
/**
* A special type Int field used for foreign keys in has_one relationships.
* @uses ImageField
@ -12,7 +15,7 @@
* @package framework
* @subpackage model
*/
class ForeignKey extends Int {
class ForeignKey extends DBInt {
/**
* @var DataObject

View File

@ -1,11 +1,20 @@
<?php
namespace SilverStripe\Model\FieldType;
use DB;
use DBField;
use NumericField;
use ArrayList;
use ArrayData;
/**
* Represents a signed 32 bit integer field.
*
* @package framework
* @subpackage model
*/
class Int extends DBField {
class DBInt extends DBField {
public function __construct($name = null, $defaultVal = 0) {
$this->defaultVal = is_int($defaultVal) ? $defaultVal : 0;
@ -64,3 +73,4 @@ class Int extends DBField {
}

View File

@ -1,4 +1,7 @@
<?php
use SilverStripe\Model\FieldType\DBInt;
/**
* A special type Int field used for primary keys.
*
@ -7,7 +10,7 @@
* @package framework
* @subpackage model
*/
class PrimaryKey extends Int {
class PrimaryKey extends DBInt {
/**
* @var DataObject
*/

View File

@ -196,11 +196,11 @@ class VersionedTest extends SapphireTest {
public function testVersionedFieldsAdded() {
$obj = new VersionedTest_DataObject();
// Check that the Version column is added as a full-fledged column
$this->assertInstanceOf('Int', $obj->dbObject('Version'));
$this->assertInstanceOf('SilverStripe\\Model\\FieldType\\DBInt', $obj->dbObject('Version'));
$obj2 = new VersionedTest_Subclass();
// Check that the Version column is added as a full-fledged column
$this->assertInstanceOf('Int', $obj2->dbObject('Version'));
$this->assertInstanceOf('SilverStripe\\Model\\FieldType\\DBInt', $obj2->dbObject('Version'));
}
public function testVersionedFieldsNotInCMS() {