From 04a10a4265e27b3d69387c6bcad05642e4abde5a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 30 Jan 2012 23:13:42 +0100 Subject: [PATCH] MINOR Updated coding conventions to require the 'public' keyword for class methods and variables --- docs/en/howto/csv-import.md | 10 +++---- docs/en/howto/extend-cms-interface.md | 6 ++-- docs/en/misc/coding-conventions.md | 28 +++++++++++-------- docs/en/misc/release-process.md | 2 +- docs/en/misc/ss-markdown.md | 2 +- docs/en/reference/dataextension.md | 4 +-- docs/en/reference/dataobject.md | 2 +- docs/en/reference/execution-pipeline.md | 4 +-- docs/en/reference/image.md | 2 +- docs/en/reference/member.md | 10 +++---- docs/en/reference/partial-caching.md | 4 +-- docs/en/reference/permission.md | 4 +-- docs/en/reference/restfulservice.md | 8 +++--- docs/en/reference/rssfeed.md | 10 +++---- docs/en/reference/site-reports.md | 12 ++++---- docs/en/reference/siteconfig.md | 2 +- docs/en/reference/sitetree.md | 16 +++++------ docs/en/reference/sqlquery.md | 2 +- docs/en/reference/staticpublisher.md | 16 +++++------ docs/en/reference/tablelistfield.md | 6 ++-- docs/en/reference/templates.md | 10 +++---- docs/en/reference/typography.md | 2 +- docs/en/reference/versioned.md | 4 +-- docs/en/topics/commandline.md | 2 +- docs/en/topics/controller.md | 2 +- docs/en/topics/css.md | 2 +- docs/en/topics/datamodel.md | 16 +++++------ docs/en/topics/form-validation.md | 2 +- docs/en/topics/forms.md | 12 ++++---- docs/en/topics/grid-field.md | 14 +++++----- docs/en/topics/i18n.md | 2 +- docs/en/topics/module-development.md | 2 +- docs/en/topics/page-types.md | 4 +-- docs/en/topics/security.md | 16 +++++------ .../topics/testing/create-functional-test.md | 4 +-- .../en/topics/testing/create-sapphire-test.md | 2 +- docs/en/topics/widgets.md | 18 ++++++------ docs/en/tutorials/2-extending-a-basic-site.md | 12 ++++---- docs/en/tutorials/3-forms.md | 12 ++++---- docs/en/tutorials/4-site-search.md | 2 +- .../5-dataobject-relationship-management.md | 18 ++++++------ 41 files changed, 156 insertions(+), 152 deletions(-) diff --git a/docs/en/howto/csv-import.md b/docs/en/howto/csv-import.md index 07fdf0d0a..a0aa50ba4 100644 --- a/docs/en/howto/csv-import.md +++ b/docs/en/howto/csv-import.md @@ -70,11 +70,11 @@ You can have more customized logic and interface feedback through a custom contr class MyController extends Controller { protected $template = "BlankPage"; - function Link($action = null) { + public function Link($action = null) { return Controller::join_links('MyController', $action); } - function Form() { + public function Form() { $form = new Form( $this, 'Form', @@ -89,7 +89,7 @@ You can have more customized logic and interface feedback through a custom contr return $form; } - function doUpload($data, $form) { + public function doUpload($data, $form) { $loader = new CsvBulkLoader('MyDataObject'); $results = $loader->load($_FILES['CsvFile']['tmp_name']); $messages = array(); @@ -177,13 +177,13 @@ Sample implementation of a custom loader. Assumes a CSV-file in a certain format 'callback' => 'getTeamByTitle' ) ); - static function importFirstAndLastName(&$obj, $val, $record) { + public static function importFirstAndLastName(&$obj, $val, $record) { $parts = explode(' ', $val); if(count($parts) != 2) return false; $obj->FirstName = $parts[0]; $obj->LastName = $parts[1]; } - static function getTeamByTitle(&$obj, $val, $record) { + public static function getTeamByTitle(&$obj, $val, $record) { $SQL_val = Convert::raw2sql($val); return DataObject::get_one( 'FootballTeam', "Title = '{$SQL_val}'" diff --git a/docs/en/howto/extend-cms-interface.md b/docs/en/howto/extend-cms-interface.md index 6be63dbe8..bc3339646 100644 --- a/docs/en/howto/extend-cms-interface.md +++ b/docs/en/howto/extend-cms-interface.md @@ -85,10 +85,10 @@ Create a new file called `zzz_admin/code/BookmarkedPageExtension.php` and insert :::php array('IsBookmarked' => 'Boolean')); } - function updateCMSFields(&$fields) { + public function updateCMSFields(&$fields) { $fields->addFieldToTab('Root.Main', new CheckboxField('IsBookmarked', "Show in CMS bookmarks?") ); @@ -114,7 +114,7 @@ Add the following code to a new file `zzz_admin/code/BookmarkedLeftAndMainExtens :::php where('"IsBookmarked" = 1'); } } diff --git a/docs/en/misc/coding-conventions.md b/docs/en/misc/coding-conventions.md index 2ba87adc7..68296686c 100644 --- a/docs/en/misc/coding-conventions.md +++ b/docs/en/misc/coding-conventions.md @@ -48,7 +48,7 @@ Successive capitalized letters are not allowed, e.g. a class `XMLImporter` is no Static methods should be in `lowercase_with_underscores()` format: :::php - static function my_static_method() {} + public static function my_static_method() {} Action handlers on controllers should be in `completelylowercase()` format. This is because they go into the controller URL in the same format (eg, `home/successfullyinstalled`). @@ -56,7 +56,7 @@ Method names are allowed to contain underscores here, in order to allow URL part (`mypage\my-action` gets translated to `my_action()` automatically). :::php - function mycontrolleraction() {} + public function mycontrolleraction() {} Object methods that will be callable from templates should be in `$this->UpperCamelCase()` format. Alternatively, `$this->getUpperCamelCase()` will work the same way in templates - @@ -65,7 +65,9 @@ you can access both coding styles as `$UpperCamelCase`. Other instance methods should be in `$this->lowerCamelCase()` format: :::php - function myInstanceMethod() {} + public function myInstanceMethod() {} + +Methods inside classes must always declare their visibility by using one of the private, protected, or public modifiers. ### Variables @@ -74,10 +76,12 @@ Static variables should be `self::$lowercase_with_underscores` :::php self::$my_static_variable = 'foo'; -Object variables should be `$this->lowerCamelCase` +Member variables should be `$this->lowerCamelCase` :::php - $this->myObjectVariable = 'foo'; + $this->myMemberVariable = 'foo'; + +Member variables always declare their visibility by using one of the private, protected, or public modifiers ### Constants @@ -232,20 +236,20 @@ No method or function invocation is allowed to have spaces directly before or after the opening parathesis, as well as no space before the closing parenthesis. :::php - function foo($arg1, $arg2) {} // good - function foo ( $arg1, $arg2 ) {} // bad + public function foo($arg1, $arg2) {} // good + public function foo ( $arg1, $arg2 ) {} // bad Keep the opening brace on the same line as the statement. :::php // good - function foo() { + public function foo() { // ... } :::php // bad - function bar() + public function bar() { // ... } @@ -346,7 +350,7 @@ Try to avoid using PHP's ability to mix HTML into the code. :::php // PHP code - function getTitle() { + public function getTitle() { return "

Bad Example

"; } @@ -357,7 +361,7 @@ Better: Keep HTML in template files: :::php // PHP code - function getTitle() { + public function getTitle() { return "Better Example"; } @@ -410,7 +414,7 @@ Example: Put code into the classes in the following order (where applicable). * Static variables - * Object variables + * Member variables * Static methods * Data-model definition static variables. (`$db`, `$has_one`, `$many_many`, etc) * Commonly used methods like `getCMSFields()` diff --git a/docs/en/misc/release-process.md b/docs/en/misc/release-process.md index ca516974f..fe3490160 100644 --- a/docs/en/misc/release-process.md +++ b/docs/en/misc/release-process.md @@ -107,7 +107,7 @@ Here's an example for replacing `Director::isDev()` with a (theoretical) `Env::i * Returns true if your are in development mode * @deprecated (since 2.2.2) Use {@link Env::is_dev()} instead. */ - function isDev() { + public function isDev() { user_error("DEPRECATED: Use Env::is_dev() instead.", E_USER_NOTICE); return Env::is_dev(); } diff --git a/docs/en/misc/ss-markdown.md b/docs/en/misc/ss-markdown.md index 0fc692c2d..e82f15d45 100644 --- a/docs/en/misc/ss-markdown.md +++ b/docs/en/misc/ss-markdown.md @@ -76,7 +76,7 @@ Example for PHP: :::php class Page extends SiteTree { - function myFunction() { + public function myFunction() { // ... } } diff --git a/docs/en/reference/dataextension.md b/docs/en/reference/dataextension.md index 584c4bf39..a0ffeadd1 100644 --- a/docs/en/reference/dataextension.md +++ b/docs/en/reference/dataextension.md @@ -52,7 +52,7 @@ The function should return a map where the keys are the names of the static vari :::php class CustomMember extends DataExtension { - function extraStatics() { + public function extraStatics() { return array( 'db' => array( 'AvatarURL' => 'Varchar', @@ -161,7 +161,7 @@ extended by. class CustomerWorkflow extends DataExtension { - function IsMarkedForDeletion() { + public function IsMarkedForDeletion() { return ($this->owner->Account()->IsMarkedForDeletion == 1) ? true : false; } diff --git a/docs/en/reference/dataobject.md b/docs/en/reference/dataobject.md index d5f1269bc..587e1ed95 100644 --- a/docs/en/reference/dataobject.md +++ b/docs/en/reference/dataobject.md @@ -17,7 +17,7 @@ which returns a `[api:FieldList]`''. :::php class MyPage extends Page { - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Content',new CheckboxField('CustomProperty')); return $fields; diff --git a/docs/en/reference/execution-pipeline.md b/docs/en/reference/execution-pipeline.md index 413867129..e42b1a3e5 100644 --- a/docs/en/reference/execution-pipeline.md +++ b/docs/en/reference/execution-pipeline.md @@ -64,7 +64,7 @@ This will add an object with ID 12 to the cart. When you create a function, you can access the ID like this: :::php - function addToCart ($request) { + public function addToCart ($request) { $param = $r->allParams(); echo "my ID = ".$param["ID"]; $obj = DataObject::get("myProduct", $param["ID"]); @@ -83,7 +83,7 @@ You can access the following controller-method with /team/signup class Team extends DataObject {} class Team_Controller extends Controller { - function signup($id, $otherId) { + public function signup($id, $otherId) { return $this->renderWith('MyTemplate'); } } diff --git a/docs/en/reference/image.md b/docs/en/reference/image.md index 14a89ca78..62a8fcab8 100644 --- a/docs/en/reference/image.md +++ b/docs/en/reference/image.md @@ -59,7 +59,7 @@ You can also create your own functions by extending the image class, for example return $this->getWidth() < $this->getHeight(); } - function generatePaddedImageByWidth(GD $gd,$width=600,$color="fff"){ + public function generatePaddedImageByWidth(GD $gd,$width=600,$color="fff"){ return $gd->paddedResize($width, round($gd->getHeight()/($gd->getWidth()/$width),0),$color); } diff --git a/docs/en/reference/member.md b/docs/en/reference/member.md index c0bc0f97e..d8846a01a 100644 --- a/docs/en/reference/member.md +++ b/docs/en/reference/member.md @@ -63,12 +63,12 @@ Note that if you want to look this class-name up, you can call Object::getCustom ## Overloading getCMSFields() -If you overload the built-in function getCMSFields(), then you can change the form that is used to view & edit member +If you overload the built-in public function getCMSFields(), then you can change the form that is used to view & edit member details in the newsletter system. This function returns a `[api:FieldList]` object. You should generally start by calling parent::getCMSFields() and manipulate the `[api:FieldList]` from there. :::php - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->insertBefore(new TextField("Age"), "HTMLEmail"); $fields->removeByName("JobTitle"); @@ -106,18 +106,18 @@ things, you should add appropriate `[api:Permission::checkMember()]` calls to th * Modify the field set to be displayed in the CMS detail pop-up */ - function updateCMSFields(FieldList $currentFields) { + public function updateCMSFields(FieldList $currentFields) { // Only show the additional fields on an appropriate kind of use if(Permission::checkMember($this->owner->ID, "VIEW_FORUM")) { // Edit the FieldList passed, adding or removing fields as necessary } } - function extraStatics() { + public function extraStatics() { // Return an array containing keys 'db', 'has_one', 'many_many', 'belongs_many_many', } - function somethingElse() { + public function somethingElse() { // You can add any other methods you like, which you can call directly on the member object. } } diff --git a/docs/en/reference/partial-caching.md b/docs/en/reference/partial-caching.md index 01f8ebf55..6452b2255 100644 --- a/docs/en/reference/partial-caching.md +++ b/docs/en/reference/partial-caching.md @@ -84,7 +84,7 @@ That last example is a bit large, and is complicating our template up with icky logic into the controller :::php - function FavouriteCacheKey() { + public function FavouriteCacheKey() { $member = Member::currentUser(); return implode('_', array( 'favourites', @@ -122,7 +122,7 @@ which will invalidate after the cache lifetime expires. If you need more control configurable only on a site-wide basis), you could add a special function to your controller: :::php - function BlogStatisticsCounter() { + public function BlogStatisticsCounter() { return (int)(time() / 60 / 5); // Returns a new number every five minutes } diff --git a/docs/en/reference/permission.md b/docs/en/reference/permission.md index 4b313e8bd..f3ecb278f 100644 --- a/docs/en/reference/permission.md +++ b/docs/en/reference/permission.md @@ -28,11 +28,11 @@ map of permission code names with a human readable explanation of its purpose (s :::php class Page_Controller implements PermissionProvider { - function init() { + public function init() { if(!Permission::check("VIEW_SITE")) Security::permissionFailure(); } - function providePermissions() { + public function providePermissions() { return array( "VIEW_SITE" => "Access the site", ); diff --git a/docs/en/reference/restfulservice.md b/docs/en/reference/restfulservice.md index b7621ca0f..33379aec5 100644 --- a/docs/en/reference/restfulservice.md +++ b/docs/en/reference/restfulservice.md @@ -30,7 +30,7 @@ RestfulService (see [flickrservice](http://silverstripe.org/flickr-module/) and //example for extending RestfulService class FlickrService extends RestfulService { - function __construct($expiry=NULL){ + public function __construct($expiry=NULL){ parent::__construct('http://www.flickr.com/services/rest/', $expiry); $this->checkErrors = true; } @@ -121,7 +121,7 @@ could delgate the error handling to it's descendant class. To handle the errors This will raise Youtube API specific error messages (if any). */ - function errorCatch($response){ + public function errorCatch($response){ $err_msg = $response; if(strpos($err_msg, '<') === false) //user_error("YouTube Service Error : $err_msg", E_USER_ERROR); @@ -135,7 +135,7 @@ could delgate the error handling to it's descendant class. To handle the errors If you want to bypass error handling on your sub-classes you could define that in the constructor. :::php - function __construct($expiry=NULL){ + public function __construct($expiry=NULL){ parent::__construct('http://www.flickr.com/services/rest/', $expiry); $this->checkErrors = false; //Set checkErrors to false to bypass error checking } @@ -152,7 +152,7 @@ Put something like this code in mysite/code/Page.php inside class Page_Controlle :::php // Accepts an RSS feed URL and outputs a list of links from it - function RestfulLinks($url){ + public function RestfulLinks($url){ $delicious = new RestfulService($url); $conn = $delicious->connect(); diff --git a/docs/en/reference/rssfeed.md b/docs/en/reference/rssfeed.md index 0be4ec7f3..097f06970 100644 --- a/docs/en/reference/rssfeed.md +++ b/docs/en/reference/rssfeed.md @@ -17,12 +17,12 @@ your website, so its advisable to just create feeds from subclasses of `[api:Sit * The second part sets up /this-page/rss to return the RSS feed. This one returns the children of the current page. :::php - function init() { + public function init() { RSSFeed::linkToFeed($this->Link() . "rss", "RSS feed of this blog"); parent::init(); } - function rss() { + public function rss() { $rss = new RSSFeed($this->Children(), $this->Link(), "My feed", "This is an example feed.", "Title", "Content", "Author"); $rss->outputToBrowser(); } @@ -45,17 +45,17 @@ something like this: class Page_Controller extends ContentController { - function init() { + public function init() { RSSFeed::linkToFeed($this->Link() . "rss", "10 Most Recently Updated Pages"); parent::init(); } - function rss() { + public function rss() { $rss = new RSSFeed($this->LatestUpdates(), $this->Link(), "10 Most Recently Updated Pages", "Shows a list of the 10 most recently updated pages.", "Title", "Content", "Author"); $rss->outputToBrowser(); } - function LatestUpdates() { + public function LatestUpdates() { // 10 is the number of pages return DataObject::get("Page", "", "LastEdited DESC", "", 10); } diff --git a/docs/en/reference/site-reports.md b/docs/en/reference/site-reports.md index fd660b919..60ed878a5 100644 --- a/docs/en/reference/site-reports.md +++ b/docs/en/reference/site-reports.md @@ -30,13 +30,13 @@ CustomSideReport.php :::php array("NestedTitle", array("2")), diff --git a/docs/en/reference/siteconfig.md b/docs/en/reference/siteconfig.md index 47df15958..44e2dd413 100644 --- a/docs/en/reference/siteconfig.md +++ b/docs/en/reference/siteconfig.md @@ -39,7 +39,7 @@ Create a mysite/code/CustomSiteConfig.php file. class CustomSiteConfig extends DataExtension { - function extraStatics() { + public function extraStatics() { return array( 'db' => array( 'FooterContent' => 'HTMLText' diff --git a/docs/en/reference/sitetree.md b/docs/en/reference/sitetree.md index 46e01a397..a1eff2318 100644 --- a/docs/en/reference/sitetree.md +++ b/docs/en/reference/sitetree.md @@ -134,7 +134,7 @@ it is a good starting point, for choosing your customisation. return false; } - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); return $fields; } @@ -187,16 +187,16 @@ Example: static $many_many = array( 'MyProducts' => 'MyProduct' ); - function stageChildren($showAll = false) { + public function stageChildren($showAll = false) { // @todo Implement $showAll return $this->MyProducts(); } - function liveChildren($showAll = false) { + public function liveChildren($showAll = false) { // @todo Implement $showAll return $this->MyProducts(); } - function numChildren() { + public function numChildren() { return $this->MyProducts()->Count(); } } } @@ -210,7 +210,7 @@ The `[api:LeftAndMain]` tree supports multiple parents. We overload CMSTreeClas the class list. :::php - function CMSTreeClasses($controller) { + public function CMSTreeClasses($controller) { return parent::CMSTreeClasses($controller) . ' manyparents'; } @@ -219,10 +219,10 @@ Don't forget to define a new Parent() method that also references your new many- up the hierarchy! :::php - function getParent() { + public function getParent() { return $this->Parent(); } - function Parent() { + public function Parent() { $parents = $this->Parents(); if($parents) return $parents->First(); } @@ -245,7 +245,7 @@ saved into the database. This will represent our dynamic groups. ### LeftAndMain::getSiteTreeFor() Currently LeftAndMain::getSiteTreeFor() Calls LeftAndMain::getRecord($id) to get a new record. We need to instead -create a new function getTreeRecord($id) which will be able to create BlogMonthTreeNode objects as well as look up +create a new public function getTreeRecord($id) which will be able to create BlogMonthTreeNode objects as well as look up SiteTree records from the database. The IDs don't **need** be numeric; so we can set the system to allow for 2 $id formats. diff --git a/docs/en/reference/sqlquery.md b/docs/en/reference/sqlquery.md index 5b562e9a7..2527454e6 100644 --- a/docs/en/reference/sqlquery.md +++ b/docs/en/reference/sqlquery.md @@ -79,7 +79,7 @@ Raw SQL is handy for performance-optimized calls. :::php class Team extends DataObject { - function getPlayerCount() { + public function getPlayerCount() { $sqlQuery = new SQLQuery( "COUNT(Player.ID)", "Team LEFT JOIN Player ON Team.ID = Player.TeamID" diff --git a/docs/en/reference/staticpublisher.md b/docs/en/reference/staticpublisher.md index ec61cb6b1..5ef41088e 100644 --- a/docs/en/reference/staticpublisher.md +++ b/docs/en/reference/staticpublisher.md @@ -31,7 +31,7 @@ publisher to generate folders and HTML-files. * Return a list of all the pages to cache */ - function allPagesToCache() { + public function allPagesToCache() { // Get each page type to define its sub-urls $urls = array(); @@ -52,7 +52,7 @@ publisher to generate folders and HTML-files. * Get a list of URLs to cache related to this page */ - function subPagesToCache() { + public function subPagesToCache() { $urls = array(); // add current page @@ -66,7 +66,7 @@ publisher to generate folders and HTML-files. return $urls; } - function pagesAffectedByChanges() { + public function pagesAffectedByChanges() { $urls = $this->subPagesToCache(); if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache()); return $urls; @@ -80,7 +80,7 @@ cache then you unset these URLs from the returned array. If you do not want to c you can also add an exclusion :::php - function allPagesToCache() { + public function allPagesToCache() { $urls = array(); $pages = DataObject::get("SiteTree"); @@ -100,7 +100,7 @@ you can also add an exclusion You can also pass the filtering to the original DataObject::get("SiteTree"); :::php - function allPagesToCache() { + public function allPagesToCache() { $urls = array(); $pages = DataObject::get("SiteTree", "ClassName != 'UserDefinedForm'"); ... @@ -150,7 +150,7 @@ Instead of the above code snippet for Page.php, use the following code: // ... - function allPagesToCache() { + public function allPagesToCache() { // Get each page type to define its sub-urls $urls = array(); @@ -164,13 +164,13 @@ Instead of the above code snippet for Page.php, use the following code: return $urls; } - function subPagesToCache() { + public function subPagesToCache() { $urls = array(); $urls[] = $this->AbsoluteLink(); return $urls; } - function pagesAffectedByChanges() { + public function pagesAffectedByChanges() { $urls = $this->subPagesToCache(); if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache()); return $urls; diff --git a/docs/en/reference/tablelistfield.md b/docs/en/reference/tablelistfield.md index 625901748..d9fd64b1e 100644 --- a/docs/en/reference/tablelistfield.md +++ b/docs/en/reference/tablelistfield.md @@ -13,7 +13,7 @@ directly as a button on each record, as well as filtering, and sorting. It also allowing export of data as a CSV. :::php - function getReportField() { + public function getReportField() { $resultSet = new DataObjectSet(); $filter = `; $sort = "Member.ID ASC"; @@ -104,7 +104,7 @@ For more information on each of the features used in the example, you can read b // Product.php Example class Product extends DataObject { $has_one = array('Buyer'=>'Member'); - function getPriceWithShipping() { + public function getPriceWithShipping() { return $this->Price + $this->Shipping; } } @@ -263,7 +263,7 @@ Please subclass `[api:TableListField]` to implement custom sorting, following th :::php class CustomTableListField extends TableListField { // referenced through "dateAverage" - function colFunction_dateAverage($values) { + public function colFunction_dateAverage($values) { // custom date summaries } } diff --git a/docs/en/reference/templates.md b/docs/en/reference/templates.md index 22bae4ddc..a908d2a85 100644 --- a/docs/en/reference/templates.md +++ b/docs/en/reference/templates.md @@ -326,7 +326,7 @@ There are two ways you can extend the template variables you have available. You **mysite/code/Page.php** ... - function MyCustomValue() { + public function MyCustomValue() { return "Hi, this is my site"; } @@ -344,7 +344,7 @@ Your function could return a single value as above or it could be a subclass of :::php .. - function MyCustomValues() { + public function MyCustomValues() { return new ArrayData(array("Hi" => "Kia Ora", "Name" => "John Smith")); } @@ -376,7 +376,7 @@ For example, this Controller method :::php private $counter = 0; - function Counter() { + public function Counter() { $this->counter += 1; return $this->counter; } @@ -451,11 +451,11 @@ default if it exists and there is no action in the url parameters. :::php class MyPage_Controller extends Page_Controller { - function init(){ + public function init(){ parent::init(); } - function index() { + public function index() { if(Director::is_ajax()) { return $this->renderWith("myAjaxTemplate"); } diff --git a/docs/en/reference/typography.md b/docs/en/reference/typography.md index a1795096a..dc2f42863 100644 --- a/docs/en/reference/typography.md +++ b/docs/en/reference/typography.md @@ -93,7 +93,7 @@ Sometimes, it's not enough to add a class, you also want to remove the typograph This example sets another CSS class typographybis: :::php - function getCMSFields() { + public function getCMSFields() { ... $htmleditor = new HTMLEditorField("ContentBis", "Content Bis"); $htmleditor->setCSSClass('typographybis'); diff --git a/docs/en/reference/versioned.md b/docs/en/reference/versioned.md index 5e269be21..82c03d5fa 100644 --- a/docs/en/reference/versioned.md +++ b/docs/en/reference/versioned.md @@ -12,7 +12,7 @@ whenever a blog entry has been published. :::php class Page extends SiteTree { // ... - function publish($fromStage, $toStage, $createNewVersion = false) { + public function publish($fromStage, $toStage, $createNewVersion = false) { mail("sam@silverstripe.com", "Blog published", "The blog has been published"); return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion); } @@ -24,7 +24,7 @@ whenever a blog entry has been published. :::php class Page extends SiteTree { // ... - function onAfterPublish() { + public function onAfterPublish() { mail("sam@silverstripe.com", "Blog published", "The blog has been published"); parent::onAfterPublish(); } diff --git a/docs/en/topics/commandline.md b/docs/en/topics/commandline.md index ba1e648b1..505ad2c2d 100644 --- a/docs/en/topics/commandline.md +++ b/docs/en/topics/commandline.md @@ -98,7 +98,7 @@ This code provides a good template: :::php class MyProcess extends Controller { - function index() { + public function index() { set_time_limit(0); while(memory_get_usage() < 32*1024*1024) { if($this->somethingToDo()) { diff --git a/docs/en/topics/controller.md b/docs/en/topics/controller.md index 52c9e5d70..94bcae9a6 100644 --- a/docs/en/topics/controller.md +++ b/docs/en/topics/controller.md @@ -12,7 +12,7 @@ your SilverStripe site. `" or "set`Status - function getStatus() { + public function getStatus() { // check if the Player is actually... born already! return (!$this->obj("Birthday")->InPast()) ? "Unborn" : $this->Status; } @@ -353,13 +353,13 @@ Here we combined a Player's first name and surname, accessible through $myPlayer :::php class Player extends DataObject { - function getTitle() { + public function getTitle() { return "{$this->FirstName} {$this->Surname}"; } // access through $myPlayer->Title = "John Doe"; // just saves data on the object, please use $myPlayer->write() to save the database-row - function setTitle($title) { + public function setTitle($title) { list($firstName, $surName) = explode(' ', $title); $this->FirstName = $firstName; $this->Surname = $surName; @@ -409,7 +409,7 @@ but using the *obj()*-method or accessing through a template will cast the value // $myPlayer->MembershipFee() returns a float (e.g. 123.45) // $myPlayer->obj('MembershipFee') returns a object of type Currency // In a template: <% control MyPlayer %>MembershipFee.Nice<% end_control %> returns a casted string (e.g. "$123.45") - function getMembershipFee() { + public function getMembershipFee() { return $this->Team()->BaseFee * $this->MembershipYears; } } @@ -542,7 +542,7 @@ Inside sapphire it doesn't matter if you're editing a *has_many*- or a *many_man * @param DataObjectSet */ - function addCategories($additionalCategories) { + public function addCategories($additionalCategories) { $existingCategories = $this->Categories(); // method 1: Add many by iteration @@ -569,7 +569,7 @@ the described relations). ); // can be accessed by $myTeam->ActivePlayers() - function ActivePlayers() { + public function ActivePlayers() { return $this->Players("Status='Active'"); } } @@ -655,7 +655,7 @@ Example: Disallow creation of new players if the currently logged-in player is n "Teams"=>"Team" ); - function onBeforeWrite() { + public function onBeforeWrite() { // check on first write action, aka "database row creation" (ID-property is not set) if(!$this->ID) { $currentPlayer = Member::currentUser(); @@ -695,7 +695,7 @@ It checks if a member is logged in who belongs to a group containing the permiss "Teams"=>"Team" ); - function onBeforeDelete() { + public function onBeforeDelete() { if(!Permission::check('PLAYER_DELETE')) { Security::permissionFailure($this); exit(); diff --git a/docs/en/topics/form-validation.md b/docs/en/topics/form-validation.md index f68a61ee2..ce1abad68 100644 --- a/docs/en/topics/form-validation.md +++ b/docs/en/topics/form-validation.md @@ -12,7 +12,7 @@ class. :::php - function Form() { + public function Form() { $form = new Form($this, 'Form', new FieldList( new TextField('MyRequiredField'), diff --git a/docs/en/topics/forms.md b/docs/en/topics/forms.md index 56cda31b5..2d89737a6 100644 --- a/docs/en/topics/forms.md +++ b/docs/en/topics/forms.md @@ -21,7 +21,7 @@ have problems with form action handler not working, check that these values are Example: :::php - function MyCustomForm() { + public function MyCustomForm() { $fields = new FieldList( new EmailField("Email"), new EncryptField("Password") @@ -43,7 +43,7 @@ $name must be passed - their values depend on where the form is instantiated. :::php class MyForm extends Form { - function __construct($controller, $name) { + public function __construct($controller, $name) { $fields = new FieldList( new EmailField("Email"), new EncryptedField("Password") @@ -167,7 +167,7 @@ First of all, you need to create your form on it's own class, that way you can d :::php class MyForm extends Form { - function __construct($controller, $name) { + public function __construct($controller, $name) { $fields = new FieldList( new TextField('FirstName', 'First name'), new EmailField('Email', 'Email address') @@ -180,14 +180,14 @@ First of all, you need to create your form on it's own class, that way you can d parent::__construct($controller, $name, $fields, $actions); } - function forTemplate() { + public function forTemplate() { return $this->renderWith(array( $this->class, 'Form' )); } - function submit($data, $form) { + public function submit($data, $form) { // do stuff here } @@ -269,7 +269,7 @@ If you want to remove certain fields from your subclass: :::php class MyCustomForm extends MyForm { - function __construct($controller, $name) { + public function __construct($controller, $name) { parent::__construct($controller, $name); // remove a normal field diff --git a/docs/en/topics/grid-field.md b/docs/en/topics/grid-field.md index 3822fbfd3..790348c4a 100644 --- a/docs/en/topics/grid-field.md +++ b/docs/en/topics/grid-field.md @@ -12,7 +12,7 @@ This example might come from a Controller designed to manage the members of a gr /** * Form to display all members in a group */ - function MemberForm() { + public function MemberForm() { $field = new GridField("Members", "Members of this group", $this->group->Members()); return new Form("MemberForm", $this, new FieldSet($field), new FieldSet()); } @@ -134,7 +134,7 @@ For example, this components will add a footer row to the grid field, thanking t :::php class ThankYouForUsingSilverStripe implements GridField_HTMLProvider { - function getHTMLFragments($gridField) { + public function getHTMLFragments($gridField) { $colSpan = $gridField->getColumnCount(); return array( 'footer' => 'Thank you for using SilverStripe!', @@ -211,13 +211,13 @@ Here is an example in full. The actual implementation of the view and edit form * - /field//item//edit */ class GridFieldPopupForms implements GridField_URLHandler { - function getURLHandlers($gridField) { + public function getURLHandlers($gridField) { return array( 'item/$ID' => 'handleItem', ); } - function handleItem($gridField, $request) { + public function handleItem($gridField, $request) { $record = $gridField->getList()->byId($request->param("ID")); return new GridFieldPopupForm_ItemRequest($gridField, $this, $record); } @@ -228,18 +228,18 @@ Here is an example in full. The actual implementation of the view and edit form protected $component; protected $record; - function __construct($gridField, $component, $record) { + public function __construct($gridField, $component, $record) { $this->gridField = $gridField; $this->component = $gridField; $this->record = $record; parent::__construct(); } - function index() { + public function index() { echo "view form for record #" . $record->ID; } - function edit() { + public function edit() { echo "edit form for record #" . $record->ID; } } diff --git a/docs/en/topics/i18n.md b/docs/en/topics/i18n.md index 86505b47b..bdda0e19b 100644 --- a/docs/en/topics/i18n.md +++ b/docs/en/topics/i18n.md @@ -138,7 +138,7 @@ below), which is the starting point for translations. Here is the function prototype of this translator function :::php - function _t(string $entity [, string $string [, int $priority [, string $context]]]) { + public function _t(string $entity [, string $string [, int $priority [, string $context]]]) { **$entity:** The first parameter is the identifier, and is composed by a namespace and an entity name, with a dot separating them. diff --git a/docs/en/topics/module-development.md b/docs/en/topics/module-development.md index b3dcf2e33..e528d6510 100644 --- a/docs/en/topics/module-development.md +++ b/docs/en/topics/module-development.md @@ -24,7 +24,7 @@ init() function on your module controller classes: :::php class Forum_Controller extends Page_Controller { - function init() { + public function init() { if(Director::fileExists(project() . "/css/forum.css")) { Requirements::css(project() . "/css/forum.css"); }else{ diff --git a/docs/en/topics/page-types.md b/docs/en/topics/page-types.md index 91a93329d..58065a837 100644 --- a/docs/en/topics/page-types.md +++ b/docs/en/topics/page-types.md @@ -91,7 +91,7 @@ want the MenuTitle field to show on your page, which is inherited from `[api:Sit :::php class StaffPage extends Page { - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeFieldFromTab('Root.Content', 'MenuTitle'); return $fields; @@ -111,7 +111,7 @@ required on a certain page-type. :::php class MyForm extends Form { - function __construct($controller, $name) { + public function __construct($controller, $name) { // add a default FieldList of form fields $member = singleton('Member'); diff --git a/docs/en/topics/security.md b/docs/en/topics/security.md index f162f6e53..75c84cd55 100644 --- a/docs/en/topics/security.md +++ b/docs/en/topics/security.md @@ -52,7 +52,7 @@ Example: :::php class MyForm extends Form { - function save($RAW_data, $form) { + public function save($RAW_data, $form) { $SQL_data = Convert::raw2sql($RAW_data); // works recursively on an array $objs = DataObject::get('Player', "Name = '{$SQL_data[name]}'"); // ... @@ -67,7 +67,7 @@ Example: :::php class MyController extends Controller { - function myurlaction($RAW_urlParams) { + public function myurlaction($RAW_urlParams) { $SQL_urlParams = Convert::raw2sql($RAW_urlParams); // works recursively on an array $objs = DataObject::get('Player', "Name = '{$SQL_data[OtherID]}'"); // ... @@ -84,12 +84,12 @@ This means if you've got a chain of functions passing data through, escaping sho * @param array $RAW_data All names in an indexed array (not SQL-safe) */ - function saveAllNames($RAW_data) { + public function saveAllNames($RAW_data) { // $SQL_data = Convert::raw2sql($RAW_data); // premature escaping foreach($RAW_data as $item) $this->saveName($item); } - function saveName($RAW_name) { + public function saveName($RAW_name) { $SQL_name = Convert::raw2sql($RAW_name); DB::query("UPDATE Player SET Name = '{$SQL_name}'"); } @@ -178,7 +178,7 @@ PHP: 'TitleWithHTMLSuffix' => 'HTMLText' // optional, as HTMLText is the default casting ); - function TitleWithHTMLSuffix($suffix) { + public function TitleWithHTMLSuffix($suffix) { // $this->Title is not casted in PHP return $this->Title . '(' . $suffix. ')'; } @@ -210,7 +210,7 @@ PHP: :::php class MyController extends Controller { - function search($request) { + public function search($request) { $htmlTitle = '

Your results for:' . Convert::raw2xml($request->getVar('Query')) . '

'; return $this->customise(array( 'Query' => DBField::create('Text', $request->getVar('Query')), @@ -239,7 +239,7 @@ PHP: :::php class MyController extends Controller { - function search($request) { + public function search($request) { $rssRelativeLink = "/rss?Query=" . urlencode($_REQUEST['query']) . "&sortOrder=asc"; $rssLink = Controller::join_links($this->Link(), $rssRelativeLink); return $this->customise(array( @@ -294,7 +294,7 @@ passed, such as *mysite.com/home/add/dfsdfdsfd*, then it returns 0. Below is an example with different ways you would use this casting technique: :::php - function CaseStudies() { + public function CaseStudies() { // cast an ID from URL parameters e.g. (mysite.com/home/action/ID) $anotherID = (int)Director::urlParam['ID']; diff --git a/docs/en/topics/testing/create-functional-test.md b/docs/en/topics/testing/create-functional-test.md index 4d024a0d1..14bcdd1c5 100644 --- a/docs/en/topics/testing/create-functional-test.md +++ b/docs/en/topics/testing/create-functional-test.md @@ -17,7 +17,7 @@ URLs. Here is an example from the subsites module: /** * Return a session that has a user logged in as an administrator */ - function adminLoggedInSession() { + public function adminLoggedInSession() { return new Session(array( 'loggedInAs' => $this->idFromFixture('Member', 'admin') )); @@ -26,7 +26,7 @@ URLs. Here is an example from the subsites module: /** * Test generation of the view */ - function testBasicView() { + public function testBasicView() { // Open the admin area logged in as admin $response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession()); diff --git a/docs/en/topics/testing/create-sapphire-test.md b/docs/en/topics/testing/create-sapphire-test.md index 47d9ceeb0..1ccb64884 100644 --- a/docs/en/topics/testing/create-sapphire-test.md +++ b/docs/en/topics/testing/create-sapphire-test.md @@ -24,7 +24,7 @@ provides us the basics of creating unit tests. * - Generates from Title by default, unless URLSegment is explicitly set * - Resolves duplicates by appending a number */ - function testURLGeneration() { + public function testURLGeneration() { $expectedURLs = array( 'home' => 'home', 'staff' => 'my-staff', diff --git a/docs/en/topics/widgets.md b/docs/en/topics/widgets.md index 2bed3d007..66a4764d2 100644 --- a/docs/en/topics/widgets.md +++ b/docs/en/topics/widgets.md @@ -51,7 +51,7 @@ Widget Form to manage the widgets. An example of this is below "Sidebar" => "WidgetArea", ); - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar")); return $fields; @@ -113,7 +113,7 @@ An example widget is below: static $cmsTitle = "Flickr Photos"; static $description = "Shows flickr photos."; - function Photos() { + public function Photos() { Requirements::javascript("sapphire/thirdparty/prototype/prototype.js"); Requirements::javascript("sapphire/thirdparty/scriptaculous/effects.js"); Requirements::javascript("mashups/javascript/lightbox.js"); @@ -138,7 +138,7 @@ An example widget is below: return $output; } - function getCMSFields() { + public function getCMSFields() { return new FieldList( new TextField("User", "User"), new TextField("PhotoSet", "Photo Set"), @@ -170,7 +170,7 @@ This example creates an RSSWidget with the SilverStripe blog feed. :::php RssUrl = "http://feeds.feedburner.com/silverstripe-blog"; return $widget->renderWith("WidgetHolder"); @@ -205,7 +205,7 @@ variable. For example, to set your widgets title to 'Hello World!', you could us **widgets_yourWidget/YourWidgetWidget.php** :::php - function Title() { + public function Title() { return "Hello World!"; } @@ -217,7 +217,7 @@ widget called WidgetTitle, that you wish to use as your title. If nothing is set This is similar to the RSS Widget in the blog module. :::php - function Title() { + public function Title() { return $this->WidgetTitle ? $this->WidgetTitle : self::$title; } @@ -242,7 +242,7 @@ sure that your controller follows the usual naming conventions, and it will be a } class MyWidget_Controller extends Widget_Controller { - function MyFormName() { + public function MyFormName() { return new Form( $this, 'MyFormName', @@ -255,7 +255,7 @@ sure that your controller follows the usual naming conventions, and it will be a ); } - function doAction($data, $form) { + public function doAction($data, $form) { // $this->widget points to the widget } } @@ -295,7 +295,7 @@ Page class). One way to fix this is to comment out line 30 in BlogHolder.php and // "SideBar" => "WidgetArea", COMMENT OUT 'Newsletter' => 'NewsletterType' ....... - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeFieldFromTab("Root.Content","Content"); // $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("SideBar")); COMMENT OUT diff --git a/docs/en/tutorials/2-extending-a-basic-site.md b/docs/en/tutorials/2-extending-a-basic-site.md index 8b3672f88..e4ba319ed 100644 --- a/docs/en/tutorials/2-extending-a-basic-site.md +++ b/docs/en/tutorials/2-extending-a-basic-site.md @@ -171,7 +171,7 @@ method to the *ArticlePage* class. class ArticlePage extends Page { // ... - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Content', new DateField('Date'), 'Content'); @@ -229,7 +229,7 @@ To make the date field a bit more user friendly, you can add a dropdown calendar // ..... - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Content', $dateField = new DateField('Date','Article Date (for example: 20/12/2010)'), 'Content'); @@ -472,7 +472,7 @@ control. We can get the data for the news articles by implementing our own funct :::php ... - function LatestNews($num=5) { + public function LatestNews($num=5) { $news = DataObject::get_one("ArticleHolder"); return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false; } @@ -518,7 +518,7 @@ providing an `[api:RSSFeed]` class to do all the hard work for you. Create the f *ArticleHolder_Controller*: :::php - function rss() { + public function rss() { $rss = new RSSFeed($this->Children(), $this->Link(), "The coolest news around"); $rss->outputToBrowser(); } @@ -538,7 +538,7 @@ Now all we need is to let the user know that our RSS feed exists. The `[api:RSSF called when the page is requested. Add this function to *ArticleHolder_Controller*: :::php - function init() { + public function init() { RSSFeed::linkToFeed($this->Link() . "rss"); parent::init(); } @@ -591,7 +591,7 @@ insert an image in the *$Content* field). 'Photo' => 'Image' ); - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Content.Images", new ImageField('Photo')); diff --git a/docs/en/tutorials/3-forms.md b/docs/en/tutorials/3-forms.md index e53718e2f..5aa8a3ab4 100644 --- a/docs/en/tutorials/3-forms.md +++ b/docs/en/tutorials/3-forms.md @@ -31,7 +31,7 @@ the form in a method on *HomePage_Controller*. class HomePage_Controller extends Page_Controller { // ... - function BrowserPollForm() { + public function BrowserPollForm() { // Create fields $fields = new FieldList( new TextField('Name'), @@ -203,7 +203,7 @@ that the *BrowserPollSubmission* table is created. Now we just need to define 'd :::php class HomePage_Controller extends Page_Controller { // ... - function doBrowserPoll($data, $form) { + public function doBrowserPoll($data, $form) { $submission = new BrowserPollSubmission(); $form->saveInto($submission); $submission->write(); @@ -236,7 +236,7 @@ Change the end of the 'BrowserPollForm' function so it looks like this: ** mysite/code/HomePage.php ** :::php - function BrowserPollForm() { + public function BrowserPollForm() { ... // Create validator @@ -271,7 +271,7 @@ First modify the 'doBrowserPoll' to set the session variable 'BrowserPollVoted' HomePage_Controller extends Page_Controller { ... - function doBrowserPoll($data, $form) { + public function doBrowserPoll($data, $form) { $submission = new BrowserPollSubmission(); $form->saveInto($submission); $submission->write(); @@ -289,7 +289,7 @@ Then we simply need to check if the session variable has been set in 'BrowserPol it is. :::php - function BrowserPollForm() { + public function BrowserPollForm() { if(Session::get('BrowserPollVoted')) { return false; } @@ -320,7 +320,7 @@ then create our graph using a page control in the template. Create the function ** mysite/code/HomePage.php ** :::php - function BrowserPollResults() { + public function BrowserPollResults() { $submissions = DataObject::get('BrowserPollSubmission'); $total = $submissions->Count(); diff --git a/docs/en/tutorials/4-site-search.md b/docs/en/tutorials/4-site-search.md index 91cc05eea..3460c0e04 100644 --- a/docs/en/tutorials/4-site-search.md +++ b/docs/en/tutorials/4-site-search.md @@ -117,7 +117,7 @@ Next we need to create the *results* function. class Page_Controller extends ContentController { ... - function results($data, $form){ + public function results($data, $form){ $data = array( 'Results' => $form->getResults(), 'Query' => $form->getSearchQuery(), diff --git a/docs/en/tutorials/5-dataobject-relationship-management.md b/docs/en/tutorials/5-dataobject-relationship-management.md index 4d054bfc9..f7920843c 100644 --- a/docs/en/tutorials/5-dataobject-relationship-management.md +++ b/docs/en/tutorials/5-dataobject-relationship-management.md @@ -82,7 +82,7 @@ The first step is to create the student and project objects. 'Nationality' => 'Text' ); - function getCMSFields_forPopup() { + public function getCMSFields_forPopup() { $fields = new FieldList(); $fields->push( new TextField( 'FirstName', 'First Name' ) ); @@ -119,7 +119,7 @@ The second step is to add the table in the method *getCMSFields* which will allo ... - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $tablefield = new HasOneComplexTableField( @@ -206,7 +206,7 @@ To use your *HasOneComplexTableField* table for a **1-to-1** relation, make this ... - function getCMSFields() { + public function getCMSFields() { ... @@ -256,7 +256,7 @@ The first step is to create the mentor object and set the relation with the *Stu 'Students' => 'Student' ); - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab( 'Root.Content', new TextField( 'FirstName' ) ); @@ -295,7 +295,7 @@ The second step is to add the table in the method *getCMSFields* which will allo ... - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); ... @@ -380,7 +380,7 @@ The first step is to create the module object and set the relation with the *Pro 'Projects' => 'Project' ); - function getCMSFields_forPopup() { + public function getCMSFields_forPopup() { $fields = new FieldList(); $fields->push( new TextField( 'Name' ) ); return $fields; @@ -413,7 +413,7 @@ relation. ... - function getCMSFields() { + public function getCMSFields() { $fields = parent::getCMSFields(); ... @@ -638,7 +638,7 @@ from templates either within a control block or dot notation. *tutorial/code/Student.php, tutorial/code/Mentor.php* :::php - function PersonalInfo() { + public function PersonalInfo() { $template = 'GSOCPerson'; return $this->renderWith( $template ); } @@ -702,7 +702,7 @@ it *MyProject* for instance. ... - function MyProject() { + public function MyProject() { return DataObject::get( 'Project', "`MyStudentID` = '{$this->ID}'" ); }