Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpextension.php
Go to the documentation of this file.
1 <?php
15 class ezpExtension
16 {
17 public $name;
18
24 private static $instances = array();
25
31 protected function __construct( $name )
32 {
33 $this->name = $name;
34 }
35
44 public static function getInstance( $name )
45 {
46 if (! isset( self::$instances[$name] ) )
47 self::$instances[$name] = new self( $name );
48
49 return self::$instances[$name];
50 }
51
57 public function getLoadingOrder()
58 {
59 $return = array( 'before' => array(), 'after' => array() );
60
61 if ( is_readable( $XMLDependencyFile = eZExtension::baseDirectory() . "/{$this->name}/extension.xml" ) )
62 {
63 libxml_use_internal_errors( true );
64 $xml = simplexml_load_file( $XMLDependencyFile );
65 // xml parsing error
66 if ( $xml === false )
67 {
68 eZDebug::writeError( libxml_get_errors(), "ezpExtension( {$this->name} )::getLoadingOrder()" );
69 return null;
70 }
71 foreach ( $xml->dependencies as $dependenciesNode )
72 {
73 foreach ( $dependenciesNode as $dependencyType => $dependenciesNode )
74 {
75 switch ( $dependencyType )
76 {
77 case 'requires':
78 $relationship = 'after';
79 break;
80
81 case 'uses':
82 $relationship = 'after';
83 break;
84
85 case 'extends':
86 $relationship = 'before';
87 break;
88 }
89
90 foreach ( $dependenciesNode as $dependency )
91 {
92 $return[$relationship][] = (string)$dependency['name'];
93 }
94 }
95 }
96 }
97
98 return $return;
99 }
100
108 public function getInfo()
109 {
110 // try extension.xml first
111 if ( is_readable( $XMLFilePath = eZExtension::baseDirectory() . "/{$this->name}/extension.xml" ) )
112 {
113 $infoFields = array( 'name', 'description', 'version', 'copyright', 'author', 'license', 'info_url' );
114
115 libxml_use_internal_errors( true );
116 $xml = simplexml_load_file( $XMLFilePath );
117 // xml parsing error
118 if ( $xml === false )
119 {
120 eZDebug::writeError( libxml_get_errors(), "ezpExtension({$this->name})::getInfo()" );
121 return null;
122 }
123 $return = array();
124 $metadataNode = $xml->metadata;
125
126 // standard extension metadata
127 foreach ( $infoFields as $field )
128 {
129 if ( (string)$metadataNode->$field !== '' )
130 $return[$field] = (string)$metadataNode->$field;
131 }
132
133 // 3rd party software
134 if ( !$metadataNode->software->uses )
135 return $return;
136
137 $index = 1;
138 foreach ( $metadataNode->software->uses as $software )
139 {
140 $label = "Includes the following third-party software";
141 if ( $index > 1 )
142 $label .= " (" . $index . ")";
143
144 foreach ( $infoFields as $field )
145 {
146 if ( (string)$software->$field !== '' )
147 $return[$label][$field] = (string)$software->$field;
148 }
149 $index++;
150 }
151
152 return $return;
153 }
154 // then try ezinfo.php, for backwards compatibility
155 elseif ( is_readable( $infoFilePath = eZExtension::baseDirectory() . "/{$this->name}/ezinfo.php" ) )
156 {
157 include_once( $infoFilePath );
158 $className = $this->name . 'Info';
159 if ( is_callable( array( $className, 'info' ) ) )
160 {
161 $result = call_user_func_array( array( $className, 'info' ), array() );
162 if ( is_array( $result ) )
163 {
164 return $result;
165 }
166 }
167 }
168 else
169 {
170 return null;
171 }
172 }
173 }
174 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:546
eZExtension\baseDirectory
static baseDirectory(eZINI|null $siteINI=null)
Definition: ezextension.php:40
ezpExtension
Definition: ezpextension.php:16
ezpExtension\$instances
static $instances
Definition: ezpextension.php:24
ezpExtension\$name
$name
Definition: ezpextension.php:17
ezpExtension\getInfo
getInfo()
Definition: ezpextension.php:108
ezpExtension\getLoadingOrder
getLoadingOrder()
Definition: ezpextension.php:57
ezpExtension\getInstance
static getInstance( $name)
Definition: ezpextension.php:44
ezpExtension\__construct
__construct( $name)
Definition: ezpextension.php:31
$result
$result
Definition: companysearch.php:94
$index
$index
Definition: ezforum/user/messageedit.php:36
$field
$field
Definition: listtable.php:41
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.