chiamate con istanza di altra classe rispetto la classe di app. (plugin)

  • Creatore Discussione Creatore Discussione andriun
  • Data di inizio Data di inizio

andriun

Nuovo Utente
14 Nov 2014
5
2
0
Salve, vi chiedo un cortesemente un chiarimento, dal momento che per le mie conoscenze attuali non riesco a trovare una motivazione plausibile al comportamento da me riscontrato durante il debug. Premetto che non è facile per me esporre il problema, senza dover postare montagne di codice, quindi diciamo che faccio un tentativo: se a qualcuno viene in mente qualche cosa bene, altrimenti vedrò come fare. Aggiungo anche che come vedrete più avanti e come indicato nell'oggetto, si tratta di un plugin wp, anche se il mio sospetto è che il mio problema abbia poco a che vedere con questo.

In ogni caso ringrazio in anticipo chi vorrà intervenire.

Il codice prende inizio da qui:

PHP:
require_once ( 'framework/init.php' );


if ( ! class_exists( 'userMeta' ) ) :
class userMeta extends pluginFramework {

....
//Load Plugins & Framework modal classes
        global $pluginFramework, $userMetaCache;
        $this->cacheName        = 'userMetaCache';
        $userMetaCache          = new stdClass;
        
        $this->loadModels( $this->modelsPath );
        $this->loadModels( $pluginFramework->modelsPath );                                     
    }

}
endif;

global $userMeta;
$userMeta = new userMeta;
$userMeta->init();

qui viene chiamata l'altra classe 'framework/init.php' lascio anche il commento di testa se può aiutare a capire per chi si ritiene esperto/navigato.

PHP:
/**
 * Framework for wordpress plugin
 * Primary framework class is pluginFramework
 * global varaiable $pluginFramework are available as instance of pluginFramework class
 * all classes from models directory are preloaded with $pluginFramework
 * any method of models class can be access as $pluginFramework->methodNmae(); 
 */

if ( ! class_exists( 'pluginFramework' ) ) :
class pluginFramework {
...
...
    function __construct() {                          
        $this->frameworkPath   = dirname( __FILE__ );
        $this->modelsPath      = $this->frameworkPath . '/models/';
		  
        $this->controllersPath = $this->frameworkPath . '/controllers/';
        $this->viewsPath       = $this->frameworkPath . '/views/';
        
        $this->loadModels( $this->modelsPath );
		  
        $this->pluginPath      = $this->directoryUp( $this->frameworkPath );  <-- avviene il fatto strano(*)


(*) infatti $this contiene "pluginFramework", ma "directoryUp" risiede in altra classe(vedi sotto) e non ne è figlia         

....
....
    function init() {        
....
....
        $this->pluginInit();  
		  
    }



if ( ! class_exists( 'PluginFrameworkRawFunction' ) ):
    class PluginFrameworkRawFunction {
....
....
        /**
         * go up one directory/url
         * @param string $path: url or path
         * @return string : path/url without last slash
         */
        function directoryUp( $path ) {
...
...

A qualcuno viene in mente per caso a cosa potrebbe essere dovuto tale comportamento?
 
Salve, vi chiedo un cortesemente un chiarimento...

Ho capito dove stava l'arcano: la variabile $this in questo caso non contiene un'unica istanza, come mi aspettavo di trovare, ma una serie di istanze tra cui esiste anche quella della classe PluginFrameworkRawFunction(adesso posso dire: ovvio) a cui il metodo "directoryUp" appartiene.

saluti.
 

Discussioni simili