Development

Changeset 11358 for branches/dwhittle

You must first sign up to be able to contribute.

Show
Ignore:
Timestamp:
09/07/08 03:19:02 (3 months ago)
Author:
dwhittle
Message:

dwhittle: merged changes to branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dwhittle/1.1/lib/task/sfBaseTask.class.php

    r9683 r11358  
    2727  protected function doRun(sfCommandManager $commandManager, $options) 
    2828  { 
     29    $this->dispatcher->filter(new sfEvent($this, 'command.filter_options', array('command_manager' => $commandManager)), $options); 
     30 
    2931    $this->process($commandManager, $options); 
     32 
     33    $event = new sfEvent($this, 'command.pre_command', array('arguments' => $commandManager->getArgumentValues(), 'options' => $commandManager->getOptionValues())); 
     34    $this->dispatcher->notifyUntil($event); 
     35    if ($event->isProcessed()) 
     36    { 
     37      return $this->getReturnValue(); 
     38    } 
    3039 
    3140    $this->checkProjectExists(); 
     
    6675    } 
    6776 
    68     return $this->execute($commandManager->getArgumentValues(), $commandManager->getOptionValues()); 
     77    $ret = $this->execute($commandManager->getArgumentValues(), $commandManager->getOptionValues()); 
     78 
     79    $this->dispatcher->notify(new sfEvent($this, 'command.post_command')); 
     80 
     81    return $ret; 
    6982  } 
    7083 
  • branches/dwhittle/1.2/UPGRADE_TO_1_2

    r11335 r11358  
    6868      <!-- // ... --> 
    6969    </form> 
     70 
     71The `form_tag()` helper has been updated to automatically generate the hidden 
     72tag for methods different form `GET` and `POST`. So, the opening `form` tag 
     73from the code above can be generated by using the `form_tag()` helper like this: 
     74 
     75    [php] 
     76    <?php echo form_tag('#', array('method' => 'PUT')) ?> 
     77 
     78Forms 
     79----- 
     80 
     81The new `sfForm::renderFormTag()` method generatess the opening 
     82`form` tag for the current form. It also adds the `enctype` 
     83attribute if the form needs to be multipart and adds a 
     84hidden tag if the form method is not `GET` or `POST`: 
     85 
     86    [php] 
     87    <?php echo $form->renderFormTag('@article_update', array('method' => 'PUT')) ?> 
     88 
     89The `sfFormPropel` class overrides `renderFormTag()` to automatically change 
     90the HTTP method based on the related object: if the object is new, the method 
     91will be `POST`, and if the object already exists, the method will be `PUT`. 
    7092 
    7193Response 
     
    452474                         confirmed, false otherwise 
    453475 
     476The `propel:generate-crud` has been renamed to `propel:generate-module`. The old 
     477task name is still available as an alias. 
     478 
    454479Routing 
    455480------- 
     
    564589    echo url_for('@articles?page=2'); 
    565590    // /articles?page=2 
     591 
     592URL helpers 
     593----------- 
     594 
     595If you want to create a link to a resource that must be submitted with the 
     596`POST`, `PUT`, or `DELETE` HTTP method, the `link_to()` helper can convert 
     597a link to a form if you pass the `method` option: 
     598 
     599    [php] 
     600    <?php echo link_to('@article_delete?id=1', array('method' => 'delete')) ?> 
     601 
     602The old `post` option is still valid but deprecated: 
     603 
     604    [php] 
     605    // is deprecated 
     606    <?php echo link_to('@some_route', array('post' => true)) ?> 
     607 
     608    // and equivalent to 
     609    <?php echo link_to('@some_route', array('method' => 'post')) ?> 
  • branches/dwhittle/1.2/lib/command/sfCommandApplication.class.php

    r9720 r11358  
    474474 
    475475    $abbrev = $this->getAbbreviations($aliases); 
    476     if (!isset($abbrev[$name])) 
    477     { 
    478       throw new sfCommandException(sprintf('Task "%s" is not defined.', $name)); 
    479     } 
    480     else if (count($abbrev[$name]) > 1) 
    481     { 
    482       throw new sfCommandException(sprintf('Task "%s" is ambiguous (%s).', $name, implode(', ', $abbrev[$name]))); 
     476    $fullName = $namespace ? $namespace.':'.$name : $name; 
     477    if (!isset($abbrev[$fullName])) 
     478    { 
     479      throw new sfCommandException(sprintf('Task "%s" is not defined.', $fullName)); 
     480    } 
     481    else if (count($abbrev[$fullName]) > 1) 
     482    { 
     483      throw new sfCommandException(sprintf('Task "%s" is ambiguous (%s).', $fullName, implode(', ', $abbrev[$fullName]))); 
    483484    } 
    484485    else 
    485486    { 
    486       return $this->getTask($abbrev[$name][0]); 
     487      return $this->getTask($abbrev[$fullName][0]); 
    487488    } 
    488489  } 
  • branches/dwhittle/1.2/lib/form/sfForm.class.php

    r9944 r11358  
    685685  } 
    686686 
     687  /** 
     688   * Renders the form tag. 
     689   * 
     690   * This methods only renders the opening form tag. 
     691   * You need to close it after the form rendering. 
     692   * 
     693   * This method takes into account the multipart widgets 
     694   * and converts PUT and DELETE methods to a hidden field 
     695   * for later processing. 
     696   * 
     697   * @param  string $url         The URL for the action 
     698   * @param  array  $attributes  An array of HTML attributes 
     699   * 
     700   * @return string An HTML representation of the opening form tag 
     701   */ 
     702  public function renderFormTag($url, array $attributes = array()) 
     703  { 
     704    $attributes['action'] = $url; 
     705    $attributes['method'] = isset($attributes['method']) ? $attributes['method'] : 'POST'; 
     706    if ($this->isMultipart()) 
     707    { 
     708      $attributes['enctype'] = 'multipart/form-data'; 
     709    } 
     710 
     711    $html = ''; 
     712    if (!in_array($attributes['method'], array('GET', 'POST'))) 
     713    { 
     714      $html = $this->getWidgetSchema()->renderTag('input', array('type' => 'hidden', 'name' => 'sf_method', 'value' => $attributes['method'], 'id' => false)); 
     715      $attributes['method'] = 'POST'; 
     716    } 
     717 
     718    return sprintf('<form%s>', $this->getWidgetSchema()->attributesToHtml($attributes)).$html; 
     719  } 
     720 
    687721  public function resetFormFields() 
    688722  { 
  • branches/dwhittle/1.2/lib/generator/sfAdminGenerator.class.php

    r11183 r11358  
    2727{ 
    2828  protected 
     29    $formObject = null, 
    2930    $fields = array(); 
    3031 
     
    718719  public function getFormObject() 
    719720  { 
    720     $class = $this->getClassName().'Form'; 
    721  
    722     return new $class(); 
     721    if (is_null($this->formObject)) 
     722    { 
     723      $class = $this->getFormClassName(); 
     724 
     725      $this->formObject = new $class(); 
     726    } 
     727 
     728    return $this->formObject; 
     729  } 
     730 
     731  /** 
     732   * Gets the form class name 
     733   * 
     734   * @return string The form class name associated with this generator 
     735   */ 
     736  public function getFormClassName() 
     737  { 
     738    return isset($this->params['form_class']) ? $this->params['form_class'] : $this->getClassName().'Form'; 
     739  } 
     740 
     741  public function getFormParameterName() 
     742  { 
     743    return str_replace('[%s]', '', $this->getFormObject()->getWidgetSchema()->getNameFormat()); 
    723744  } 
    724745 
     
    777798 
    778799    return $last; 
     800  } 
     801 
     802  /** 
     803   * Gets the HTML to add to the form tag if the form is multipart. 
     804   * 
     805   * @return string 
     806   */ 
     807  public function getFormMultipartHtml() 
     808  { 
     809    if (isset($this->params['non_verbose_templates']) && $this->params['non_verbose_templates']) 
     810    { 
     811      return '[?php $form->isMultipart() and print \' enctype="multipart/form-data"\' ?]'; 
     812    } 
     813    else 
     814    { 
     815      return $this->getFormObject()->isMultipart() ? ' enctype="multipart/form-data"' : ''; 
     816    } 
    779817  } 
    780818 
  • branches/dwhittle/1.2/lib/generator/sfCrudGenerator.class.php

    r11183 r11358  
    2424    $singularName  = '', 
    2525    $pluralName    = '', 
    26     $peerClassName = '', 
    2726    $map           = null, 
    2827    $tableMap      = null, 
     
    121120    foreach ($this->getPrimaryKey() as $pk) 
    122121    { 
    123       $name = sfInflector::underscore($pk->getPhpName()); 
    124 //      $params[] = sprintf("\$request->getParameter('%s', \$request->getParameter('%s'))", sprintf('%s[%s]', $prefix, $name), $name); 
    125       $params[] = sprintf("\$request->getParameter('%s')", $name); 
     122      $params[] = sprintf("\$request->getParameter('%s')", sfInflector::underscore($pk->getPhpName())); 
    126123    } 
    127124 
     
    201198  protected function setScaffoldingClassName($className) 
    202199  { 
    203     $this->singularName  = sfInflector::underscore($className); 
    204     $this->pluralName    = $this->singularName.'s'; 
    205     $this->className     = $className; 
    206     $this->peerClassName = $className.'Peer'; 
     200    $this->singularName = isset($this->params['singular']) ? $this->params['singular'] : sfInflector::underscore($className); 
     201    $this->pluralName   = isset($this->params['plural']) ? $this->params['plural'] : $this->singularName.'s'; 
     202    $this->className    = $className; 
    207203  } 
    208204 
     
    235231  { 
    236232    return $this->className; 
    237   } 
    238  
    239   /** 
    240    * Gets the Peer class name. 
    241    * 
    242    * @return string 
    243    */ 
    244   public function getPeerClassName() 
    245   { 
    246     return $this->peerClassName; 
    247233  } 
    248234 
  • branches/dwhittle/1.2/lib/helper/FormHelper.php

    r10995 r11358  
    125125 
    126126  $html_options = $options; 
    127   if (!isset($html_options['method'])) 
    128   { 
    129     $html_options['method'] = 'post'; 
    130   } 
     127 
     128  $html_options['method'] = isset($html_options['method']) ? strtoupper($html_options['method']) : 'POST'; 
    131129 
    132130  if (_get_option($html_options, 'multipart')) 
     
    137135  $html_options['action'] = url_for($url_for_options); 
    138136 
    139   return tag('form', $html_options, true); 
     137  $html = ''; 
     138  if (!in_array($html_options['method'], array('GET', 'POST'))) 
     139  { 
     140    $html = tag('input', array('type' => 'hidden', 'name' => 'sf_method', 'value' => $html_options['method'])); 
     141    $html_options['method'] = 'POST'; 
     142  } 
     143 
     144  return tag('form', $html_options, true).$html; 
    140145} 
    141146 
  • branches/dwhittle/1.2/lib/helper/UrlHelper.php

    r9325 r11358  
    6161 * - 'popup' - if set to true, the link opens a new browser window  
    6262 * - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form) 
    63  * 
    64  * <b>Note:</b> The 'popup' and 'post' options are not compatible with each other. 
     63 * - 'method' - if set to post, delete, or put, the link submits a request with the given HTTP method instead of GET (caution: do not use inside a form) 
     64 * 
     65 * <b>Note:</b> The 'popup', 'post', and 'method' options are not compatible with each other. 
    6566 * 
    6667 * <b>Examples:</b> 
     
    393394  unset($html_options['popup']); 
    394395 
    395   // post 
    396   $post = isset($html_options['post']) ? $html_options['post'] : ''
    397   unset($html_options['post']); 
     396  // method 
     397  $method = isset($html_options['method']) ? $html_options['method'] : (isset($html_options['post']) && $html_options['post'] ? 'post' : false)
     398  unset($html_options['post'], $html_options['method']); 
    398399 
    399400  $onclick = isset($html_options['onclick']) ? $html_options['onclick'] : ''; 
    400401 
    401   if ($popup && $post
    402   { 
    403     throw new sfConfigurationException('You can\'t use "popup" and "post" in the same link.'); 
     402  if ($popup && $method
     403  { 
     404    throw new sfConfigurationException('You can\'t use "popup", "method" and "post" in the same link.'); 
    404405  } 
    405406  else if ($confirm && $popup) 
     
    407408    $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $url).' };return false;'; 
    408409  } 
    409   else if ($confirm && $post
    410   { 
    411     $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._post_javascript_function().' };return false;'; 
     410  else if ($confirm && $method
     411  { 
     412    $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._method_javascript_function($method).' };return false;'; 
    412413  } 
    413414  else if ($confirm) 
     
    422423    } 
    423424  } 
    424   else if ($post
    425   { 
    426     $html_options['onclick'] = $onclick._post_javascript_function().'return false;'; 
     425  else if ($method
     426  { 
     427    $html_options['onclick'] = $onclick._method_javascript_function($method).'return false;'; 
    427428  } 
    428429  else if ($popup) 
     
    460461function _post_javascript_function() 
    461462{ 
    462   return "f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit();"; 
     463  return _method_javascript_function('POST'); 
     464
     465 
     466function _method_javascript_function($method) 
     467
     468  $function = "var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;"; 
     469 
     470  if ('post' != strtolower($method)) 
     471  { 
     472    $function .= "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); "; 
     473    $function .= sprintf("m.setAttribute('name', 'sf_method'); m.setAttribute('value', '%s'); f.appendChild(m);", strtoupper($method)); 
     474  } 
     475 
     476  $function .= "f.submit();"; 
     477 
     478  return $function; 
    463479} 
    464480 
  • branches/dwhittle/1.2/lib/request/sfWebRequest.class.php

    r11335 r11358  
    6868    $this->parameterHolder->add($this->postParameters); 
    6969 
    70     $this->fixParameters(); 
    71  
    7270    if (isset($_SERVER['REQUEST_METHOD'])) 
    7371    { 
     
    126124    $this->requestParameters = $this->parseRequestParameters(); 
    127125    $this->parameterHolder->add($this->requestParameters); 
     126 
     127    $this->fixParameters(); 
    128128  } 
    129129 
     
    818818  protected function fixParameters() 
    819819  { 
     820    // arguments that come from the routing 
     821    if ($this->getParameter('_arguments')) 
     822    { 
     823      $this->getAttributeHolder()->add($this->getParameter('_arguments')); 
     824      $this->getParameterHolder()->remove('_arguments'); 
     825    } 
     826 
    820827    // move symfony parameters to attributes (parameters prefixed with _sf_) 
    821828    foreach ($this->parameterHolder->getAll() as $key => $value) 
  • branches/dwhittle/1.2/lib/routing/sfPatternRouting.class.php

    r11318 r11358  
    2222{ 
    2323  protected 
    24     $currentRouteName       = null, 
    25     $currentInternalUri     = array(), 
    26     $currentRouteParameters = null, 
    27     $routes                 = array(), 
    28     $cacheData              = array(), 
    29     $cacheChanged           = false; 
     24    $currentRouteName   = null, 
     25    $currentInternalUri = array(), 
     26    $routes             = array(), 
     27    $cacheData          = array(), 
     28    $cacheChanged       = false; 
    3029 
    3130  /** 
     
    9998  public function getCurrentInternalUri($withRouteName = false) 
    10099  { 
    101     if (is_null($this->currentRouteName)) 
    102     { 
    103       return null; 
    104     } 
    105     else 
    106     { 
    107       return $this->currentInternalUri[$withRouteName ? 0 : 1]; 
    108     } 
     100    return is_null($this->currentRouteName) ? null : $this->currentInternalUri[$withRouteName ? 0 : 1]; 
    109101  } 
    110102 
     
    355347 
    356348    // store the route name 
    357     $this->currentRouteName       = $info['name']; 
    358     $this->currentRouteParameters = $info['parameters']; 
    359     $this->currentInternalUri     = array(); 
     349    $this->currentRouteName   = $info['name']; 
     350    $this->currentInternalUri = array(); 
    360351 
    361352    if ($this->options['logging']) 
     
    382373    $this->currentInternalUri = array($internalUri[0].$params, $internalUri[1].$params); 
    383374 
    384     return array_merge($this->currentRouteParameters, $info['extra_parameters']); 
     375    if ($info['extra_parameters']) 
     376    { 
     377      return array_merge($info['parameters'], array('_arguments' => $info['extra_parameters'])); 
     378    } 
     379    else 
     380    { 
     381      return $info['parameters']; 
     382    } 
    385383  } 
    386384 
  • branches/dwhittle/1.2/lib/task/sfBaseTask.class.php

    r11296 r11358  
    2727  protected function doRun(sfCommandManager $commandManager, $options) 
    2828  { 
     29    $this->dispatcher->filter(new sfEvent($this, 'command.filter_options', array('command_manager' => $commandManager)), $options); 
     30 
    2931    $this->process($commandManager, $options); 
     32 
     33    $event = new sfEvent($this, 'command.pre_command', array('arguments' => $commandManager->getArgumentValues(), 'options' => $commandManager->getOptionValues())); 
     34    $this->dispatcher->notifyUntil($event); 
     35    if ($event->isProcessed()) 
     36    { 
     37      return $this->getReturnValue(); 
     38    } 
    3039 
    3140    $this->checkProjectExists(); 
     
    8190    } 
    8291 
    83     return $this->execute($commandManager->getArgumentValues(), $commandManager->getOptionValues()); 
     92    $ret = $this->execute($commandManager->getArgumentValues(), $commandManager->getOptionValues()); 
     93 
     94    $this->dispatcher->notify(new sfEvent($this, 'command.post_command')); 
     95 
     96    return $ret; 
    8497  } 
    8598 
  • branches/dwhittle/1.2/lib/widget/sfWidget.class.php

    r10995 r11358  
    346346  protected function attributesToHtmlCallback($k, $v) 
    347347  { 
    348     return is_null($v) || '' === $v ? '' : sprintf(' %s="%s"', $k, $this->escapeOnce($v)); 
     348    return false === $v || is_null($v) || '' === $v ? '' : sprintf(' %s="%s"', $k, $this->escapeOnce($v)); 
    349349  } 
    350350} 
  • branches/dwhittle/1.2/test/other/tasksTest.php

    r11318 r11358  
    110110$t->ok(file_exists($c->tmp_dir.DS.'data'.DS.'database.sqlite'), '"propel:insert-sql" creates tables in the database'); 
    111111 
    112 $content = $c->execute_command('propel:generate-crud --generate-in-cache frontend articleInitCrud Article'); 
    113 $t->ok(file_exists($c->tmp_dir.DS.'apps'.DS.'frontend'.DS.'modules'.DS.'articleInitCrud'.DS.'config'.DS.'generator.yml'), '"propel:generate-crud" initializes a CRUD module'); 
     112$content = $c->execute_command('propel:generate-module --generate-in-cache frontend articleInitCrud Article'); 
     113$t->ok(file_exists($c->tmp_dir.DS.'apps'.DS.'frontend'.DS.'modules'.DS.'articleInitCrud'.DS.'config'.DS.'generator.yml'), '"propel:generate-module" initializes a CRUD module'); 
    114114 
    115115$content = $c->execute_command('propel:init-admin frontend articleInitAdmin Article'); 
  • branches/dwhittle/1.2/test/unit/form/sfFormTest.php

    r9501 r11358  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(99, new lime_output_color()); 
     13$t = new lime_test(102, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    532532$t->is_deeply(sfForm::convertFileInformation($expected), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention'); 
    533533 
     534// ->renderFormTag() 
     535$t->diag('->renderFormTag()'); 
     536$f = new FormTest(); 
     537$t->is($f->renderFormTag('/url'), '<form action="/url" method="POST">', '->renderFormTag() renders the form tag'); 
     538$t->is($f->renderFormTag('/url', array('method' => 'PUT')), '<form method="POST" action="/url"><input type="hidden" name="sf_method" value="PUT" />', '->renderFormTag() adds a hidden input tag if the method is not GET or POST'); 
     539$f->setWidgetSchema(new sfWidgetFormSchema(array('image' => new sfWidgetFormInputFile()))); 
     540$t->is($f->renderFormTag('/url'), '<form action="/url" method="POST" enctype="multipart/form-data">', '->renderFormTag() adds the enctype attribute if the form is multipart'); 
     541 
    534542// __clone() 
    535543$t->diag('__clone()'); 
  • branches/dwhittle/1.2/test/unit/helper/FormHelperTest.php

    r9336 r11358  
    4343} 
    4444 
    45 $t = new lime_test(94, new lime_output_color()); 
     45$t = new lime_test(95, new lime_output_color()); 
    4646 
    4747$context = sfContext::getInstance(array( 
     
    7373// form_tag() 
    7474$t->diag('form_tag()'); 
    75 $t->is(form_tag(), '<form method="post" action="module/action">', 'form_tag() creates a form tag'); 
    76  
    77 // options 
    78 $t->is(form_tag('', array('class' => 'foo')), '<form class="foo" method="post" action="module/action">', 'form_tag() takes an array of attribute options'); 
    79 $t->is(form_tag('', array('method' => 'get')), '<form method="get" action="module/action">', 'form_tag() takes a "method" as an option'); 
    80 $t->is(form_tag('', array('multipart' => true)), '<form method="post" enctype="multipart/form-data" action="module/action">', 'form_tag() takes a "multipart" boolean option'); 
     75$t->is(form_tag(), '<form method="POST" action="module/action">', 'form_tag() creates a form tag'); 
     76 
     77// options 
     78$t->is(form_tag('', array('class' => 'foo')), '<form class="foo" method="POST" action="module/action">', 'form_tag() takes an array of attribute options'); 
     79$t->is(form_tag('', array('method' => 'get')), '<form method="GET" action="module/action">', 'form_tag() takes a "method" as an option'); 
     80$t->is(form_tag('', array('multipart' => true)), '<form method="POST" enctype="multipart/form-data" action="module/action">', 'form_tag() takes a "multipart" boolean option'); 
     81$t->is(form_tag('', array('method' => 'put')), '<form method="POST" action="module/action"><input type="hidden" name="sf_method" value="PUT" />', 'form_tag() creates a hidden field for methods different from GET or POST'); 
    8182 
    8283// select_tag()