ultimix
core_public_api.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
30  function throw_exception( $Message )
31  {
32  throw( new Exception( $Message ) );
33  }
34 
49  function mkdir_ex( $Path )
50  {
51  @mkdir( $Path );
52  file_put_contents( rtrim( $Path , "/\\" ).'/index.html' , '<html><head></head><body></body></html>' );
53  }
54 
73  function get_package_version_s( $ClassName )
74  {
75  $ClassVersion = explode( '_' , $ClassName );
76  $ClassVersionRet = '';
77  $ClassVersionRet = array_pop( $ClassVersion ).$ClassVersionRet;
78  $ClassVersionRet = array_pop( $ClassVersion ).'.'.$ClassVersionRet;
79  $ClassVersionRet = array_pop( $ClassVersion ).'.'.$ClassVersionRet;
80  return( $ClassVersionRet );
81  }
82 
105  function _get_package_from_cache( $Key )
106  {
107  try
108  {
109  global $ObjectLabel;
110  global $PackageCache;
111  global $PackagePathsCache;
112  $ObjectLabel = 'default';
113  return( $PackageCache[ $PackagePathsCache[ $Key ][ 'path' ] ] );
114  }
115  catch( Exception $e )
116  {
117  $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
118  }
119  }
120 
157  function get_package( $PackageName , $PackageVersion = 'last' , $PackageScriptPath = false )
158  {
159  try
160  {
161  list( $Fetched , $Object ) = _try_fetch_from_cache( $PackageName , $PackageVersion );
162 
163  global $ObjectLabel;
164  if( $Fetched )
165  {
166  $ObjectLabel = 'default';
167  return( $Object );
168  }
169 
170  _fill_package_paths_cache( $PackageName , $PackageVersion , $PackageScriptPath );
171  _store_package_path( $PackageName , $PackageVersion );
172  $PackageClassName = _package_script_fast_load( $PackageName , $PackageVersion );
173 
174  $Key = "$PackageName $PackageVersion $ObjectLabel";
175  _store_package_object( $PackageClassName , $Key );
176 
177  return( _get_package_from_cache( $Key ) );
178  }
179  catch( Exception $e )
180  {
181  $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
182  }
183  }
184 
186 
218  function get_package_object( $PackageName , $PackageVersion = 'last' , $PackageScriptPath = false )
219  {
220  try
221  {
222  list( $PackageName , $PackageVersion ) = _get_package_info_after_rewrites(
223  $PackageName , $PackageVersion , $PackageScriptPath
224  );
225 
226  global $GetPackageObjectCache;
227  $Key = "$PackageName $PackageVersion";
228 
229  if( isset( $GetPackageObjectCache[ $Key ] ) === false )
230  {
231  get_package( $PackageName , $PackageVersion , $PackageScriptPath );
232 
233  $GetPackageObjectCache[ $Key ] = _get_requested_class_name();
234  }
235 
236  $ClassName = $GetPackageObjectCache[ $Key ];
237 
238  return( new $ClassName() );
239  }
240  catch( Exception $e )
241  {
242  $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
243  }
244  }
245 ?>