Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MINOR Using late static binding instead of Object::create() calls

  • Loading branch information...
commit 40d73127ae493e60b7c81991239805387aa00d2d 1 parent 6517f44
@chillu chillu authored
View
4 admin/code/LeftAndMain.php
@@ -969,7 +969,7 @@ function EmptyForm() {
* Return the CMS's HTML-editor toolbar
*/
public function EditorToolbar() {
- return Object::create('HtmlEditorField_Toolbar', $this, "EditorToolbar");
+ return HtmlEditorField_Toolbar::create($this, "EditorToolbar");
}
/**
@@ -1032,7 +1032,7 @@ function BatchActionsForm() {
'BatchActionsForm',
new FieldList(
new HiddenField('csvIDs'),
- Object::create('DropdownField',
+ DropdownField::create(
'Action',
false,
$actionsMap
View
6 admin/code/ModelAdmin.php
@@ -117,7 +117,7 @@ function getEditForm($id = null, $fields = null) {
$list = $this->getList();
$exportButton = new GridFieldExportButton();
$exportButton->setExportColumns($this->getExportFields());
- $listField = Object::create('GridField',
+ $listField = GridField::create(
$this->modelClass,
false,
$list,
@@ -180,9 +180,9 @@ public function SearchForm() {
$form = new Form($this, "SearchForm",
$context->getSearchFields(),
new FieldList(
- Object::create('ResetFormAction','clearsearch', _t('ModelAdmin.CLEAR_SEARCH','Clear Search'))
+ ResetFormAction::create('clearsearch', _t('ModelAdmin.CLEAR_SEARCH','Clear Search'))
->setUseButtonTag(true)->addExtraClass('ss-ui-action-minor'),
- Object::create('FormAction', 'search', _t('MemberTableField.SEARCH', 'Search'))
+ FormAction::create('search', _t('MemberTableField.SEARCH', 'Search'))
->setUseButtonTag(true)
),
new RequiredFields()
View
8 admin/code/SecurityAdmin.php
@@ -43,7 +43,7 @@ public function getEditForm($id = null, $fields = null) {
$record = $this->getRecord($id);
if($record && !$record->canView()) return Security::permissionFailure($this);
- $memberList = Object::create('GridField',
+ $memberList = GridField::create(
'Members',
false,
DataList::create('Member'),
@@ -52,8 +52,7 @@ public function getEditForm($id = null, $fields = null) {
)->addExtraClass("members_grid");
$memberListConfig->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator());
- $groupList = Object::create('GridField',
- 'Groups',
+ $groupList = GridField::create( 'Groups',
false,
DataList::create('Group'),
GridFieldConfig_RecordEditor::create()
@@ -104,8 +103,7 @@ public function getEditForm($id = null, $fields = null) {
// Add roles editing interface
if(Permission::check('APPLY_ROLES')) {
- $rolesField = Object::create('GridField',
- 'Roles',
+ $rolesField = GridField::create( 'Roles',
false,
DataList::create('PermissionRole'),
GridFieldConfig_RecordEditor::create()
View
2  core/Convert.php
@@ -320,7 +320,7 @@ static function raw2mailto($data) {
* @return string
*/
public static function raw2url($title) {
- $f = Object::create('URLSegmentFilter');
+ $f = URLSegmentFilter::create();
return $f->filter($title);
}
}
View
6 core/Object.php
@@ -87,7 +87,7 @@ public function config() {
* or calling on Object and passing the class name as the first parameter. The following
* are equivalent:
* $list = DataList::create('SiteTree');
- * $list = Object::create('DataList', 'SiteTree');
+ * $list = DataList::create('SiteTree');
*
* @param string $class the class name
* @param mixed $arguments,... arguments to pass to the constructor
@@ -121,7 +121,7 @@ public static function create() {
* are respected.
*
* `Object::create_from_string("Versioned('Stage','Live')")` will return the result of
- * `Object::create('Versioned', 'Stage', 'Live);`
+ * `Versioned::create('Stage', 'Live);`
*
* It is designed for simple, clonable objects. The first time this method is called for a given
* string it is cached, and clones of that object are returned.
@@ -130,7 +130,7 @@ public static function create() {
* impossible to pass null as the firstArg argument.
*
* `Object::create_from_string("Varchar(50)", "MyField")` will return the result of
- * `Object::create('Vachar', 'MyField', '50');`
+ * `Vachar::create('MyField', '50');`
*
* Arguments are always strings, although this is a quirk of the current implementation rather
* than something that can be relied upon.
View
22 dev/DevelopmentAdmin.php
@@ -92,7 +92,7 @@ function index() {
// This action is sake-only right now.
unset($actions["modules/add"]);
- $renderer = Object::create('DebugView');
+ $renderer = DebugView::create();
$renderer->writeHeader();
$renderer->writeInfo("Sapphire Development Tools", Director::absoluteBaseURL());
$base = Director::baseURL();
@@ -116,33 +116,33 @@ function index() {
}
function tests($request) {
- return Object::create('TestRunner');
+ return TestRunner::create();
}
function jstests($request) {
- return Object::create('JSTestRunner');
+ return JSTestRunner::create();
}
function tasks() {
- return Object::create('TaskRunner');
+ return TaskRunner::create();
}
function viewmodel() {
- return Object::create('ModelViewer');
+ return ModelViewer::create();
}
function build($request) {
if(Director::is_cli()) {
- $da = Object::create('DatabaseAdmin');
+ $da = DatabaseAdmin::create();
return $da->handleRequest($request, $this->model);
} else {
- $renderer = Object::create('DebugView');
+ $renderer = DebugView::create();
$renderer->writeHeader();
$renderer->writeInfo("Environment Builder", Director::absoluteBaseURL());
echo "<div style=\"margin: 0 2em\">";
echo "<div class=\"status pending\"><h2 class='buildProgress'>Database is building.... Check below for any errors</h2><h2 class='buildCompleted'>Database has been built successfully</h2></div>";
- $da = Object::create('DatabaseAdmin');
+ $da = DatabaseAdmin::create();
return $da->handleRequest($request, $this->model);
echo "</div>";
@@ -157,10 +157,10 @@ function build($request) {
* 'build/defaults' => 'buildDefaults',
*/
function buildDefaults() {
- $da = Object::create('DatabaseAdmin');
+ $da = DatabaseAdmin::create();
if (!Director::is_cli()) {
- $renderer = Object::create('DebugView');
+ $renderer = DebugView::create();
$renderer->writeHeader();
$renderer->writeInfo("Defaults Builder", Director::absoluteBaseURL());
echo "<div style=\"margin: 0 2em\">";
@@ -189,6 +189,6 @@ function errors() {
}
function viewcode($request) {
- return Object::create('CodeViewer');
+ return CodeViewer::create();
}
}
View
2  docs/en/topics/rich-text-editing.md
@@ -93,7 +93,7 @@ of the CMS you have to take care of instanciation yourself:
// File: mysite/code/MyController.php
class MyObjectController extends Controller {
public function EditorToolbar() {
- return Object::create('HtmlEditorField_Toolbar', $this, "EditorToolbar");
+ return HtmlEditorField_Toolbar::create($this, "EditorToolbar");
}
}
View
6 docs/en/topics/security.md
@@ -213,8 +213,8 @@ PHP:
public function search($request) {
$htmlTitle = '<p>Your results for:' . Convert::raw2xml($request->getVar('Query')) . '</p>';
return $this->customise(array(
- 'Query' => DBField::create('Text', $request->getVar('Query')),
- 'HTMLTitle' => DBField::create('HTMLText', $htmlTitle)
+ 'Query' => Text::create($request->getVar('Query')),
+ 'HTMLTitle' => HTMLText::create($htmlTitle)
));
}
}
@@ -243,7 +243,7 @@ PHP:
$rssRelativeLink = "/rss?Query=" . urlencode($_REQUEST['query']) . "&sortOrder=asc";
$rssLink = Controller::join_links($this->Link(), $rssRelativeLink);
return $this->customise(array(
- "RSSLink" => DBField::create("Text", $rssLink),
+ "RSSLink" => Text::create($rssLink),
));
}
}
View
10 filesystem/File.php
@@ -349,12 +349,12 @@ function getCMSFields($params = null) {
}
//create the file attributes in a FieldGroup
- $filePreview = FormField::create('CompositeField',
- FormField::create('CompositeField',
+ $filePreview = CompositeField::create(
+ CompositeField::create(
$previewField
)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'),
- FormField::create('CompositeField',
- FormField::create('CompositeField',
+ CompositeField::create(
+ CompositeField::create(
new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':'),
new ReadonlyField("Size", _t('AssetTableField.SIZE','File size') . ':', $this->getSize()),
$urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL','URL'),
@@ -566,7 +566,7 @@ function setName($name) {
if(!$name) $name = $this->Title;
// Fix illegal characters
- $filter = Object::create('FileNameFilter');
+ $filter = FileNameFilter::create();
$name = $filter->filter($name);
// We might have just turned it blank, so check again.
View
4 filesystem/FileNameFilter.php
@@ -26,7 +26,7 @@
*
* See {@link URLSegmentFilter} for a more generic implementation.
*/
-class FileNameFilter {
+class FileNameFilter extends Object {
/**
* @var Boolean
@@ -100,7 +100,7 @@ function getReplacements() {
*/
function getTransliterator() {
if($this->transliterator === null && self::$default_use_transliterator) {
- $this->transliterator = Object::create('Transliterator');
+ $this->transliterator = Transliterator::create();
}
return $this->transliterator;
}
View
2  filesystem/Folder.php
@@ -232,7 +232,7 @@ function addUploadToFolder($tmpFile) {
// $parentFolder = Folder::findOrMake("Uploads");
// Generate default filename
- $nameFilter = Object::create('FileNameFilter');
+ $nameFilter = FileNameFilter::create();
$file = $nameFilter->filter($tmpFile['name']);
while($file[0] == '_' || $file[0] == '.') {
$file = substr($file, 1);
View
2  filesystem/Upload.php
@@ -131,7 +131,7 @@ function load($tmpFile, $folderPath = false) {
}
// Generate default filename
- $nameFilter = Object::create('FileNameFilter');
+ $nameFilter = FileNameFilter::create();
$file = $nameFilter->filter($tmpFile['name']);
$fileName = basename($file);
View
2  forms/ComplexTableField.php
@@ -816,7 +816,7 @@ function __construct($controller, $name, $fields, $validator, $readonly, $dataOb
$actions = new FieldList();
if(!$readonly) {
$actions->push(
- Object::create('FormAction',
+ FormAction::create(
"saveComplexTableField",
_t('CMSMain.SAVE', 'Save')
)
View
4 forms/DateField.php
@@ -112,7 +112,7 @@ function __construct($name, $title = null, $value = null) {
function FieldHolder() {
// TODO Replace with properly extensible view helper system
- $d = Object::create('DateField_View_JQuery', $this);
+ $d = DateField_View_JQuery::create($this);
$d->onBeforeRender();
$html = parent::FieldHolder();
$html = $d->onAfterRender($html);
@@ -459,7 +459,7 @@ function validate($validator) {
* @package sapphire
* @subpackage forms
*/
-class DateField_View_JQuery {
+class DateField_View_JQuery extends Object {
protected $field;
View
4 forms/DatetimeField.php
@@ -57,8 +57,8 @@ class DatetimeField extends FormField {
function __construct($name, $title = null, $value = ""){
$this->config = self::$default_config;
- $this->dateField = Object::create('DateField', $name . '[date]', false);
- $this->timeField = Object::create('TimeField', $name . '[time]', false);
+ $this->dateField = DateField::create($name . '[date]', false);
+ $this->timeField = TimeField::create($name . '[time]', false);
$this->timezoneField = new HiddenField($this->getName() . '[timezone]');
parent::__construct($name, $title, $value);
View
2  forms/HtmlEditorField.php
@@ -322,7 +322,7 @@ function LinkForm() {
)
),
new FieldList(
- Object::create('ResetFormAction', 'remove', _t('HtmlEditorField.BUTTONREMOVELINK', 'Remove link'))
+ ResetFormAction::create('remove', _t('HtmlEditorField.BUTTONREMOVELINK', 'Remove link'))
->addExtraClass('ss-ui-action-destructive')
->setUseButtonTag(true)
,
View
4 forms/UploadField.php
@@ -407,7 +407,7 @@ public function handleItem(SS_HTTPRequest $request) {
* @return UploadField_ItemHandler
*/
public function getItemHandler($itemID) {
- return Object::create('UploadField_ItemHandler', $this, $itemID);
+ return UploadField_ItemHandler::create($this, $itemID);
}
/**
@@ -415,7 +415,7 @@ public function getItemHandler($itemID) {
* @return UploadField_ItemHandler
*/
public function handleSelect(SS_HTTPRequest $request) {
- return Object::create('UploadField_SelectHandler', $this, $this->folderName);
+ return UploadField_SelectHandler::create($this, $this->folderName);
}
/**
View
4 forms/gridfield/GridFieldDeleteAction.php
@@ -98,7 +98,7 @@ public function getActions($gridField) {
*/
public function getColumnContent($gridField, $record, $columnName) {
if($this->removeRelation) {
- $field = Object::create('GridField_FormAction', $gridField, 'UnlinkRelation'.$record->ID, false, "unlinkrelation", array('RecordID' => $record->ID))
+ $field = GridField_FormAction::create($gridField, 'UnlinkRelation'.$record->ID, false, "unlinkrelation", array('RecordID' => $record->ID))
->addExtraClass('gridfield-button-unlink')
->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink"))
->setAttribute('data-icon', 'chain--minus');
@@ -106,7 +106,7 @@ public function getColumnContent($gridField, $record, $columnName) {
if(!$record->canDelete()) {
return;
}
- $field = Object::create('GridField_FormAction', $gridField, 'DeleteRecord'.$record->ID, false, "deleterecord", array('RecordID' => $record->ID))
+ $field = GridField_FormAction::create($gridField, 'DeleteRecord'.$record->ID, false, "deleterecord", array('RecordID' => $record->ID))
->addExtraClass('gridfield-button-delete')
->setAttribute('title', _t('GridAction.Delete', "Delete"))
->setAttribute('data-icon', 'decline');
View
4 forms/gridfield/GridFieldFilterHeader.php
@@ -123,11 +123,11 @@ public function getHTMLFragments($gridField) {
$field = new FieldGroup(
$field,
- Object::create('GridField_FormAction', $gridField, 'filter', false, 'filter', null)
+ GridField_FormAction::create($gridField, 'filter', false, 'filter', null)
->addExtraClass('ss-gridfield-button-filter')
->setAttribute('title', _t('GridField.Filter', "Filter"))
,
- Object::create('GridField_FormAction', $gridField, 'reset', false, 'reset', null)
+ GridField_FormAction::create($gridField, 'reset', false, 'reset', null)
->addExtraClass('ss-gridfield-button-reset')
->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
);
View
2  model/Image.php
@@ -153,7 +153,7 @@ function loadUploadedImage($tmpFile) {
}
// Generate default filename
- $nameFilter = Object::create('FileNameFilter');
+ $nameFilter = FileNameFilter::create();
$file = $nameFilter->filter($tmpFile['name']);
if(!$file) $file = "file.jpg";
View
8 model/Transliterator.php
@@ -13,17 +13,13 @@
* @package sapphire
* @subpackage model
*/
-class Transliterator {
+class Transliterator extends Object {
/**
* Allow the use of iconv() to perform transliteration. Set to false to disable.
* Even if this variable is true, iconv() won't be used if it's not installed.
*/
static $use_iconv = false;
-
- function __construct() {
- // A constructor is necessary for Object::create() to work
- }
-
+
/**
* Convert the given utf8 string to a safe ASCII source
*/
View
9 model/URLSegmentFilter.php
@@ -14,12 +14,7 @@
*
* See {@link FileNameFilter} for similar implementation for filesystem-based URLs.
*/
-class URLSegmentFilter {
-
- /**
- * Necessary to support {@link Object::create()}
- */
- function __construct() {}
+class URLSegmentFilter extends Object {
/**
* @var Boolean
@@ -104,7 +99,7 @@ function getReplacements() {
*/
function getTransliterator() {
if($this->transliterator === null && self::$default_use_transliterator) {
- $this->transliterator = Object::create('Transliterator');
+ $this->transliterator = Transliterator::create();
}
return $this->transliterator;
}
View
7 security/Group.php
@@ -66,8 +66,7 @@ public function getCMSFields($params = null) {
new TabSet("Root",
new Tab('Members', _t('SecurityAdmin.MEMBERS', 'Members'),
new TextField("Title", $this->fieldLabel('Title')),
- $parentidfield = Object::create('DropdownField',
- 'ParentID',
+ $parentidfield = DropdownField::create( 'ParentID',
$this->fieldLabel('Parent'),
DataList::create('Group')->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
)->setEmptyString(' ')
@@ -100,7 +99,7 @@ public function getCMSFields($params = null) {
$config->getComponentByType('GridFieldAddExistingAutocompleter')
->setResultsFormat('$Title ($Email)')->setSearchFields(array('FirstName', 'Surname', 'Email'));
$config->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator());
- $memberList = Object::create('GridField', 'Members',false, $this->Members(), $config)->addExtraClass('members_grid');
+ $memberList = GridField::create('Members',false, $this->Members(), $config)->addExtraClass('members_grid');
// @todo Implement permission checking on GridField
//$memberList->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd'));
$fields->addFieldToTab('Root.Members', $memberList);
@@ -164,7 +163,7 @@ public function getCMSFields($params = null) {
$inheritedRoleIDs = array();
}
- $rolesField = Object::create('ListboxField', 'Roles', false, $allRoles->map()->toArray())
+ $rolesField = ListboxField::create('Roles', false, $allRoles->map()->toArray())
->setMultiple(true)
->setDefaultItems($groupRoleIDs)
->setAttribute('data-placeholder', _t('Group.AddRole', 'Add a role for this group'))
View
10 security/Member.php
@@ -151,7 +151,7 @@ function requireDefaultRecords() {
if(!$admins) {
// Leave 'Email' and 'Password' are not set to avoid creating
// persistent logins in the database. See Security::setDefaultAdmin().
- $admin = Object::create('Member');
+ $admin = Member::create();
$admin->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
$admin->write();
$admin->Groups()->add($adminGroup);
@@ -480,13 +480,13 @@ static function member_from_autologinhash($RAW_hash, $login = false) {
function sendInfo($type = 'signup', $data = null) {
switch($type) {
case "signup":
- $e = Object::create('Member_SignupEmail');
+ $e = Member_SignupEmail::create();
break;
case "changePassword":
- $e = Object::create('Member_ChangePasswordEmail');
+ $e = Member_ChangePasswordEmail::create();
break;
case "forgotPassword":
- $e = Object::create('Member_ForgotPasswordEmail');
+ $e = Member_ForgotPasswordEmail::create();
break;
}
@@ -1134,7 +1134,7 @@ public function getCMSFields($params = null) {
$groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
asort($groupsMap);
$fields->addFieldToTab('Root.Main',
- Object::create('ListboxField', 'DirectGroups', singleton('Group')->i18n_plural_name())
+ ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())
->setMultiple(true)->setSource($groupsMap)
);
View
3  security/Security.php
@@ -448,8 +448,7 @@ public function lostpassword() {
* @return Form Returns the lost password form
*/
public function LostPasswordForm() {
- return Object::create('MemberLoginForm',
- $this,
+ return MemberLoginForm::create( $this,
'LostPasswordForm',
new FieldList(
new EmailField('Email', _t('Member.EMAIL', 'Email'))
View
14 tests/core/ObjectTest.php
@@ -113,7 +113,7 @@ function testStaticSettingOnInstances() {
* Tests that {@link Object::create()} correctly passes all arguments to the new object
*/
public function testCreateWithArgs() {
- $createdObj = Object::create('ObjectTest_CreateTest', 'arg1', 'arg2', array(), null, 'arg5');
+ $createdObj = ObjectTest_CreateTest::create('arg1', 'arg2', array(), null, 'arg5');
$this->assertEquals($createdObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
$strongObj = Object::strong_create('ObjectTest_CreateTest', 'arg1', 'arg2', array(), null, 'arg5');
@@ -129,18 +129,18 @@ public function testCreateLateStaticBinding() {
* Tests that {@link Object::useCustomClass()} correnctly replaces normal and strong objects
*/
public function testUseCustomClass() {
- $obj1 = Object::create('ObjectTest_CreateTest');
+ $obj1 = ObjectTest_CreateTest::create();
$this->assertTrue($obj1 instanceof ObjectTest_CreateTest);
Object::useCustomClass('ObjectTest_CreateTest', 'ObjectTest_CreateTest2');
- $obj2 = Object::create('ObjectTest_CreateTest');
+ $obj2 = ObjectTest_CreateTest::create();
$this->assertTrue($obj2 instanceof ObjectTest_CreateTest2);
$obj2_2 = Object::strong_create('ObjectTest_CreateTest');
$this->assertTrue($obj2_2 instanceof ObjectTest_CreateTest);
Object::useCustomClass('ObjectTest_CreateTest', 'ObjectTest_CreateTest3', true);
- $obj3 = Object::create('ObjectTest_CreateTest');
+ $obj3 = ObjectTest_CreateTest::create();
$this->assertTrue($obj3 instanceof ObjectTest_CreateTest3);
$obj3_2 = Object::strong_create('ObjectTest_CreateTest');
@@ -269,12 +269,12 @@ public function testRemoveExtension() {
}
public function testParentClass() {
- $this->assertEquals(Object::create('ObjectTest_MyObject')->parentClass(), 'Object');
+ $this->assertEquals(ObjectTest_MyObject::create()->parentClass(), 'Object');
}
public function testIsA() {
- $this->assertTrue(Object::create('ObjectTest_MyObject') instanceof Object);
- $this->assertTrue(Object::create('ObjectTest_MyObject') instanceof ObjectTest_MyObject);
+ $this->assertTrue(ObjectTest_MyObject::create() instanceof Object);
+ $this->assertTrue(ObjectTest_MyObject::create() instanceof ObjectTest_MyObject);
}
/**
View
6 tests/forms/gridfield/GridFieldDetailFormTest.php
@@ -144,7 +144,7 @@ function getCMSFields($params = null) {
$fields = parent::getCMSFields($params);
// TODO No longer necessary once FormScaffolder uses GridField
$fields->replaceField('Categories',
- Object::create('GridField', 'Categories', 'Categories',
+ GridField::create('Categories', 'Categories',
$this->Categories(),
GridFieldConfig_RelationEditor::create()
)
@@ -166,7 +166,7 @@ function getCMSFields($params = null) {
$fields = parent::getCMSFields($params);
// TODO No longer necessary once FormScaffolder uses GridField
$fields->replaceField('People',
- Object::create('GridField', 'People', 'People',
+ GridField::create('People', 'People',
$this->People(),
GridFieldConfig_RelationEditor::create()
)
@@ -188,7 +188,7 @@ function getCMSFields($params = null) {
$fields = parent::getCMSFields($params);
// TODO No longer necessary once FormScaffolder uses GridField
$fields->replaceField('People',
- Object::create('GridField', 'People', 'People',
+ GridField::create('People', 'People',
$this->People(),
GridFieldConfig_RelationEditor::create()
)
View
2  view/ViewableData.php
@@ -717,7 +717,7 @@ public function forTemplate($field = null) {
// check for an extra attached data
if($this->object->hasMethod('data') && $this->object->data() != $this->object) {
- $debug .= Object::create('ViewableData_Debugger', $this->object->data())->forTemplate();
+ $debug .= ViewableData_Debugger::create($this->object->data())->forTemplate();
}
return $debug;
Please sign in to comment.
Something went wrong with that request. Please try again.