mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-29 20:59:23 +02:00
API CHANGE LeftAndMain.php: Removed $extra_menu_items, $replaced_menu_items, $removed_menu_items (all handled in $menu_items now)
API CHANGE Deprecated menu manipulation through Object::addStaticVars(), changed internal representation of menu_item array to always use associative arrays ENHANCEMENT Added LeftAndMain::add_menu_item(), LeftAndMain::replace_menu_item(), LeftAndMain::remove_menu_item() ENHANCEMENT Moved default menu items from LeftAndMain->MainMenu() to cms/_config.php ENHANCEMENT Added ReportAdmin::has_reports() ENHANCEMENT Object::addStaticVars() can replace the whole array optionally ENHANCEMENT Object::stat() optionally returns uncached results ENHANCEMENT Moved Object::useCustomClass('SSDateTime') from Object.php to sapphire/_config.php ENHANCEMENT Misc documentation and formatting in LeftAndMain and Object classes git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@52171 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
a42b76bc73
commit
d713777d73
@ -17,6 +17,13 @@
|
|||||||
* @subpackage core
|
* @subpackage core
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP 5.2 has a namespace conflict with our datetime class,
|
||||||
|
* for legacy support, we use this overload method.
|
||||||
|
* // ENFORCE STRONG_CREATE
|
||||||
|
*/
|
||||||
|
Object::useCustomClass('Datetime','SSDatetime',true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add pear parser to include path
|
* Add pear parser to include path
|
||||||
*/
|
*/
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @package sapphire
|
|
||||||
* @subpackage core
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base object that all others should inherit from.
|
* Base object that all others should inherit from.
|
||||||
* This object provides a number of helper methods that patch over PHP's deficiencies.
|
* This object provides a number of helper methods that patch over PHP's deficiencies.
|
||||||
|
*
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage core
|
* @subpackage core
|
||||||
*/
|
*/
|
||||||
class Object {
|
class Object {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This DataObjects extensions, eg Versioned.
|
* This DataObjects extensions, eg Versioned.
|
||||||
* @var array
|
* @var array
|
||||||
@ -44,6 +40,23 @@ class Object {
|
|||||||
private static $strong_classes = array();
|
private static $strong_classes = array();
|
||||||
|
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$this->class = get_class($this);
|
||||||
|
|
||||||
|
// Set up the extensions
|
||||||
|
if($extensions = $this->stat('extensions')) {
|
||||||
|
foreach($extensions as $extension) {
|
||||||
|
$instance = eval("return new $extension;");
|
||||||
|
$instance->setOwner($this);
|
||||||
|
$this->extension_instances[$instance->class] = $instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset(Object::$classConstructed[$this->class])) {
|
||||||
|
$this->defineMethods();
|
||||||
|
Object::$classConstructed[$this->class] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function allows you to overload class creation methods, so certain classes are
|
* This function allows you to overload class creation methods, so certain classes are
|
||||||
@ -120,25 +133,6 @@ class Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
$this->class = get_class($this);
|
|
||||||
|
|
||||||
// Set up the extensions
|
|
||||||
if($extensions = $this->stat('extensions')) {
|
|
||||||
foreach($extensions as $extension) {
|
|
||||||
$instance = eval("return new $extension;");
|
|
||||||
$instance->setOwner($this);
|
|
||||||
$this->extension_instances[$instance->class] = $instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset(Object::$classConstructed[$this->class])) {
|
|
||||||
$this->defineMethods();
|
|
||||||
Object::$classConstructed[$this->class] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this object "exists", i.e., has a sensible value.
|
* Returns true if this object "exists", i.e., has a sensible value.
|
||||||
* Overload this in subclasses.
|
* Overload this in subclasses.
|
||||||
@ -285,14 +279,20 @@ class Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method lets us extend a built-in class by adding static variables to it
|
* This method lets us extend a built-in class by adding pseudo-static variables to it.
|
||||||
|
*
|
||||||
|
* @param string $class Classname
|
||||||
|
* @param array $statics Statics to add, with keys being static property names on the class
|
||||||
|
* @param boolean $replace Replace the whole variable instead of merging arrays
|
||||||
*/
|
*/
|
||||||
static function addStaticVars($class, $statics) {
|
static function addStaticVars($class, $statics, $replace = false) {
|
||||||
if (empty(Object::$extraStatics[$class])) {
|
if(empty(Object::$extraStatics[$class])) {
|
||||||
Object::$extraStatics[$class] = (array)$statics;
|
Object::$extraStatics[$class] = (array)$statics;
|
||||||
|
} elseif($replace) {
|
||||||
|
Object::$extraStatics[$class] = $statics;
|
||||||
} else {
|
} else {
|
||||||
$ar1 = (array)Object::$extraStatics[$class]; // First Array To Merge
|
$ar1 = (array)Object::$extraStatics[$class];
|
||||||
$ar2 = (array)$statics; // Second Array To Merge
|
$ar2 = (array)$statics;
|
||||||
Object::$extraStatics[$class] = array_merge_recursive($ar1, $ar2);
|
Object::$extraStatics[$class] = array_merge_recursive($ar1, $ar2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,6 +300,7 @@ class Object {
|
|||||||
function parentClass() {
|
function parentClass() {
|
||||||
return get_parent_class($this);
|
return get_parent_class($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_a($class) {
|
function is_a($class) {
|
||||||
return is_a($this, $class);
|
return is_a($this, $class);
|
||||||
}
|
}
|
||||||
@ -310,6 +311,7 @@ class Object {
|
|||||||
function set_uninherited($name, $val) {
|
function set_uninherited($name, $val) {
|
||||||
return Object::$uninherited_statics[$this->class][$name] = $val;
|
return Object::$uninherited_statics[$this->class][$name] = $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an uninherited static variable
|
* Get an uninherited static variable
|
||||||
*/
|
*/
|
||||||
@ -341,12 +343,16 @@ class Object {
|
|||||||
protected static $static_cached = array();
|
protected static $static_cached = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a static variable
|
* Get a static variable.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param boolean $uncached
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function stat($name) {
|
function stat($name, $uncached = false) {
|
||||||
if(!$this->class) $this->class = get_class($this);
|
if(!$this->class) $this->class = get_class($this);
|
||||||
|
|
||||||
if(!isset(Object::$static_cached[$this->class][$name])) {
|
if(!isset(Object::$static_cached[$this->class][$name]) || $uncached) {
|
||||||
$classes = ClassInfo::ancestry($this->class);
|
$classes = ClassInfo::ancestry($this->class);
|
||||||
foreach($classes as $class) {
|
foreach($classes as $class) {
|
||||||
if(isset(Object::$extraStatics[$class][$name])) {
|
if(isset(Object::$extraStatics[$class][$name])) {
|
||||||
@ -436,7 +442,6 @@ class Object {
|
|||||||
// CACHE METHODS (added by simon_w (simon -at- simon -dot- geek -dot- nz))
|
// CACHE METHODS (added by simon_w (simon -at- simon -dot- geek -dot- nz))
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a current cache from the filesystem, if it can.
|
* Loads a current cache from the filesystem, if it can.
|
||||||
*
|
*
|
||||||
@ -549,10 +554,4 @@ class Object {
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
/**
|
|
||||||
* PHP 5.2 has a namespace conflict with our datetime class,
|
|
||||||
* for legacy support, we use this overload method.
|
|
||||||
* // ENFORCE STRONG_CREATE
|
|
||||||
*/
|
|
||||||
Object::useCustomClass('Datetime','SSDatetime',true);
|
|
Loading…
Reference in New Issue
Block a user