jsAutoLoad.php
Go to the documentation of this file.00001 <?php
00002 $strDir = __DIR__;
00003 $strFile = __FILE__;
00004 print "/* __DIR__ $strDir*/";
00005 print "/* __FILE__ $strFile*/";
00006 $arrDir = explode( "/" , $strDir );
00007 array_pop( $arrDir );
00008 $intDeep = isset( $_REQUEST['deep'] ) ? $_REQUEST['deep'] : 0;
00009 $intBack = isset( $_REQUEST['back'] ) ? $_REQUEST['back'] : 0;
00010
00011 while( $intDeep-- )
00012 {
00013 array_pop( $arrDir );
00014 }
00015 $strDir = implode( "/" , $arrDir );
00016 print "/* strDir $strDir*/";
00017 for( $i = 0 ; $i < $intBack ; $i++ )
00018 {
00019 array_pop( $arrDir );
00020 }
00021 $strBack = implode( "/" , $arrDir );
00022 print "/* strBack $strBack*/";
00023
00024 $arrFolders = array();
00025 $arrFiles = ( describe_folder( $strDir , $strBack , $arrFolders ) );
00026
00027 function describe_folder( $strDir , $strParentDir = null , &$arrFolders = null)
00028 {
00029 $arrFiles = array();
00030 if( $arrFolders == null )
00031 {
00032 $arrFolders = array();
00033 }
00034
00035 if( $strParentDir == null )
00036 {
00037 $strParentDir = $strDir;
00038 }
00039
00040 $arrDirFiles = scandir( $strDir );
00041 foreach( $arrDirFiles as $strFileName )
00042 {
00043 if( $strFileName[0] == "." )
00044 {
00045 continue;
00046 }
00047 $strDirFolder = $strDir . '/' . $strFileName;
00048 if( is_dir( $strDirFolder ) )
00049 {
00050 $strShortName = str_replace( array( "-" , '+' , ' ' , '.' ), "_" , $strFileName );
00051 $arrFolders[ $strShortName ] = $strDirFolder;
00052 $arrChildFiles = describe_folder( $strDirFolder , $strParentDir , $arrFolders );
00053 $arrFiles = array_merge( $arrFiles , $arrChildFiles );
00054 }
00055 else
00056 {
00057 $strType = ( substr( $strFileName , strpos( $strFileName , "." ) ) );
00058 if( $strType == ".js" )
00059 {
00060 $strPath = $strDirFolder;
00061 $strRelative = "." . str_replace( $strParentDir , "", $strPath );
00062 $strShortName = substr( $strFileName , 0 , -3 );
00063 $strShortName = str_replace( array( "-" , '+' , ' ' , '.' ), "_" , $strShortName );
00064
00065 $arrFiles[ ucfirst( $strShortName ) ] = $strRelative;
00066 }
00067 }
00068 }
00069 return $arrFiles;
00070 }
00071 ?>
00072 window.autoload = function(){};
00073
00074 <?php foreach( $arrFiles as $strShortNameFile => $strPathFile ): ?>
00075 window.autoload.<?php print "load" . $strShortNameFile ?> = function <?php print "load" . $strShortNameFile ?>()
00076 {
00077 require_once( "<?php print str_repeat( "../", $intBack ) . $strPathFile ?>" );
00078 return <? print $strShortNameFile ?>;
00079 }
00080 window.autoload.<?php print "new" . $strShortNameFile ?> = function <?php print "new" . $strShortNameFile ?>( p1 , p2 , p3 , p4 , p5 , p6 )
00081 {
00082 window.autoload.<?php print "load" . $strShortNameFile ?>();
00083 var objElement = new <?php print $strShortNameFile ?>( p1 , p2 , p3 , p4 , p5 , p6 );
00084 return objElement;
00085 };
00086
00087 <? endforeach ?>
00088 <?php foreach( $arrFolders as $strShort => $strFolder ): ?>
00089 window.autoload.getPathOf<?php print ucfirst( $strShort ) ?> = function getPathOf<?php print ucfirst( $strShort ) ?>()
00090 {
00091 return '<?php print str_repeat( "../", $intBack ) . '.' . substr( $strFolder , strlen( $strDir ) ) ?>';
00092 }
00093 <? endforeach ?>