PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/data/symfony/bin/symfony.php

http://pumukit.googlecode.com/
PHP | 176 lines | 129 code | 31 blank | 16 comment | 15 complexity | 8634d4e855289203fd37666e4be2fc1d MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. if (!isset($sf_symfony_lib_dir))
  10. {
  11. die("You must launch symfony command line with the symfony script\n");
  12. }
  13. if (ini_get('zend.ze1_compatibility_mode'))
  14. {
  15. die("symfony cannot run with zend.ze1_compatibility_mode enabled.\nPlease turn zend.ze1_compatibility_mode to Off in your php.ini.\n");
  16. }
  17. // set magic_quotes_runtime to off
  18. ini_set('magic_quotes_runtime', 'Off');
  19. // check if we are using an old project
  20. if (file_exists('config/config.php') && !isset($sf_symfony_lib_dir))
  21. {
  22. // allow only upgrading
  23. if (!in_array('upgrade', $argv))
  24. {
  25. echo "Please upgrade your project before launching any other symfony task\n";
  26. exit();
  27. }
  28. }
  29. require_once($sf_symfony_lib_dir.'/vendor/pake/pakeFunction.php');
  30. require_once($sf_symfony_lib_dir.'/vendor/pake/pakeGetopt.class.php');
  31. // autoloading for pake tasks
  32. class simpleAutoloader
  33. {
  34. static public
  35. $class_paths = array(),
  36. $autoload_callables = array();
  37. static public function initialize($sf_symfony_lib_dir)
  38. {
  39. self::$class_paths = array();
  40. self::register($sf_symfony_lib_dir, '.class.php');
  41. self::register($sf_symfony_lib_dir.'/vendor/propel', '.php');
  42. self::register($sf_symfony_lib_dir.'/vendor/creole', '.php');
  43. self::register('lib/model', '.php');
  44. self::register('plugins', '.php');
  45. }
  46. static public function __autoload($class)
  47. {
  48. if (!isset(self::$class_paths[$class]))
  49. {
  50. foreach ((array) self::$autoload_callables as $callable)
  51. {
  52. if (call_user_func($callable, $class))
  53. {
  54. return true;
  55. }
  56. }
  57. return false;
  58. }
  59. require_once(self::$class_paths[$class]);
  60. return true;
  61. }
  62. static public function register($dir, $ext)
  63. {
  64. if (!is_dir($dir))
  65. {
  66. return;
  67. }
  68. foreach (pakeFinder::type('file')->name('*'.$ext)->ignore_version_control()->follow_link()->in($dir) as $file)
  69. {
  70. self::$class_paths[str_replace($ext, '', str_replace('.class', '', basename($file, $ext)))] = $file;
  71. }
  72. }
  73. static public function add($class, $file)
  74. {
  75. if (!is_file($file))
  76. {
  77. return;
  78. }
  79. self::$class_paths[$class] = $file;
  80. }
  81. static public function registerCallable($callable)
  82. {
  83. if (!is_callable($callable))
  84. {
  85. throw new Exception('Autoload callable does not exist');
  86. }
  87. self::$autoload_callables[] = $callable;
  88. }
  89. }
  90. function __autoload($class)
  91. {
  92. static $initialized = false;
  93. if (!$initialized)
  94. {
  95. simpleAutoloader::initialize(sfConfig::get('sf_symfony_lib_dir'));
  96. $initialized = true;
  97. }
  98. return simpleAutoloader::__autoload($class);
  99. }
  100. // trap -V before pake
  101. if (in_array('-V', $argv) || in_array('--version', $argv))
  102. {
  103. printf("symfony version %s\n", pakeColor::colorize(trim(file_get_contents($sf_symfony_lib_dir.'/VERSION')), 'INFO'));
  104. exit(0);
  105. }
  106. if (count($argv) <= 1)
  107. {
  108. $argv[] = '-T';
  109. }
  110. require_once($sf_symfony_lib_dir.'/config/sfConfig.class.php');
  111. sfConfig::add(array(
  112. 'sf_root_dir' => getcwd(),
  113. 'sf_symfony_lib_dir' => $sf_symfony_lib_dir,
  114. 'sf_symfony_data_dir' => $sf_symfony_data_dir,
  115. ));
  116. // directory layout
  117. include($sf_symfony_data_dir.'/config/constants.php');
  118. // include path
  119. set_include_path(
  120. sfConfig::get('sf_lib_dir').PATH_SEPARATOR.
  121. sfConfig::get('sf_app_lib_dir').PATH_SEPARATOR.
  122. sfConfig::get('sf_model_dir').PATH_SEPARATOR.
  123. sfConfig::get('sf_symfony_lib_dir').DIRECTORY_SEPARATOR.'vendor'.PATH_SEPARATOR.
  124. get_include_path()
  125. );
  126. // register tasks
  127. $dirs = array(
  128. sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'tasks' => 'myPake*.php', // project tasks
  129. sfConfig::get('sf_symfony_data_dir').DIRECTORY_SEPARATOR.'tasks' => 'sfPake*.php', // symfony tasks
  130. sfConfig::get('sf_root_dir').'/plugins/*/data/tasks' => '*.php', // plugin tasks
  131. );
  132. foreach ($dirs as $globDir => $name)
  133. {
  134. if ($dirs = glob($globDir))
  135. {
  136. $tasks = pakeFinder::type('file')->ignore_version_control()->name($name)->in($dirs);
  137. foreach ($tasks as $task)
  138. {
  139. include_once($task);
  140. }
  141. }
  142. }
  143. // run task
  144. pakeApp::get_instance()->run(null, null, false);
  145. exit(0);