Permalink
Browse files

Use Symphony::ExtensionManager, change Lang to use listInstalledHandles

  • Loading branch information...
brendo committed Jan 7, 2011
1 parent a35e0d4 commit 4b166e79b0c28b993c09cea1f53f265deaac7a0a
@@ -196,7 +196,9 @@ public function initialiseCookie(){
* a Symphony Error page will be thrown
*/
public function initialiseExtensionManager(){
- self::$ExtensionManager = new ExtensionManager($this);
+ if(!(self::$ExtensionManager instanceof ExtensionManager)){
+ self::$ExtensionManager = new ExtensionManager($this);
+ }
if(!(self::$ExtensionManager instanceof ExtensionManager)){
GenericExceptionHandler::$enabled = true;
@@ -55,8 +55,7 @@ public function __getClassName($handle){
public function __getClassPath($handle){
if(is_file(DATASOURCES . "/data.$handle.php")) return DATASOURCES;
else{
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){
@@ -124,8 +123,7 @@ public function listAll(){
}
}
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){
@@ -62,8 +62,7 @@ public function __find($name){
if(is_file(EMAILGATEWAYS . "/email.$name.php")) return EMAILGATEWAYS;
else{
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){
@@ -139,8 +138,7 @@ public function listAll(){
}
}
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){
@@ -52,8 +52,7 @@ public function __getClassPath($handle){
if(is_file(EVENTS . "/event.$handle.php")) return EVENTS;
else{
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){
@@ -117,8 +116,7 @@ public function listAll(){
}
}
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){
@@ -58,7 +58,6 @@
*/
public function __construct(&$parent=NULL){
parent::__construct($parent);
- $this->listAll();
}
/**
@@ -106,7 +105,7 @@ public function __getDriverPath($name){
*/
public function getInstance($name){
foreach(self::$_pool as $extension){
- if(get_class($extension) ==$this->__getClassName($name)) return $extension;
+ if(get_class($extension) == $this->__getClassName($name)) return $extension;
}
return $this->create($name);
@@ -18,7 +18,7 @@
* Defaults to an empty array.
* @var array
*/
- protected static $_pool = array();
+ protected static $_pool = array();
/**
* An array of all fields whose have been created by ID
@@ -46,9 +46,9 @@ public function __getHandleFromFilename($filename){
* A field handle
* @return string
*/
- public function __getClassName($type){
- return 'field' . $type;
- }
+ public function __getClassName($type){
+ return 'field' . $type;
+ }
/**
* Finds a Field by type by searching the `TOOLKIT . /fields` folder and then
@@ -59,22 +59,21 @@ public function __getClassName($type){
* The field handle, that is, `field.{$handle}.php`
* @return string
*/
- public function __getClassPath($type){
- if(is_file(TOOLKIT . "/fields/field.{$type}.php")) return TOOLKIT . '/fields';
+ public function __getClassPath($type){
+ if(is_file(TOOLKIT . "/fields/field.{$type}.php")) return TOOLKIT . '/fields';
else{
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){
if(is_file(EXTENSIONS . "/{$e}/fields/field.{$type}.php")) return EXTENSIONS . "/{$e}/fields";
}
}
- }
+ }
- return false;
- }
+ return false;
+ }
/**
* Given a field type, return the path to it's class
@@ -84,9 +83,9 @@ public function __getClassPath($type){
* The handle of the field to load (it's type)
* @return string
*/
- public function __getDriverPath($type){
- return $this->__getClassPath($type) . "/field.{$type}.php";
- }
+ public function __getDriverPath($type){
+ return $this->__getClassPath($type) . "/field.{$type}.php";
+ }
/**
* Given an associative array of fields, insert them into the database
@@ -103,7 +102,7 @@ public function __getDriverPath($type){
public function add(Array $fields){
if(!isset($fields['sortorder'])){
- $next = Symphony::Database()->fetchVar("next", 0, 'SELECT MAX(`sortorder`) + 1 AS `next` FROM tbl_fields LIMIT 1');
+ $next = Symphony::Database()->fetchVar("next", 0, 'SELECT MAX(`sortorder`) + 1 AS `next` FROM tbl_fields LIMIT 1');
$fields['sortorder'] = ($next ? $next : '1');
}
@@ -294,7 +293,7 @@ public function fetchFieldIDFromElementName($element_name, $section_id = null){
/**
* Returns an array of all available field handles discovered in the
- * `TOOLKIT . /fields` or `EXTENSIONS . /{}/fields`.
+ * `TOOLKIT . /fields` or `EXTENSIONS . /{}/fields`.
*
* @return array
* A single dimensional array of field handles.
@@ -336,17 +335,17 @@ public function fetchTypes(){
public function &create($type){
if(!isset(self::$_pool[$type])){
- $classname = $this->__getClassName($type);
- $path = $this->__getDriverPath($type);
+ $classname = $this->__getClassName($type);
+ $path = $this->__getDriverPath($type);
- if(!file_exists($path)){
- throw new Exception(
+ if(!file_exists($path)){
+ throw new Exception(
__(
'Could not find Field <code>%1$s</code> at <code>%2$s</code>. If the Field was provided by an Extension, ensure that it is installed, and enabled.',
array($type, $path)
)
);
- }
+ }
if(!class_exists($classname)){
require_once($path);
@@ -109,7 +109,7 @@ public function __construct(&$parent){
$this->DatasourceManager = new DatasourceManager($this->_Parent);
$this->EventManager = new EventManager($this->_Parent);
- $this->ExtensionManager = new ExtensionManager($this->_Parent);
+ $this->ExtensionManager = Symphony::ExtensionManager();
}
/**
@@ -45,7 +45,7 @@ function _t($string) {
/**
* An associative array mapping English strings and their translations
- * @var array
+ * @var array
*/
private $_strings;
@@ -155,7 +155,7 @@ public function remove($string) {
/**
* Context information of all available languages
- * @var array
+ * @var array
*/
private static $_languages;
@@ -167,13 +167,13 @@ public function remove($string) {
/**
* Array of transliterations
- * @var array
+ * @var array
*/
private static $_transliterations;
/**
* Array of months and weekday for localized date output
- * @var array
+ * @var array
*/
private static $_dates;
@@ -227,7 +227,7 @@ public static function set($lang, $enabled=true) {
/**
* Get current language
- *
+ *
* @return string
*/
public static function get() {
@@ -241,7 +241,7 @@ public static function get() {
*
* Note: Beginning with Symphony 2.2 translations bundled with extensions will only be loaded
* when the core dictionary of the specific language is available.
- *
+ *
* @param boolean $enabled
*/
public static function activate($enabled=true) {
@@ -260,19 +260,19 @@ public static function activate($enabled=true) {
// Load extension translations
if(class_exists('Symphony')) {
+
// Fetch Extension Manager
- $ExtensionManager = Symphony::ExtensionManager();
-
- // Loop through extensions
- foreach($ExtensionManager->listAll() as $handle => $extension) {
-
- // Skip language extensions
- if(strpos($handle, 'lang_') !== false) continue;
-
- // Load translations
- $path = $ExtensionManager->__getClassPath($handle) . '/lang/lang.' . self::get() . '.php';
- if($extension['status'] == EXTENSION_ENABLED && file_exists($path)) {
- self::load($path);
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
+
+ if(is_array($extensions) && !empty($extensions)){
+ foreach($extensions as $e){
+
+ // Skip language extensions
+ if(strpos($e, 'lang_') !== false) continue;
+
+ // Load translations
+ $path = EXTENSIONS . "/{$e}/lang/lang." . self::get() . ".php";
+ if(is_file($path)) self::load($path);
}
}
}
@@ -350,7 +350,7 @@ public static function fetch() {
/**
* Fetch language information for a single language.
- *
+ *
* @param string $source
* The filename of the extension driver where this language
* file was found
@@ -61,8 +61,7 @@ public function __getClassPath($handle){
if(is_file(TEXTFORMATTERS . "/formatter.$handle.php")) return TEXTFORMATTERS;
else{
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){
@@ -108,8 +107,7 @@ public function listAll(){
}
}
- $extensionManager = new ExtensionManager($this->_Parent);
- $extensions = $extensionManager->listInstalledHandles();
+ $extensions = Symphony::ExtensionManager()->listInstalledHandles();
if(is_array($extensions) && !empty($extensions)){
foreach($extensions as $e){

0 comments on commit 4b166e7

Please sign in to comment.