作者:BGCX26
项目:zibo-svn-to-gi
protected static function setInvertToCreatedFilter(AbstractInvertLogItemFilter $filter, Zibo $zibo, $name, $configBase)
{
$configInvert = $configBase . Module::CONFIG_INVERT;
$invert = $zibo->getConfigValue($configInvert);
if ($invert !== null) {
$filter->setInvert($invert);
}
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Gets the dependency container
* @param zibo\core\Zibo $zibo Instance of zibo
* @return zibo\core\di\DependencyContainer
*/
public function getContainer(Zibo $zibo)
{
$container = new DependencyContainer();
$files = array_reverse($zibo->getFiles(self::PATH_FILE));
foreach ($files as $file) {
$this->readDependencies($container, $file);
}
return $container;
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Gets the MIME type of a file based on it's extension
* @param zibo\core\Zibo $zibo Instance of Zibo
* @param zibo\library\filesystem\File $file The file to get the MIME from
* @return string The MIME type of the file
*/
public static function getMimeType(Zibo $zibo, File $file)
{
$extension = $file->getExtension();
if (empty($extension)) {
return self::MIME_UNKNOWN;
}
$mime = $zibo->getConfigValue(self::CONFIG_MIME . $extension);
if (!$mime) {
$mime = self::MIME_UNKNOWN;
}
return $mime;
}
作者:BGCX26
项目:zibo-svn-to-gi
public function testMainWithChainedRequests()
{
$routerMock = $this->getMock('zibo\\core\\router\\Router', array('getRequest', 'getRoutes', 'getAliases'));
$routerMockCall = $routerMock->expects($this->once());
$routerMockCall->method('getRequest');
$routerMockCall->will($this->returnValue(new Request('', '', 'zibo\\core\\TestController', 'chainAction')));
$zibo = new Zibo($this->getBrowserMock(), $this->getConfigIOMock());
$zibo->setRouter($routerMock);
$zibo->setDispatcher(new GenericDispatcher($zibo, new ObjectFactory()));
$zibo->main();
$this->assertEquals(array('chain', 'index'), TestController::$actions);
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Gets all the translations for the provided locale
* @param string $localeCode code of the locale
* @return array an associative array with translation key - value pairs
* @throws zibo\ZiboException when the locale code is empty or invalid
*/
public function getTranslations($localeCode)
{
if (!String::isString($localeCode, String::NOT_EMPTY)) {
throw new ZiboException('Provided locale code is empty');
}
if (isset($this->translations[$localeCode])) {
return $this->translations[$localeCode];
}
$this->translations[$localeCode] = array();
$translationFile = Zibo::DIRECTORY_L10N . File::DIRECTORY_SEPARATOR . $localeCode . self::EXTENSION;
$translationFiles = array_reverse($this->zibo->getFiles($translationFile));
$this->translations[$localeCode] = $this->getTranslationsFromFiles($translationFiles);
return $this->translations[$localeCode];
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Dispatches a request to the action of a controller
* @param Request $request The request to dispatch
* @param Response $response The response to dispatch the request to
* @return mixed The return value of the action
* @throws zibo\ZiboException when the action is not invokable
*/
public function dispatch(Request $request, Response $response)
{
$controller = $this->getController($request);
$actionName = $request->getActionName();
$parameters = $request->getParameters();
$callback = $this->processAction($controller, $actionName, $parameters);
$this->prepareController($controller, $request, $response, $actionName, $parameters);
$this->zibo->triggerEvent(self::EVENT_PRE_DISPATCH, $controller, $actionName, $parameters);
$controller->preAction();
$returnValue = $callback->invokeWithArrayArguments($parameters);
$controller->postAction();
$this->zibo->triggerEvent(self::EVENT_POST_DISPATCH, $controller, $actionName, $parameters);
return $returnValue;
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Render this taskbar view
* @param boolean $return true to return the rendered view, false to send it to the client
* @return mixed null when provided $return is set to true; the rendered output when the provided $return is set to false
*/
public function render($return = true)
{
$request = Zibo::getInstance()->getRequest();
if (!$request) {
return;
}
$baseUrl = $request->getBaseUrl() . Request::QUERY_SEPARATOR;
$renderedPanels = array();
$notificationPanels = $this->taskbar->getNotificationPanels();
foreach ($notificationPanels as $panel) {
$renderedPanels[] = $this->renderView($panel);
}
$applicationsMenu = $this->taskbar->getApplicationsMenu();
$applicationsMenu->setBaseUrl($baseUrl);
$settingsMenu = $this->taskbar->getSettingsMenu();
$settingsMenu->setBaseUrl($baseUrl);
$settingsMenu->orderItems();
$this->set('applicationsMenu', $applicationsMenu);
$this->set('settingsMenu', $settingsMenu);
$this->set('notificationPanels', array_reverse($renderedPanels));
$this->set('title', $this->taskbar->getTitle());
$this->addStyle(self::STYLE_TASKBAR);
$this->addJavascript(self::SCRIPT_CLICKMENU);
$this->addInlineJavascript("\$('#taskbarApplications').clickMenu({start: 'left'}); \n \t\t\t\t" . "\$('#taskbarSettings').clickMenu({start: 'right'});");
return parent::render($return);
}
作者:BGCX26
项目:zibo-svn-to-gi
public function tearDown()
{
try {
Reflection::setProperty(Zibo::getInstance(), 'instance', null);
} catch (ZiboException $e) {
}
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Gets the base URL
* @return string
*/
protected function getBaseUrl()
{
if ($this->baseUrl) {
return $this->baseUrl;
}
return $this->baseUrl = Zibo::getInstance()->getRequest()->getBaseUrl();
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Executes the callback in a different thread. All arguments to this method will be passed on to the callback.
*
* The callback will be invoked but the script will not wait for it to finish.
* @return null
*/
public function run()
{
$pid = @pcntl_fork();
if ($pid == -1) {
throw new ZiboException('Could not run the thread: unable to fork the callback');
}
if ($pid) {
// parent process code
$this->pid = $pid;
} else {
// child process code
pcntl_signal(SIGTERM, array($this, 'signalHandler'));
try {
$this->callback->invokeWithArrayArguments(func_get_args());
} catch (Exception $exception) {
$message = $exception->getMessage();
if (!$message) {
$message = get_class($exception);
}
Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $message, $exception->getTraceAsString(), 1);
echo $message . "\n";
echo $exception->getTraceAsString();
}
exit;
}
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Action to view and change the profile
* @return null
*/
public function indexAction()
{
$user = SecurityManager::getInstance()->getUser();
if (!$user) {
throw new UnauthorizedException();
}
$form = new ProfileForm($this->request->getBasePath(), $user);
$form->addHook(new AccountProfileHook());
Zibo::getInstance()->runEvent(self::EVENT_PREPARE_FORM, $form);
if ($form->isSubmitted()) {
try {
$form->validate();
$form->processSubmit($this);
if (!$this->response->getView() && !$this->response->willRedirect()) {
$this->response->setRedirect($this->request->getBasePath());
}
return;
} catch (ValidationException $exception) {
$form->setValidationException($exception);
}
}
$translator = $this->getTranslator();
$view = new ProfileView($form);
$view->setPageTitle($translator->translate(self::TRANSLATION_TITLE));
$this->response->setView($view);
}
作者:BGCX26
项目:zibo-svn-to-gi
function smarty_function_image($params, &$smarty)
{
try {
if (empty($params['src'])) {
throw new Exception('No src parameter provided for the image');
}
$src = $params['src'];
unset($params['src']);
$image = new Image($src);
if (!empty($params['thumbnail'])) {
if (empty($params['width'])) {
throw new Exception('No width parameter provided for the thumbnailer');
}
if (empty($params['height'])) {
throw new Exception('No height parameter provided for the thumbnailer');
}
$image->setThumbnailer($params['thumbnail'], $params['width'], $params['height']);
unset($params['thumbnail']);
unset($params['width']);
unset($params['height']);
}
foreach ($params as $key => $value) {
$image->setAttribute($key, $value);
}
$html = $image->getHtml();
} catch (Exception $exception) {
Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1);
$html = '<span class="red" style="color: red;">Could not load image: ' . $exception->getMessage() . '</span>';
}
return $html;
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Action to ask for extra information and to send the error report
* @return null
*/
public function indexAction()
{
$zibo = Zibo::getInstance();
$session = Session::getInstance();
$recipient = $zibo->getConfigValue(Module::CONFIG_MAIL_RECIPIENT);
$subject = $zibo->getConfigValue(Module::CONFIG_MAIL_SUBJECT);
$report = $session->get(Module::SESSION_REPORT);
if (!$report || !$recipient) {
$this->response->setRedirect($this->request->getBaseUrl());
return;
}
$form = new ReportForm($this->request->getBasePath());
if ($form->isSubmitted()) {
$comment = $form->getComment();
if ($comment) {
$report .= "\n\nComment:\n" . $comment;
}
if (!$subject) {
list($subject, $null) = explode("\n", $report, 2);
}
$mail = new Message();
$mail->setTo($recipient);
$mail->setSubject($subject);
$mail->setMessage($report);
$mail->send();
$session->set(Module::SESSION_REPORT);
$this->addInformation(self::TRANSLATION_MAIL_SENT);
$this->response->setRedirect($this->request->getBaseUrl());
return;
}
$view = new ReportView($form, $report);
$this->response->setView($view);
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Loads the archive types from the Zibo configuration
* @return null
*/
private function loadTypes(Zibo $zibo)
{
$this->types = array();
$types = $zibo->getConfigValue(self::CONFIG_TYPES, array());
foreach ($types as $typeName => $className) {
$this->register($typeName, $className);
}
}
作者:BGCX26
项目:zibo-svn-to-gi
private function loadListeners(Zibo $zibo)
{
$config = $zibo->getConfigValue(self::CONFIG_LOG);
if (isset($config[self::CONFIG_LISTENER])) {
unset($config[self::CONFIG_LISTENER]);
}
if (isset($config[self::CONFIG_FILTER])) {
unset($config[self::CONFIG_FILTER]);
}
$listenerFactory = new LogListenerFactory($zibo);
foreach ($config as $name => $parameters) {
$listener = $listenerFactory->createListener($name);
if ($listener != null) {
$this->log->addLogListener($listener);
}
}
}
作者:BGCX26
项目:zibo-svn-to-gi
public function tearDown()
{
Reflection::setProperty(Zibo::getInstance(), 'instance', null);
if (file_exists('application/config/modules.temp.xml')) {
unlink('application/config/modules.temp.xml');
}
$this->tearDownApplication();
}
作者:BGCX26
项目:zibo-svn-to-gi
protected function tearDown()
{
$this->tearDownApplication();
try {
Reflection::setProperty(Zibo::getInstance(), 'instance', null);
} catch (ZiboException $e) {
}
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Loads the defined modules from the Zibo Configuration
* @param zibo\core\Zibo $zibo Instance of Zibo
* @return array Array with the defined modules
* @throws zibo\ZiboException when a module could not be created
* @see Module
* @see CONFIG_MODULE
*/
public function loadModules(Zibo $zibo)
{
$configModules = $zibo->getConfigValue(self::CONFIG_MODULE);
if (!$configModules) {
return array();
}
$objectFactory = new ObjectFactory();
$modules = array();
$configModules = Config::parseConfigTree($configModules);
foreach ($configModules as $configKey => $moduleClass) {
try {
$modules[] = $objectFactory->create($moduleClass, self::INTERFACE_MODULE);
} catch (ZiboException $exception) {
throw new ZiboException('Could not create ' . $moduleClass . ' from the ' . $configKey . ' configuration key', 0, $exception);
}
}
return $modules;
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Gets the temporary directory for the installation process
* @param string $path The path in the temporary directory
* @return zibo\library\filesystem\File
*/
public static function getTempDirectory($path = null)
{
$rootDirectory = Zibo::getInstance()->getRootPath();
$rootDirectory = $rootDirectory->getPath();
$path = 'zibo-' . substr(md5($rootDirectory), 0, 7) . ($path ? '/' . $path : '');
$temp = new File(sys_get_temp_dir(), $path);
$temp->create();
return $temp;
}
作者:BGCX26
项目:zibo-svn-to-gi
/**
* Initialize the orm module for the request, register orm event listeners
* @return null
*/
public function initialize()
{
$zibo = Zibo::getInstance();
$zibo->registerEventListener(Zibo::EVENT_CLEAR_CACHE, array($this, 'clearCache'));
$zibo->registerEventListener(Installer::EVENT_PRE_INSTALL_SCRIPT, array($this, 'defineModelsForInstalledModules'));
$zibo->registerEventListener(Installer::EVENT_POST_UNINSTALL_MODULE, array($this, 'deleteModelsForUninstalledModules'));
$zibo->registerEventListener(Dispatcher::EVENT_PRE_DISPATCH, array($this, 'prepareController'));
$zibo->registerEventListener(BaseView::EVENT_TASKBAR, array($this, 'prepareTaskbar'));
}