Exemple #1
0
 /**
  * get model class by controller name or false
  * try to include it, if can't return false
  * we can't use autoload for it, because include on non existing file throw error/warning, that shut down app
  *
  * @return bool|string class name or false
  */
 public function getModelClass()
 {
     $class = ucfirst(str_replace('Admin', '', $this->id));
     if (!class_exists($class, false)) {
         @Yii::autoload($class);
         if (!class_exists($class, false)) {
             return false;
         }
     }
     return $class;
 }
Exemple #2
0
 public static function import($alias, $forceInclude = false)
 {
     if (isset(self::$_imports[$alias])) {
         //是否已经存在路径
         return self::$_imports[$alias];
     }
     if (class_exists($alias, false) || interface_exists($alias, false)) {
         //类是否已经定义,针对如urlManager这样的已定义于$_coreClasses[]的类
         return self::$_imports[$alias] = $alias;
     }
     if (($pos = strrpos($alias, '.')) === false) {
         // try to autoload the class with an autoloader if $forceInclude is true
         if ($forceInclude && (Yii::autoload($alias, true) || class_exists($alias, true))) {
             self::$_imports[$alias] = $alias;
         }
         return $alias;
     }
     $className = (string) substr($alias, $pos + 1);
     $isClass = $className !== '*';
     //是否为路径+类名
     if ($isClass && (class_exists($className, false) || interface_exists($className, false))) {
         return self::$_imports[$alias] = $className;
     }
     //获取真实路径
     if (($path = self::getPathOfAlias($alias)) !== false) {
         //是否以*结尾,如application.utils.*
         if ($isClass) {
             if ($forceInclude) {
                 if (is_file($path . '.php')) {
                     require $path . '.php';
                 } else {
                     throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.', array('{alias}' => $alias)));
                 }
                 self::$_imports[$alias] = $className;
             } else {
                 self::$classMap[$className] = $path . '.php';
             }
             return $className;
         } else {
             if (self::$_includePaths === null) {
                 self::$_includePaths = array_unique(explode(PATH_SEPARATOR, get_include_path()));
                 if (($pos = array_search('.', self::$_includePaths, true)) !== false) {
                     unset(self::$_includePaths[$pos]);
                 }
             }
             array_unshift(self::$_includePaths, $path);
             if (self::$enableIncludePath && set_include_path('.' . PATH_SEPARATOR . implode(PATH_SEPARATOR, self::$_includePaths)) === false) {
                 self::$enableIncludePath = false;
             }
             return self::$_imports[$alias] = $path;
         }
     }
 }
Exemple #3
0
		return $this->object[$name];
	}

	public static function initClass($className){
		if(strtolower(substr($className,0,5)) != "eyii.")return 'BaseExtClass';
		list(,$module, $type, $class) = explode(".",$className);

		$classConstruct = $class."Ext".ucfirst($type);



		Yii::import('application.modules.'.strtolower($module).'.models.*');
		if(!is_callable($classConstruct,true)){
			if(!Yii::autoload($classConstruct)){
				return false;
Exemple #4
0
 public static function import($alias, $forceInclude = false)
 {
     if (isset(self::$_imports[$alias])) {
         // previously imported
         return self::$_imports[$alias];
     }
     if (class_exists($alias, false) || interface_exists($alias, false)) {
         return self::$_imports[$alias] = $alias;
     }
     if (($pos = strrpos($alias, '\\')) !== false) {
         $namespace = str_replace('\\', '.', ltrim(substr($alias, 0, $pos), '\\'));
         if (($path = self::getPathOfAlias($namespace)) !== false) {
             $classFile = $path . DIRECTORY_SEPARATOR . substr($alias, $pos + 1) . '.php';
             if ($forceInclude) {
                 if (is_file($classFile)) {
                     require $classFile;
                 } else {
                     throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.', array('{alias}' => $alias)));
                 }
                 self::$_imports[$alias] = $alias;
             } else {
                 self::$classMap[$alias] = $classFile;
             }
             return $alias;
         } else {
             // try to autoload the class with an autoloader
             if (class_exists($alias, true)) {
                 return self::$_imports[$alias] = $alias;
             } else {
                 throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing directory or file.', array('{alias}' => $namespace)));
             }
         }
     }
     if (($pos = strrpos($alias, '.')) === false) {
         // try to autoload the class with an autoloader if $forceInclude is true
         if ($forceInclude && (Yii::autoload($alias, true) || class_exists($alias, true))) {
             self::$_imports[$alias] = $alias;
         }
         return $alias;
     }
     $className = (string) substr($alias, $pos + 1);
     $isClass = $className !== '*';
     if ($isClass && (class_exists($className, false) || interface_exists($className, false))) {
         return self::$_imports[$alias] = $className;
     }
     if (($path = self::getPathOfAlias($alias)) !== false) {
         if ($isClass) {
             if ($forceInclude) {
                 if (is_file($path . '.php')) {
                     require $path . '.php';
                 } else {
                     throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.', array('{alias}' => $alias)));
                 }
                 self::$_imports[$alias] = $className;
             } else {
                 self::$classMap[$className] = $path . '.php';
             }
             return $className;
         } else {
             if (self::$_includePaths === null) {
                 self::$_includePaths = array_unique(explode(PATH_SEPARATOR, get_include_path()));
                 if (($pos = array_search('.', self::$_includePaths, true)) !== false) {
                     unset(self::$_includePaths[$pos]);
                 }
             }
             array_unshift(self::$_includePaths, $path);
             if (self::$enableIncludePath && set_include_path('.' . PATH_SEPARATOR . implode(PATH_SEPARATOR, self::$_includePaths)) === false) {
                 self::$enableIncludePath = false;
             }
             return self::$_imports[$alias] = $path;
         }
     } else {
         throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing directory or file.', array('{alias}' => $alias)));
     }
 }
 /**
  * Tricky way to get correct model class from file name.
  * @param string $fileName
  * @return string
  */
 public function getModelClass($fileName)
 {
     $modelClass = '\\' . str_replace('.', '\\', $this->modelPath . '.' . $fileName);
     if (class_exists($modelClass, false)) {
         return $modelClass;
     } elseif (class_exists($fileName, false)) {
         return $fileName;
     } elseif (Yii::autoload($modelClass)) {
         return $modelClass;
     } else {
         return $fileName;
     }
 }
Exemple #6
0
 /**
  * @return array options for creating SoapServer instance
  * @see http://www.php.net/manual/en/soapserver.soapserver.php
  */
 protected function getOptions()
 {
     $options = array();
     if ($this->soapVersion === '1.1') {
         $options['soap_version'] = SOAP_1_1;
     } elseif ($this->soapVersion === '1.2') {
         $options['soap_version'] = SOAP_1_2;
     }
     if ($this->actor !== null) {
         $options['actor'] = $this->actor;
     }
     $options['encoding'] = $this->encoding;
     foreach ($this->classMap as $type => $className) {
         \Yii::autoload($className);
         if (is_int($type)) {
             $type = $className;
         }
         $options['classmap'][$type] = $className;
     }
     return $options;
 }
 /**
  * @param string $type PHP variable type
  */
 protected function processType($type)
 {
     if (isset(self::$typeMap[$type])) {
         return self::$typeMap[$type];
     } elseif (isset($this->types[$type])) {
         return is_array($this->types[$type]) ? 'tns:' . $type : $this->types[$type];
     } elseif (($pos = strpos($type, '[]')) !== false) {
         // array of types
         $type = substr($type, 0, $pos);
         $this->types[$type . '[]'] = 'tns:' . $type . 'Array';
         $this->processType($type);
         return $this->types[$type . '[]'];
     } else {
         // process class / complex type
         \Yii::autoload($type);
         $class = new \ReflectionClass($type);
         $type = $class->getShortName();
         $comment = $class->getDocComment();
         $comment = strtr($comment, array("\r\n" => "\n", "\r" => "\n"));
         // make line endings consistent: win -> unix, mac -> unix
         $comment = preg_replace('/^\\s*\\**(\\s*?$|\\s*)/m', '', $comment);
         // extract soap indicator flag, if defined, e.g. @soap-indicator sequence
         // see http://www.w3schools.com/schema/schema_complex_indicators.asp
         if (preg_match('/^@soap-indicator\\s+(\\w+)\\s*?(.*)$/im', $comment, $matches)) {
             $indicator = $matches[1];
             $attributes = $this->getWsdlElementAttributes($matches[2]);
         } else {
             $indicator = 'all';
             $attributes = $this->getWsdlElementAttributes('');
         }
         $custom_wsdl = false;
         if (preg_match_all('/^@soap-wsdl\\s+(\\S.*)$/im', $comment, $matches) > 0) {
             $custom_wsdl = implode("\n", $matches[1]);
         }
         $this->types[$type] = array('indicator' => $indicator, 'nillable' => $attributes['nillable'], 'minOccurs' => $attributes['minOccurs'], 'maxOccurs' => $attributes['maxOccurs'], 'custom_wsdl' => $custom_wsdl, 'properties' => array());
         foreach ($class->getProperties() as $property) {
             $comment = $property->getDocComment();
             if ($property->isPublic() && strpos($comment, '@soap') !== false) {
                 if (preg_match('/@var\\s+([\\w\\.\\\\]+(\\[\\s*\\])?)\\s*?(.*)$/mi', $comment, $matches)) {
                     $attributes = $this->getWsdlElementAttributes($matches[3]);
                     if (preg_match('/{(.+)}/', $comment, $attr)) {
                         $matches[3] = str_replace($attr[0], '', $matches[3]);
                     }
                     // extract PHPDoc @example
                     $example = '';
                     if (preg_match("/@example[:]?(.+)/mi", $comment, $match)) {
                         $example = trim($match[1]);
                     }
                     $this->types[$type]['properties'][$property->getName()] = array($this->processType(str_replace('\\', '/', $matches[1])), trim($matches[3]), $attributes['nillable'], $attributes['minOccurs'], $attributes['maxOccurs'], $example);
                     // name => type, doc, nillable, minOccurs, maxOccurs, example
                 }
             }
         }
         return 'tns:' . $type;
     }
 }