Changeset 11358 for branches/dwhittle
- Timestamp:
- 09/07/08 03:19:02 (3 months ago)
- Files:
-
- branches/dwhittle/1.1/lib/task/sfBaseTask.class.php (modified) (2 diffs)
- branches/dwhittle/1.2/UPGRADE_TO_1_2 (modified) (3 diffs)
- branches/dwhittle/1.2/lib/command/sfCommandApplication.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/form/sfForm.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/generator/sfAdminGenerator.class.php (modified) (3 diffs)
- branches/dwhittle/1.2/lib/generator/sfCrudGenerator.class.php (modified) (4 diffs)
- branches/dwhittle/1.2/lib/helper/FormHelper.php (modified) (2 diffs)
- branches/dwhittle/1.2/lib/helper/UrlHelper.php (modified) (5 diffs)
- branches/dwhittle/1.2/lib/request/sfWebRequest.class.php (modified) (3 diffs)
- branches/dwhittle/1.2/lib/routing/sfPatternRouting.class.php (modified) (4 diffs)
- branches/dwhittle/1.2/lib/task/sfBaseTask.class.php (modified) (2 diffs)
- branches/dwhittle/1.2/lib/widget/sfWidget.class.php (modified) (1 diff)
- branches/dwhittle/1.2/test/other/tasksTest.php (modified) (1 diff)
- branches/dwhittle/1.2/test/unit/form/sfFormTest.php (modified) (2 diffs)
- branches/dwhittle/1.2/test/unit/helper/FormHelperTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/1.1/lib/task/sfBaseTask.class.php
r9683 r11358 27 27 protected function doRun(sfCommandManager $commandManager, $options) 28 28 { 29 $this->dispatcher->filter(new sfEvent($this, 'command.filter_options', array('command_manager' => $commandManager)), $options); 30 29 31 $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 } 30 39 31 40 $this->checkProjectExists(); … … 66 75 } 67 76 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; 69 82 } 70 83 branches/dwhittle/1.2/UPGRADE_TO_1_2
r11335 r11358 68 68 <!-- // ... --> 69 69 </form> 70 71 The `form_tag()` helper has been updated to automatically generate the hidden 72 tag for methods different form `GET` and `POST`. So, the opening `form` tag 73 from 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 78 Forms 79 ----- 80 81 The new `sfForm::renderFormTag()` method generatess the opening 82 `form` tag for the current form. It also adds the `enctype` 83 attribute if the form needs to be multipart and adds a 84 hidden tag if the form method is not `GET` or `POST`: 85 86 [php] 87 <?php echo $form->renderFormTag('@article_update', array('method' => 'PUT')) ?> 88 89 The `sfFormPropel` class overrides `renderFormTag()` to automatically change 90 the HTTP method based on the related object: if the object is new, the method 91 will be `POST`, and if the object already exists, the method will be `PUT`. 70 92 71 93 Response … … 452 474 confirmed, false otherwise 453 475 476 The `propel:generate-crud` has been renamed to `propel:generate-module`. The old 477 task name is still available as an alias. 478 454 479 Routing 455 480 ------- … … 564 589 echo url_for('@articles?page=2'); 565 590 // /articles?page=2 591 592 URL helpers 593 ----------- 594 595 If 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 597 a 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 602 The 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 474 474 475 475 $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]))); 483 484 } 484 485 else 485 486 { 486 return $this->getTask($abbrev[$ name][0]);487 return $this->getTask($abbrev[$fullName][0]); 487 488 } 488 489 } branches/dwhittle/1.2/lib/form/sfForm.class.php
r9944 r11358 685 685 } 686 686 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 687 721 public function resetFormFields() 688 722 { branches/dwhittle/1.2/lib/generator/sfAdminGenerator.class.php
r11183 r11358 27 27 { 28 28 protected 29 $formObject = null, 29 30 $fields = array(); 30 31 … … 718 719 public function getFormObject() 719 720 { 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()); 723 744 } 724 745 … … 777 798 778 799 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 } 779 817 } 780 818 branches/dwhittle/1.2/lib/generator/sfCrudGenerator.class.php
r11183 r11358 24 24 $singularName = '', 25 25 $pluralName = '', 26 $peerClassName = '',27 26 $map = null, 28 27 $tableMap = null, … … 121 120 foreach ($this->getPrimaryKey() as $pk) 122 121 { 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())); 126 123 } 127 124 … … 201 198 protected function setScaffoldingClassName($className) 202 199 { 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; 207 203 } 208 204 … … 235 231 { 236 232 return $this->className; 237 }238 239 /**240 * Gets the Peer class name.241 *242 * @return string243 */244 public function getPeerClassName()245 {246 return $this->peerClassName;247 233 } 248 234 branches/dwhittle/1.2/lib/helper/FormHelper.php
r10995 r11358 125 125 126 126 $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'; 131 129 132 130 if (_get_option($html_options, 'multipart')) … … 137 135 $html_options['action'] = url_for($url_for_options); 138 136 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; 140 145 } 141 146 branches/dwhittle/1.2/lib/helper/UrlHelper.php
r9325 r11358 61 61 * - 'popup' - if set to true, the link opens a new browser window 62 62 * - '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. 65 66 * 66 67 * <b>Examples:</b> … … 393 394 unset($html_options['popup']); 394 395 395 // post396 $ 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']); 398 399 399 400 $onclick = isset($html_options['onclick']) ? $html_options['onclick'] : ''; 400 401 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.'); 404 405 } 405 406 else if ($confirm && $popup) … … 407 408 $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $url).' };return false;'; 408 409 } 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;'; 412 413 } 413 414 else if ($confirm) … … 422 423 } 423 424 } 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;'; 427 428 } 428 429 else if ($popup) … … 460 461 function _post_javascript_function() 461 462 { 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 466 function _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; 463 479 } 464 480 branches/dwhittle/1.2/lib/request/sfWebRequest.class.php
r11335 r11358 68 68 $this->parameterHolder->add($this->postParameters); 69 69 70 $this->fixParameters();71 72 70 if (isset($_SERVER['REQUEST_METHOD'])) 73 71 { … … 126 124 $this->requestParameters = $this->parseRequestParameters(); 127 125 $this->parameterHolder->add($this->requestParameters); 126 127 $this->fixParameters(); 128 128 } 129 129 … … 818 818 protected function fixParameters() 819 819 { 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 820 827 // move symfony parameters to attributes (parameters prefixed with _sf_) 821 828 foreach ($this->parameterHolder->getAll() as $key => $value) branches/dwhittle/1.2/lib/routing/sfPatternRouting.class.php
r11318 r11358 22 22 { 23 23 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; 30 29 31 30 /** … … 99 98 public function getCurrentInternalUri($withRouteName = false) 100 99 { 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]; 109 101 } 110 102 … … 355 347 356 348 // 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(); 360 351 361 352 if ($this->options['logging']) … … 382 373 $this->currentInternalUri = array($internalUri[0].$params, $internalUri[1].$params); 383 374 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 } 385 383 } 386 384 branches/dwhittle/1.2/lib/task/sfBaseTask.class.php
r11296 r11358 27 27 protected function doRun(sfCommandManager $commandManager, $options) 28 28 { 29 $this->dispatcher->filter(new sfEvent($this, 'command.filter_options', array('command_manager' => $commandManager)), $options); 30 29 31 $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 } 30 39 31 40 $this->checkProjectExists(); … … 81 90 } 82 91 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; 84 97 } 85 98 branches/dwhittle/1.2/lib/widget/sfWidget.class.php
r10995 r11358 346 346 protected function attributesToHtmlCallback($k, $v) 347 347 { 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)); 349 349 } 350 350 } branches/dwhittle/1.2/test/other/tasksTest.php
r11318 r11358 110 110 $t->ok(file_exists($c->tmp_dir.DS.'data'.DS.'database.sqlite'), '"propel:insert-sql" creates tables in the database'); 111 111 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'); 114 114 115 115 $content = $c->execute_command('propel:init-admin frontend articleInitAdmin Article'); branches/dwhittle/1.2/test/unit/form/sfFormTest.php
r9501 r11358 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test( 99, new lime_output_color());13 $t = new lime_test(102, new lime_output_color()); 14 14 15 15 class FormTest extends sfForm … … 532 532 $t->is_deeply(sfForm::convertFileInformation($expected), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention'); 533 533 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 534 542 // __clone() 535 543 $t->diag('__clone()'); branches/dwhittle/1.2/test/unit/helper/FormHelperTest.php
r9336 r11358 43 43 } 44 44 45 $t = new lime_test(9 4, new lime_output_color());45 $t = new lime_test(95, new lime_output_color()); 46 46 47 47 $context = sfContext::getInstance(array( … … 73 73 // form_tag() 74 74 $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'); 81 82 82 83 // select_tag()