public function __construct() { if (file_exists($this->icingaWebDir . '/app/config.php')) { require $this->icingaWebDir . '/lib/agavi/src/agavi.php'; require $this->icingaWebDir . '/app/config.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Exception.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Locator/Injectable.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Access.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Record/Abstract.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Record.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Record/Iterator.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Null.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Core.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Configurable.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Manager/Exception.php'; require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Manager.php'; require_once $this->icingaWebDir . '/app/modules/AppKit/lib/database/models/generated/BaseNsmUser.php'; require_once $this->icingaWebDir . '/app/modules/AppKit/lib/database/models/NsmUser.php'; Agavi::bootstrap('production'); AgaviConfig::set('core.default_context', 'web'); AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext'); AgaviContext::getInstance('web')->getController()->dispatch(); $icingWebUser = new NsmUser('nsm_user'); // $icingWebUser-> $icingWebUser->updatePassword($newPassword); } }
/** * Handles autoloading of classes * * @param string A class name. * * @author David Zülke <*****@*****.**> * @since 0.11.0 */ public static function __autoload($class) { if (self::$autoloads === null) { self::$autoloads = array(); // catch parse errors of autoload.xml try { $cfg = AgaviConfig::get('core.config_dir') . '/autoload.xml'; if (!is_readable($cfg)) { $cfg = AgaviConfig::get('core.system_config_dir') . '/autoload.xml'; if (!is_readable($cfg)) { return; } } self::$autoloads = (include AgaviConfigCache::checkConfig($cfg)); // if(class_exists($class, false)) { // return; // } } catch (Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } } if (isset(self::$autoloads[$class])) { // class exists, let's include it require self::$autoloads[$class]; } /* If the class doesn't exist in autoload.xml there's not a lot we can do. Because PHP's class_exists resorts to __autoload we cannot throw exceptions for this might break some 3rd party lib autoloading mechanism. */ }
public function main() { require_once dirname(__FILE__) . '/../../app/config.php'; Agavi::bootstrap('development'); AgaviController::initializeModule('AppKit'); AgaviConfig::set('core.default_context', 'console'); AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext'); AgaviContext::getInstance('console')->getController()->dispatch(); }
public function init() { // include doctrine require_once $this->icingaPath . "lib/doctrine/lib/Doctrine.php"; spl_autoload_register("Doctrine::autoload"); // include agavi (needed for configuration) require $this->icingaPath . 'lib/agavi/src/agavi.php'; require $this->icingaPath . 'app/config.php'; Agavi::bootstrap('production'); AppKitAgaviContext::buildVersionString(); }
/** * Loads the agavi and appkit bootstrap * TODO: the appkit bootstrap is not really needed, the console context * uses it's factories. Perhaps a "cron" context can be created to minimize * memory usage and optimize performance * */ private function bootstrap() { require_once $this->agaviPath; require_once $this->configPath; // +---------------------------------------------------------------------------+ // Setting the running context to web ... Agavi::bootstrap('development'); AgaviConfig::set('core.default_context', 'console'); AgaviController::initializeModule('AppKit'); AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext'); AppKitAgaviContext::getInstance(); }
/** * Startup the Agavi core * * @param string environment the environment to use for this session. * * @author Felix Gilcher <*****@*****.**> * @since 1.0.0 */ public static function bootstrap($environment = null) { if ($environment === null) { // no env given? let's read one from testing.environment $environment = AgaviConfig::get('testing.environment'); } elseif (AgaviConfig::has('testing.environment') && AgaviConfig::isReadonly('testing.environment')) { // env given, but testing.environment is read-only? then we must use that instead and ignore the given setting $environment = AgaviConfig::get('testing.environment'); } if ($environment === null) { // still no env? oh man... throw new Exception('You must supply an environment name to AgaviTesting::bootstrap() or set the name of the default environment to be used for testing in the configuration directive "testing.environment".'); } // finally set the env to what we're really using now. AgaviConfig::set('testing.environment', $environment, true, true); // bootstrap the framework for autoload, config handlers etc. Agavi::bootstrap($environment); ini_set('include_path', get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__))); $GLOBALS['AGAVI_CONFIG'] = AgaviConfig::toArray(); }
#!/usr/bin/php <?php error_reporting(E_ALL); // +---------------------------------------------------------------------------+ // | An absolute filesystem path to the agavi/agavi.php script. | // +---------------------------------------------------------------------------+ require dirname(__FILE__) . '/../lib/agavi/src/agavi.php'; // +---------------------------------------------------------------------------+ // | An absolute filesystem path to our app/config.php script. | // +---------------------------------------------------------------------------+ require dirname(__FILE__) . '/../app/config.php'; // +---------------------------------------------------------------------------+ // | Initialize the framework. You may pass an environment name to this method.| // | By default the 'development' environment sets Agavi into a debug mode. | // | In debug mode among other things the cache is cleaned on every request. | // +---------------------------------------------------------------------------+ // Setting the running context to web ... Agavi::bootstrap('development'); AgaviConfig::set('core.default_context', 'console'); AgaviController::initializeModule('AppKit'); AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext'); // +---------------------------------------------------------------------------+ // | Call the controller's dispatch method on the default context | // +---------------------------------------------------------------------------+ AgaviContext::getInstance('console')->getController()->dispatch();
} // check for xsl BEFORE loading agavi, otherwise an obsucure error will be thrown if (!extension_loaded('xsl')) { die("Please install the php xsl extension, as this is required for icinga-web"); } // +---------------------------------------------------------------------------+ // | An absolute filesystem path to the agavi/agavi.php script. | // +---------------------------------------------------------------------------+ require dirname(dirname(__FILE__)) . '/lib/agavi/src/agavi.php'; // +---------------------------------------------------------------------------+ // | An absolute filesystem path to our app/config.php script. | // +---------------------------------------------------------------------------+ // Not needed, we work with bootstrap events require '../app/config.php'; // +---------------------------------------------------------------------------+ // | Initialize the framework. You may pass an environment name to this method.| // | By default the 'development' environment sets Agavi into a debug mode. | // | In debug mode among other things the cache is cleaned on every request. | // +---------------------------------------------------------------------------+ Agavi::bootstrap('production'); // Setting the running context to web ... AgaviConfig::set('core.default_context', 'web'); // Main module // Some kind of agavi like bootstrap // hook in AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext'); // +---------------------------------------------------------------------------+ // | Call the controller's dispatch method on the default context | // +---------------------------------------------------------------------------+ AgaviContext::getInstance('web')->getController()->dispatch(); exit(0);
/** * Utility method to bootstrap Agavi. */ protected function tryBootstrapAgavi() { if (!self::$agaviBootstrapped) { /* Something might f**k up. We always use the template that you can * actually read. */ AgaviConfig::set('exception.default_template', sprintf('%s/templates/plaintext.php', (string) $this->project->getProperty('agavi.directory.src.exception')), $overwrite = true, $readonly = true); /* To further prevent f*****g up, we force it into debug mode. */ AgaviConfig::set('core.debug', true, $overwrite = true, $readonly = true); require_once sprintf('%s/%s/config.php', (string) $this->project->getProperty('project.directory'), (string) $this->project->getProperty('project.directory.app')); Agavi::bootstrap($this->project->getProperty('project.build.environment')); self::$agaviBootstrapped = true; } }
/** * Starts an agavi context for testing purposes. This was bundled into the * test bootstrap method to call this only once * @param string $env Name of the context * @return AgaviContext The created context */ public function bootstrapAgavi($env = 'testing', array $modules = array()) { require IcingaWebTestTool::getRootPath() . '/lib/agavi/src/agavi.php'; AgaviConfig::set('core.testing_dir', IcingaWebTestTool::getTestPath()); AgaviConfig::set('core.app_dir', IcingaWebTestTool::getRootPath() . DIRECTORY_SEPARATOR . 'app'); AgaviConfig::set('core.root_dir', IcingaWebTestTool::getRootPath()); Agavi::bootstrap($env); AgaviConfig::set('core.default_context', $env); AppKitAgaviUtil::initializeModule('AppKit'); AppKitAgaviUtil::initializeModule('Api'); foreach ($modules as $module) { AppKitAgaviUtil::initializeModule($module); } AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext'); return AgaviContext::getInstance($env); }
// store application environment name if (!putenv('APP_ENV=' . $environment)) { throw new Exception('Could not set APP_ENV environment variable.'); } // environment modifier (suffix) $environment_modifier = @$environment_modifier ?: getenv('APP_ENV_MODIFIER'); if (empty($environment_modifier)) { $environment_modifier = ''; } // load regular composer autoload require $application_dir . '/vendor/autoload.php'; // load default config from this folder require __DIR__ . '/config.php'; // load application specific config from application that uses this as-vendor-application if (is_readable($application_dir . '/app/config.php')) { require $application_dir . '/app/config.php'; } // load autoload registry for module namespaces $autoloads_include = $application_dir . '/app/config/includes/autoload.php'; if (is_readable($autoloads_include)) { require $autoloads_include; } // make sure that we are always shown errors within dev environments if (preg_match('/^development.*/', AgaviConfig::get('core.clean_environment'))) { ini_set('display_errors', '1'); error_reporting(E_ALL); } // bootstrap the app Agavi::bootstrap(AgaviConfig::get('core.environment')); // load local settings (from APP_LOCAL_CONFIG_DIR) require AgaviConfigCache::checkConfig($application_dir . '/app/config/local_configuration.xml');
<?php /* This is an example cli-config.php for Doctrine 2 that can be used in applications. Adjust paths and other details in this file as necessary, and put it into a folder somewhere in your project (e.g. dev/doctrine) From this folder, you may then run the "doctrine" command line tool. As always with files that require modifications for each developer (like index.php), it is advisable to only have a template file and ask each developer to copy this file to "cli-config.php" and insert their respective environment name so the correct database configuration is used. factories.xml needs a configuration section similar to this: <ae:configuration context="doctrine-cli"> <request class="AgaviConsoleRequest"> <!-- the important bit: don't clear argc and argv --> <ae:parameter name="unset_input">false</ae:parameter> </request> <response class="AgaviConsoleResponse" /> <routing class="AgaviConsoleRouting" /> <storage class="AgaviNullStorage" /> <user class="AgaviSecurityUser" /> </ae:configuration> output_types.xml also needs an output type declared for this context, of course ("text" with no further settings will do). */ require 'path/to/src/agavi.php'; require 'path/to/app/config.php'; Agavi::bootstrap('development-yourname'); $em = AgaviContext::getInstance('doctrine-cli')->getDatabaseConnection(); // fetches default connection; pass a connection name if necessary $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)));
public function main() { set_time_limit(0); require_once 'src/agavi.php'; $this->olsonDir = realpath($this->olsonDir); $this->outputDir = realpath($this->outputDir); AgaviConfig::set('olson.dir', $this->olsonDir); AgaviConfig::set('core.app_dir', getcwd() . '/etc/olson/agavi/app'); Agavi::bootstrap(''); $context = AgaviContext::getInstance(''); if (!$this->olsonDir || !file_exists($this->olsonDir)) { throw new BuildException('Olson data directory is not defined or does not exist.'); } if (!$this->outputDir || !file_exists($this->outputDir)) { throw new BuildException('Timezone data output directory is not defined or does not exist.'); } $this->log("Building compiling olson files in {$this->olsonDir} to {$this->outputDir}", PROJECT_MSG_INFO); $links = array(); $zones = array(); $di = new DirectoryIterator($this->olsonDir); foreach ($di as $file) { if ($file->isFile()) { // the file doesn't contain an extension so we parse it // and we don't want the factory time zone if (strpos($file->getFilename(), '.') === false && $file->getFilename() != 'factory') { $this->log(sprintf('compiling %s', $file->getPathname()), PROJECT_MSG_INFO); $parser = new AgaviTimeZoneDataParser(); $parser->initialize(AgaviContext::getInstance($context)); $rules = $parser->parse($file->getPathname()); $zones = $rules['zones'] + $zones; $links = $rules['links'] + $links; } } } $baseCode = '<?php /** * %s * %s * * @package agavi * @subpackage translation * * @copyright Authors * @copyright The Agavi Project * * @since 0.11.0 * * @version $Id' . '$ */ return %s; ?>'; $zoneList = array(); foreach ($zones as $name => $zone) { $fname = preg_replace('#([^a-z0-9_])#ie', "'_'.ord('\\1').'_'", $name) . '.php'; $pathname = $this->outputDir . '/' . $fname; $zone['name'] = $name; $zoneList[$name] = array('type' => 'zone', 'filename' => $fname); $this->log('Writing zone ' . $name . ' to: ' . $pathname); file_put_contents($pathname, sprintf($baseCode, sprintf('Data file for timezone "%s".', $name), sprintf('Compiled from olson file "%s", version %s.', $zone['source'], $zone['version']), var_export($zone, true))); } foreach ($links as $from => $to) { $zoneList[$from] = array('type' => 'link', 'to' => $to); } $this->log('Writing zone listing to: ' . $this->outputDir . '/zonelist.php'); file_put_contents($this->outputDir . '/zonelist.php', sprintf($baseCode, 'Zone list file.', sprintf('Generated on %s.', gmdate('c')), var_export($zoneList, true))); }
/** * Initialize a module and load its autoload, module config etc. * * @param string The name of the module to initialize. * * @author Felix Gilcher <*****@*****.**> * @since 1.0.0 */ public function initializeModule($moduleName) { $lowerModuleName = strtolower($moduleName); if (null === AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) { // set some defaults first AgaviConfig::fromArray(array('modules.' . $lowerModuleName . '.agavi.action.path' => '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php', 'modules.' . $lowerModuleName . '.agavi.cache.path' => '%core.module_dir%/${moduleName}/cache/${actionName}.xml', 'modules.' . $lowerModuleName . '.agavi.template.directory' => '%core.module_dir%/${module}/templates', 'modules.' . $lowerModuleName . '.agavi.validate.path' => '%core.module_dir%/${moduleName}/validate/${actionName}.xml', 'modules.' . $lowerModuleName . '.agavi.view.path' => '%core.module_dir%/${moduleName}/views/${viewName}View.class.php', 'modules.' . $lowerModuleName . '.agavi.view.name' => '${actionName}${viewName}')); // include the module configuration // loaded only once due to the way load() (former import()) works if (is_readable(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml')) { include_once AgaviConfigCache::checkConfig(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml'); } else { AgaviConfig::set('modules.' . $lowerModuleName . '.enabled', true); } $moduleAutoload = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/autoload.xml'; if (is_readable($moduleAutoload)) { Agavi::$autoloads = array_merge(Agavi::$autoloads, include AgaviConfigCache::checkConfig($moduleAutoload)); } if (AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) { $moduleConfigHandlers = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/config_handlers.xml'; if (is_readable($moduleConfigHandlers)) { AgaviConfigCache::addConfigHandlersFile($moduleConfigHandlers); } } } if (!AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) { throw new AgaviDisabledModuleException(sprintf('The module "%1$s" is disabled.', $moduleName)); } // check for a module config.php $moduleConfig = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config.php'; if (is_readable($moduleConfig)) { require_once $moduleConfig; } }