svn: /pear2/sandbox/Pyrus_WebFrontend/trunk/ src/pear2/Pyrus/WebFrontend/ClassToTemplateMapper.php src/pear2/Pyrus/WebFrontend/Controller.php
src/pear2/Pyrus/WebFrontend/InstallPackage.php www/index.php www/templates/Exception.tpl.php www/templates/ExceptionMessage.tpl.php
www/templates/WebFrontend/Controller.tpl.php www/templates/WebFrontend/InstallPackage.tpl.php

From: Date: Tue, 23 Mar 2010 14:13:59 +0000
Subject: svn: /pear2/sandbox/Pyrus_WebFrontend/trunk/ src/pear2/Pyrus/WebFrontend/ClassToTemplateMapper.php src/pear2/Pyrus/WebFrontend/Controller.php
src/pear2/Pyrus/WebFrontend/InstallPackage.php www/index.php www/templates/Exception.tpl.php www/templates/ExceptionMessage.tpl.php
www/templates/WebFrontend/Controller.tpl.php www/templates/WebFrontend/InstallPackage.tpl.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-9320@lists.php.net to get a copy of this message
saltybeagle Tue, 23 Mar 2010 14:13:59 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=296672 Log: Add package install command. Get Exception handling under control. Show the actual tree of previous exceptions. Changed paths: A pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/ClassToTemplateMapper.php U pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/Controller.php A pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/InstallPackage.php U pear2/sandbox/Pyrus_WebFrontend/trunk/www/index.php A pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/Exception.tpl.php A pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/ExceptionMessage.tpl.php U pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/Controller.tpl.php A pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/InstallPackage.tpl.php Added: pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/ClassToTemplateMapper.php =================================================================== --- pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/ClassToTemplateMapper.php (rev 0) +++ pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/ClassToTemplateMapper.php 2010-03-23 14:13:59 UTC (rev 296672) @@ -0,0 +1,18 @@ +<?php +namespace pear2\Pyrus\WebFrontend; +class ClassToTemplateMapper extends \pear2\Templates\Savant\ClassToTemplateMapper +{ + function __construct($options = array()) + { + static::$classname_replacement = 'pear2\Pyrus\\'; + } + + function map($class) + { + if (false === strpos($class, 'Exception')) { + return parent::map($class); + } + + return 'Exception.tpl.php'; + } +} \ No newline at end of file Modified: pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/Controller.php =================================================================== --- pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/Controller.php 2010-03-23 14:09:07 UTC (rev 296671) +++ pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/Controller.php 2010-03-23 14:13:59 UTC (rev 296672) @@ -28,7 +28,8 @@ { public $view_map = array( 'index' => 'pear2\Pyrus\WebFrontend\Index', - 'list_packages' => 'pear2\Pyrus\WebFrontend\ListPackages' + 'list_packages' => 'pear2\Pyrus\WebFrontend\ListPackages', + 'install' => 'pear2\Pyrus\WebFrontend\InstallPackage' ); public $options = array('view'=>'index'); @@ -46,21 +47,20 @@ if (!empty($_POST)) { try { $this->handlePost(); - } catch(Exception $e) { + } catch(\Exception $e) { $this->actionable[] = $e; } } try { $this->run(); - } catch(Exception $e) { + } catch(\Exception $e) { $this->actionable[] = $e; } } function handlePost() { - $this->filterPostValues(); switch($_POST['_type']) { case '': break; Added: pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/InstallPackage.php =================================================================== --- pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/InstallPackage.php (rev 0) +++ pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/InstallPackage.php 2010-03-23 14:13:59 UTC (rev 296672) @@ -0,0 +1,36 @@ +<?php +namespace pear2\Pyrus\WebFrontend; +class InstallPackage +{ + function __construct($options) + { + if (isset($_POST)) { + $this->handlePost(); + } + } + + function handlePost() + { + if (isset($_POST['package'])) { + $current_state = Controller::getConfig()->preferred_state; + if (isset($_POST['stability'])) { + Controller::getConfig()->preferred_state = $_POST['stability']; + } + $this->install($_POST['package']); + Controller::getConfig()->preferred_state = $current_state; + } + } + + function install($name) + { + $package = new \pear2\Pyrus\Package($name); + try { + \pear2\Pyrus\Installer::begin(); + \pear2\Pyrus\Installer::prepare($package); + \pear2\Pyrus\Installer::commit(); + } catch (Exception $e) { + \pear2\Pyrus\Installer::rollback(); + throw new \Exception('Unable to install '.$name, $e); + } + } +} \ No newline at end of file Modified: pear2/sandbox/Pyrus_WebFrontend/trunk/www/index.php =================================================================== --- pear2/sandbox/Pyrus_WebFrontend/trunk/www/index.php 2010-03-23 14:09:07 UTC (rev 296671) +++ pear2/sandbox/Pyrus_WebFrontend/trunk/www/index.php 2010-03-23 14:13:59 UTC (rev 296672) @@ -12,12 +12,12 @@ set_include_path(dirname(__DIR__).'/src'); -pear2\Pyrus\WebFrontend\Controller::setConfigDir('/Users/bbieber/pyrus'); +pear2\Pyrus\WebFrontend\Controller::setConfigDir('/tmp/pyrustest'); $controller = new pear2\Pyrus\WebFrontend\Controller($_GET); -pear2\Templates\Savant\ClassToTemplateMapper::$classname_replacement = 'pear2\Pyrus\\'; $savant = new pear2\Templates\Savant\Main(); +$savant->setClassToTemplateMapper(new pear2\Pyrus\WebFrontend\ClassToTemplateMapper); $savant->setTemplatePath(__DIR__.'/templates'); $savant->setEscape('htmlspecialchars'); $savant->setFilters(array($controller, 'postRender')); Added: pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/Exception.tpl.php =================================================================== --- pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/Exception.tpl.php (rev 0) +++ pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/Exception.tpl.php 2010-03-23 14:13:59 UTC (rev 296672) @@ -0,0 +1,3 @@ +<?php $parent->context->page_title = 'Error'; ?> +<h2>Eh, sorry - that didn't work.</h2> +<?php echo $savant->render($context, 'ExceptionMessage.tpl.php'); ?> \ No newline at end of file Added: pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/ExceptionMessage.tpl.php =================================================================== --- pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/ExceptionMessage.tpl.php (rev 0) +++ pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/ExceptionMessage.tpl.php 2010-03-23 14:13:59 UTC (rev 296672) @@ -0,0 +1,10 @@ +<?php +echo '<ul><li>'.$context->getMessage(); +foreach ($context as $error) { + echo $savant->render($error, 'ExceptionMessage.tpl.php'); +} +if ($context = $context->getPrevious()) { + echo $savant->render($context, 'ExceptionMessage.tpl.php'); +} +echo '</li>'; +echo '</ul>'; \ No newline at end of file Modified: pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/Controller.tpl.php =================================================================== --- pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/Controller.tpl.php 2010-03-23 14:09:07 UTC (rev 296671) +++ pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/Controller.tpl.php 2010-03-23 14:13:59 UTC (rev 296672) @@ -7,6 +7,7 @@ <li><a href="?view=index">Home</a></li> <li><a href="?view=list_packages">List Packages</a></li> <li><a href="?view=list_channels">List Channels</a></li> + <li><a href="?view=install">Install/Upgrade</a></li> </ul> <?php echo $savant->render($context->actionable); ?> </body> \ No newline at end of file Added: pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/InstallPackage.tpl.php =================================================================== --- pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/InstallPackage.tpl.php (rev 0) +++ pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/InstallPackage.tpl.php 2010-03-23 14:13:59 UTC (rev 296672) @@ -0,0 +1,15 @@ +<?php +$parent->context->page_title = 'Install Package'; +?> +<h2>Install Package</h2> +<form method="post" action="?view=install"> +<input name="_type" value="install" type="hidden" /> +<label>Package name (eg pear/Net_URL2):</label><input type="text" name="package" /> +<select name="stability"> + <option value="<?php echo pear2\Pyrus\WebFrontend\Controller::getConfig()->preferred_state; ?>"><?php echo pear2\Pyrus\WebFrontend\Controller::getConfig()->preferred_state; ?> (preferred state)</option> + <option value="alpha">alpha</option> + <option value="beta">beta</option> + <option value="stable">stable</option> +</select> +<input type="submit" value="Submit" /> +</form> \ No newline at end of file

« previous php.pear.core (#9320) next »