64 if ( defined(
'OXID_PHP_UNIT' ) ) {
65 self::$_instance = null;
71 $oUtilsObject =
new oxUtilsObject();
72 self::$_instance = $oUtilsObject->oxNew(
'oxUtilsObject' );
88 $sClassName = strtolower( $sClassName );
89 self::$_aClassInstances[$sClassName] = $oInstance;
99 self::$_aClassInstances = array();
111 self::$_aModuleVars = array();
113 $sMask =
oxRegistry::get(
"oxConfigFile")->getVar(
"sCompileDir") .
"/" . self::CACHE_FILE_PREFIX .
".*.txt" ;
114 $aFiles = glob( $sMask );
115 if ( is_array( $aFiles ) ) {
116 foreach ( $aFiles as $sFile ) {
117 if (is_file($sFile)) {
134 public function oxNew( $sClassName )
136 $aArgs = func_get_args();
137 array_shift( $aArgs );
138 $iArgCnt = count( $aArgs );
139 $blCacheObj = $iArgCnt < 2;
140 $sClassName = strtolower( $sClassName );
142 if ( isset( self::$_aClassInstances[$sClassName] ) ) {
143 return self::$_aClassInstances[$sClassName];
145 if ( !defined(
'OXID_PHP_UNIT' ) && $blCacheObj ) {
146 $sCacheKey = ( $iArgCnt )?$sClassName.md5( serialize( $aArgs ) ):$sClassName;
147 if ( isset( self::$_aInstanceCache[$sCacheKey] ) ) {
148 return clone self::$_aInstanceCache[$sCacheKey];
153 if ( !defined(
'OXID_PHP_UNIT' ) && isset( $this->_aClassNameCache[$sClassName] ) ) {
154 $sActionClassName = $this->_aClassNameCache[$sClassName];
158 if ( !class_exists( $sActionClassName ) ) {
162 $oEx =
oxNew(
"oxSystemComponentException" );
163 $oEx->setMessage(
'EXCEPTION_SYSTEMCOMPONENT_CLASSNOTFOUND');
164 $oEx->setComponent($sClassName);
169 $this->_aClassNameCache[$sClassName] = $sActionClassName;
172 $oActionObject = $this->
_getObject( $sActionClassName, $iArgCnt, $aArgs );
173 if ( $blCacheObj && $oActionObject instanceof
oxBase ) {
174 self::$_aInstanceCache[$sCacheKey] = clone $oActionObject;
177 return $oActionObject;
192 protected function _getObject( $sClassName, $iArgCnt, $aParams )
197 $oObj =
new $sClassName();
200 $oObj =
new $sClassName( $aParams[0] );
203 $oObj =
new $sClassName( $aParams[0], $aParams[1] );
206 $oObj =
new $sClassName( $aParams[0], $aParams[1], $aParams[2] );
211 $oRo =
new ReflectionClass( $sClassName );
212 $oObj = $oRo->newInstanceArgs( $aParams );
213 }
catch ( ReflectionException $oRefExcp ) {
218 $oEx =
oxNew(
"oxSystemComponentException" );
219 $oEx->setMessage( $oRefExcp->getMessage() );
220 $oEx->setComponent( $sClassName );
241 if ( $sOxID && isset( self::$_aLoadedArticles[$sOxID] ) ) {
242 return self::$_aLoadedArticles[$sOxID];
245 $oActionObject = $this->
oxNew(
'oxarticle' );
248 foreach ( $aProperties as $sPropertyName => $sPropertyVal ) {
249 $oActionObject->$sPropertyName = $sPropertyVal;
252 $oActionObject->load( $sOxID );
254 self::$_aLoadedArticles[$sOxID] = $oActionObject;
255 return $oActionObject;
267 if ($sClassName && isset(self::$_aInstanceCache[$sClassName])) {
268 unset(self::$_aInstanceCache[$sClassName]);
273 if (is_array(self::$_aInstanceCache)) {
274 foreach (self::$_aInstanceCache as $sKey => $oInstance) {
275 unset(self::$_aInstanceCache[$sKey]);
279 self::$_aInstanceCache = array();
289 return substr( md5( uniqid(
'',
true ).
'|'.microtime() ), 0, 32 );
305 $aClassChain = array();
308 if (is_array( $aModules )) {
310 $aModules = array_change_key_case( $aModules );
312 if ( array_key_exists( $sClassName, $aModules ) ) {
316 $aClassChain = explode(
"&", $aModules[$sClassName] );
320 if (count($aClassChain)) {
321 $sParent = $sClassName;
324 $sParent = str_replace(chr(0),
'', $sParent);
332 $sClassName = basename( $sClassName );
346 $aDisabledModules = $this->
getModuleVar(
'aDisabledModules' );
349 if (is_array( $aDisabledModules ) && count($aDisabledModules) > 0) {
350 foreach ($aDisabledModules as $sId) {
351 $sPath = $aModulePaths[$sId];
352 if (!isset($sPath)) {
355 foreach ( $aClassChain as $sKey => $sModuleClass ) {
356 if ( strpos($sModuleClass, $sPath.
"/" ) === 0 ) {
357 unset( $aClassChain[$sKey] );
360 elseif ( strpos( $sPath,
"." ) ) {
361 if ( strpos( $sPath, strtolower( $sModuleClass ) ) === 0 ) {
362 unset( $aClassChain[$sKey] );
384 $oModule =
oxNew(
"oxModule");
385 $sModuleId = $oModule->getIdByPath($sModule);
386 $oModule->deactivate($sModuleId);
401 $sParent = $sBaseModule;
402 $sClassName = $sBaseModule;
405 foreach ($aClassChain as $sModule) {
412 $sModule = str_replace(chr(0),
'', $sModule);
415 $sModuleClass = basename($sModule);
417 if ( !class_exists( $sModuleClass,
false ) ) {
418 $sParentClass = basename($sParent);
419 $sModuleParentClass = $sModuleClass.
"_parent";
422 if (!class_exists($sModuleParentClass,
false)) {
424 if (function_exists(
'class_alias')) {
425 class_alias($sParentClass, $sModuleParentClass);
427 eval(
"abstract class $sModuleParentClass extends $sParentClass {}");
430 $sParentPath =
oxRegistry::get(
"oxConfigFile" )->getVar(
"sShopDir" ) .
"/modules/".$sModule.
".php";
433 if ( file_exists( $sParentPath ) ) {
434 include_once $sParentPath;
435 } elseif ( !class_exists( $sModuleClass ) ) {
438 if ( $sParentClass ==
"oxconfig" ) {
439 $oConfig = $this->
_getObject(
"oxconfig", 0, null );
444 $blDisableModuleOnError = !
oxRegistry::get(
"oxConfigFile" )->getVar(
"blDoNotDisableModuleOnError" );
445 if ( $blDisableModuleOnError ) {
449 $oEx =
oxNew(
"oxSystemComponentException" );
450 $oEx->setMessage(
"EXCEPTION_SYSTEMCOMPONENT_CLASSNOTFOUND");
451 $oEx->setComponent( $sModuleClass );
458 $sClassName = $sModule;
487 if ( isset(self::$_aModuleVars[$sModuleVarName]) ) {
488 return self::$_aModuleVars[$sModuleVarName];
495 if ( is_null( $aValue ) ) {
501 self::$_aModuleVars[$sModuleVarName] = $aValue;
516 if ( is_null( $aValues) ) {
517 self::$_aModuleVars = null;
519 self::$_aModuleVars[$sModuleVarName] = $aValues;
532 $sFileName = dirname( __FILE__ ) .
"/oxconfk.php";
533 $sCfgFile =
new oxConfigFile( $sFileName );
534 return $sCfgFile->getVar(
"sConfigKey");
546 if (isset( self::$_aModuleVars[
"urlMap"] )) {
547 return self::$_aModuleVars[
"urlMap"];
552 if (!is_null($aMap)) {
553 self::$_aModuleVars[
"urlMap"] = $aMap;
562 $sSelect =
"SELECT oxshopid, oxvarname, DECODE( oxvarvalue , ".$oDb->quote($sConfKey).
" ) as oxvarvalue ".
563 "FROM oxconfig WHERE oxvarname in ('aLanguageURLs','sMallShopURL','sMallSSLShopURL')";
565 $oRs = $oDb->select($sSelect,
false,
false);
567 if ( $oRs && $oRs->recordCount() > 0) {
568 while ( !$oRs->EOF ) {
569 $iShp = (int) $oRs->fields[0];
570 $sVar = $oRs->fields[1];
571 $sURL = $oRs->fields[2];
573 if ($sVar ==
'aLanguageURLs') {
574 $aUrls = unserialize($sURL);
575 if (is_array($aUrls) && count($aUrls)) {
576 $aUrls = array_filter($aUrls);
577 $aUrls = array_fill_keys($aUrls, $iShp);
578 $aMap = array_merge($aMap, $aUrls);
581 $aMap[$sURL] = $iShp;
590 self::$_aModuleVars[
"urlMap"] = $aMap;
616 if (is_null($sShopId)) {
621 $sVar = strtolower( basename ($sModuleVarName) );
622 $sShop = strtolower( basename ($sShopId) );
624 $sFileName = $sDir .
"/" . self::CACHE_FILE_PREFIX .
"." . $sShop .
'.' . $sVar .
".txt";
643 $sSelect =
"SELECT DECODE( oxvarvalue , ".$oDb->quote($sConfKey).
" ) FROM oxconfig ".
644 "WHERE oxvarname = ".$oDb->quote( $sModuleVarName ).
" AND oxshopid = ".$oDb->quote($sShopId);
646 $sModuleVarName = $oDb->getOne($sSelect,
false,
false);
648 $sModuleVarName = unserialize( $sModuleVarName );
650 return $sModuleVarName;
662 protected function _getFromCache( $sModuleVarName, $blSubshopSpecific =
true )
665 if ( !$blSubshopSpecific ) {
671 if ( is_readable( $sFileName ) ) {
672 $sValue = file_get_contents( $sFileName );
673 if ( $sValue == serialize(
false ) ) {
677 $sValue = unserialize( $sValue );
678 if ( $sValue ===
false ) {
695 protected function _setToCache( $sVarName, $sValue, $blSubshopSpecific =
true )
698 if ( !$blSubshopSpecific ) {
703 file_put_contents( $sFileName, serialize($sValue), LOCK_EX );