Author: marijn
Date: 2010-01-12 15:48:07 +0100 (Tue, 12 Jan 2010)
New Revision: 26536
Modified:
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentForm.php
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentFormAbstract.php
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentSelectForm.php
Log:
[sfPaymentPlugin] Reorganized form class files.
Modified: plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentForm.php
===================================================================
--- plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentForm.php
2010-01-12 14:37:08 UTC (rev 26535)
+++ plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentForm.php
2010-01-12 14:48:07 UTC (rev 26536)
@@ -12,6 +12,29 @@
{
/**
+ * @var sfTransactionInterface The transaction object bound to the form.
+ */
+ protected $_transaction;
+
+ /**
+ * @var sfPaymentBasketInterface The basket containing all the objects on
sale.
+ */
+ protected $_basket;
+
+ /**
+ * Form setup.
+ *
+ * @return void
+ */
+ public function setup ()
+ {
+ $this->widgetSchema ['selection'] = new
sfWidgetFormChoice(array('expanded' => TRUE
+
,'multiple' => TRUE
+
,'choices' => NULL));
+ $this->validatorSchema['selection'] = new
sfValidatorChoice(array('choices' => NULL));
+ }
+
+ /**
* Process the payment selection.
*
* @return sfPaymentTransactionInterface
@@ -21,4 +44,157 @@
throw new BadMethodCallException('Not yet implemented');
}
+ /**
+ * {...@inheritdoc}
+ *
+ * @throws BadMethodCallException If no transaction was set for the form.
+ * @throws BadMethodCallException If no basket was set for the form.
+ */
+ public function bind (array $taintedValues = NULL, array $taintedFiles =
NULL)
+ {
+ if (NULL === $this->_transaction)
+ {
+ throw new BadMethodCallException(sprintf('Cannot bind the "%s" form to
the request because no transaction object was set', get_class($this)));
+ }
+ else if (NULL === $this->_basket)
+ {
+ throw new BadMethodCallException(sprintf('Cannot bind the "%s" form to
the request because no basket object was set', get_class($this)));
+ }
+
+ parent::bind($taintedValues, $taintedFiles);
+ }
+
+ /**
+ * Call this method to update the form defaults to reflect changes in the
+ * bound transaction and basket objects.
+ *
+ * @return sfPaymentForm The object itself to support a fluent interface.
+ */
+ public function updateFormDefaults ()
+ {
+ $defaults = array();
+
+ if ($this->hasBasket())
+ {
+ $defaults['selection'] =
$this->_updateChoiceField($this->widgetSchema['selection'],
$this->getBasket()->toArray());
+ }
+
+ $this->setDefaults($defaults);
+
+ return $this;
+ }
+
+ /**
+ * Set the transaction object.
+ *
+ * @param sfTransactionInterface $arg_transaction The transaction
object
+ * to use
+ *
+ * @return sfPaymentForm The object itself to
+ * support a fluent
+ * interface
+ */
+ public function setTransaction (sfPaymentTransactionInterface
$arg_transaction)
+ {
+ if ($this->hasTransaction())
+ {
+ throw new BadMethodCallException(sprintf('Cannot set the transaction
object on this "%s" form instance because one is already set.',
get_class($this)));
+ }
+
+ $this->_transaction = $arg_transaction;
+
+ return $this->updateFormDefaults();
+ }
+
+ /**
+ * Set the basket for the form.
+ *
+ * @param sfPaymentBasketInterface $arg_gateways The available gateways
+ *
+ * @return sfPaymentForm The object itself to
+ * support a fluent
+ * interface
+ */
+ public function setBasket (sfPaymentBasketInterface $arg_basket)
+ {
+ if ($this->hasBasket())
+ {
+ throw new BadMethodCallException(sprintf('Cannot set the basket object
on this "%s" form instance because one is already set.', get_class($this)));
+ }
+
+ $this->_basket = $arg_basket;
+
+ return $this->updateFormDefaults();
+ }
+
+ /**
+ * Get the bound transaction object.
+ *
+ * @throws BadMethodCallException When no transaction object is
+ * associated with the form
+ *
+ * @return sfPaymentTransactionInterface
+ */
+ public function getTransaction ()
+ {
+ if ( ! $this->hasTransaction())
+ {
+ throw new BadMethodCallException(sprintf('Cannot get transaction
object because there is no object bound to this "$s" form instance.',
get_class($this)));
+ }
+
+ return $this->_transaction;
+ }
+
+ /**
+ * Get the bound basket object.
+ *
+ * @throws BadMethodCallException When no basket object is associated
+ * with the form
+ *
+ * @return sfPaymentBasketInterface
+ */
+ public function getBasket ()
+ {
+ if ( ! $this->hasBasket())
+ {
+ throw new BadMethodCallException(sprintf('Cannot get basket object
because there is no object bound to this "$s" form instance.',
get_class($this)));
+ }
+
+ return $this->_basket;
+ }
+
+ /**
+ * Check if the form has a transaction object attached to it.
+ *
+ * @return boolean
+ */
+ public function hasTransaction ()
+ {
+ return NULL !== $this->_transaction;
+ }
+
+ /**
+ * Check if the form has a basket object attached to it.
+ *
+ * @return boolean
+ */
+ public function hasBasket ()
+ {
+ return NULL !== $this->_basket;
+ }
+
+ /**
+ * Update a choice field.
+ *
+ * @param sfWidgetFormChoice The widget to update
+ *
+ * @return array The keys of the fields that were added
+ */
+ protected function _updateChoiceField (sfWidgetFormChoice $arg_widget,
array $arg_choices)
+ {
+ $arg_widget->setOption('choices', $arg_choices);
+
+ return array_keys($arg_options);
+ }
+
}
\ No newline at end of file
Modified:
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentFormAbstract.php
===================================================================
---
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentFormAbstract.php
2010-01-12 14:37:08 UTC (rev 26535)
+++
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentFormAbstract.php
2010-01-12 14:48:07 UTC (rev 26536)
@@ -12,21 +12,11 @@
{
/**
- * @var sfTransactionInterface The transaction object bound to the form.
- */
- private $_transaction;
-
- /**
* @var array The available gateways.
*/
- private $_gateways;
+ protected $_gateways;
/**
- * @var sfPaymentBasketInterface The basket containing all the objects on
sale.
- */
- private $_basket;
-
- /**
* Payment form constructor.
*
* @param array $arg_gateways The available
gateways.
@@ -42,20 +32,17 @@
$this->_gateways = array_filter($arg_gateways, array($this,
'_filterGateway'));
$this->widgetSchema = new sfWidgetFormSchema(array('transaction_id' =>
new sfWidgetFormInputHidden()
- ,'gateway' =>
new sfWidgetFormChoice(array('choices' => $this->_gateways))
- ,'selection' =>
new sfWidgetFormChoice(array('expanded' => TRUE
-
,'multiple' => TRUE
-
,'choices' => NULL))
+ ,'gateway' =>
new sfWidgetFormInputHidden()
));
$this->validatorSchema = new sfValidatorSchema(array('transaction_id' =>
new sfValidatorPass()
,'gateway' =>
new sfValidatorChoice(array('choices' => array_keys($this->_gateways)))
- ,'selection' =>
new sfValidatorChoice(array('choices' => NULL))
));
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
$this->widgetSchema->setNameFormat('payment[%s]');
+
$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('sf_payment_form');
$this->setup();
$this->configure();
@@ -72,163 +59,13 @@
abstract public function process ();
/**
- * {...@inheritdoc}
- *
- * @throws BadMethodCallException If no transaction was set for the form.
- * @throws BadMethodCallException If no basket was set for the form.
- */
- public function bind (array $taintedValues = NULL, array $taintedFiles =
NULL)
- {
- if (NULL === $this->_transaction)
- {
- throw new BadMethodCallException(sprintf('Cannot bind the "%s" form to
the request because no transaction object was set', get_class($this)));
- }
- else if (NULL === $this->_basket)
- {
- throw new BadMethodCallException(sprintf('Cannot bind the "%s" form to
the request because no basket object was set', get_class($this)));
- }
-
- parent::bind($taintedValues, $taintedFiles);
- }
-
- /**
- * Call this method to update the form defaults to reflect changes in the
- * bound transaction and basket objects.
- *
- * @return sfPaymentFormAbstract The object itself to
support a fluent interface.
- */
- public function updateFormDefaults ()
- {
- $defaults = array();
-
- if ($this->hasBasket())
- {
- $defaults['selection'] =
$this->_updateChoiceField($this->widgetSchema['selection'],
$this->getBasket()->toArray());
- }
-
- $this->setDefaults($defaults);
-
- return $this;
- }
-
- /**
- * Set the transaction object.
- *
- * @param sfTransactionInterface $arg_transaction The transaction
object
- * to use
- *
- * @return sfPaymentFormAbstract The object itself to
- * support a fluent
- * interface
- */
- public function setTransaction (sfPaymentTransactionInterface
$arg_transaction)
- {
- if ($this->hasTransaction())
- {
- throw new BadMethodCallException(sprintf('Cannot set the transaction
object on this "%s" form instance because one is already set.',
get_class($this)));
- }
-
- $this->_transaction = $arg_transaction;
-
- return $this->updateFormDefaults();
- }
-
- /**
- * Set the basket for the form.
- *
- * @param sfPaymentBasketInterface $arg_gateways The available
gateways.
- *
- * @return sfPaymentFormAbstract The object itself to
support a fluent interface.
- */
- public function setBasket (sfPaymentBasketInterface $arg_basket)
- {
- if ($this->hasBasket())
- {
- throw new BadMethodCallException(sprintf('Cannot set the basket object
on this "%s" form instance because one is already set.', get_class($this)));
- }
-
- $this->_basket = $arg_basket;
-
- return $this->updateFormDefaults();
- }
-
- /**
- * Get the bound transaction object.
- *
- * @throws BadMethodCallException When no transaction object is
associated with the form.
- *
- * @return sfPaymentTransactionInterface
- */
- public function getTransaction ()
- {
- if ( ! $this->hasTransaction())
- {
- throw new BadMethodCallException(sprintf('Cannot get transaction
object because there is no object bound to this "$s" form instance.',
get_class($this)));
- }
-
- return $this->_transaction;
- }
-
- /**
- * Get the bound basket object.
- *
- * @throws BadMethodCallException When no basket object is associated
with the form.
- *
- * @return sfPaymentBasketInterface
- */
- public function getBasket ()
- {
- if ( ! $this->hasBasket())
- {
- throw new BadMethodCallException(sprintf('Cannot get basket object
because there is no object bound to this "$s" form instance.',
get_class($this)));
- }
-
- return $this->_basket;
- }
-
- /**
- * Check if the form has a transaction object attached to it.
- *
- * @return boolean
- */
- public function hasTransaction ()
- {
- return NULL !== $this->_transaction;
- }
-
- /**
- * Check if the form has a basket object attached to it.
- *
- * @return boolean
- */
- public function hasBasket ()
- {
- return NULL !== $this->_basket;
- }
-
- /**
- * Update a choice field.
- *
- * @param sfWidgetFormChoice The widget to update
- *
- * @return array The keys of the fields that were added
- */
- private function _updateChoiceField (sfWidgetFormChoice $arg_widget, array
$arg_choices)
- {
- $arg_widget->setOption('choices', $arg_choices);
-
- return array_keys($arg_options);
- }
-
-
- /**
* Filter the gateways.
*
* @param sfTransactionGatewayInterface $arg_gateway A gateway
implementation.
*
* @return boolean
*/
- private function _filterGateway (sfPaymentTransactionGatewayInterface
$arg_gateway = NULL)
+ protected function _filterGateway (sfPaymentTransactionGatewayInterface
$arg_gateway = NULL)
{
return NULL !== $arg_gateway && $arg_gateway->isEnabled();
}
Modified:
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentSelectForm.php
===================================================================
---
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentSelectForm.php
2010-01-12 14:37:08 UTC (rev 26535)
+++
plugins/sfPaymentPlugin/branches/1.2-marijn/lib/form/sfPaymentSelectForm.php
2010-01-12 14:48:07 UTC (rev 26536)
@@ -12,13 +12,30 @@
{
/**
+ * Form setup.
+ *
+ * @return void
+ */
+ public function setup ()
+ {
+ $this->widgetSchema ['gateway'] = new
sfWidgetFormChoice(array('choices' => $this->_gateways));;
+ $this->validatorSchema['gateway'] = new
sfValidatorChoice(array('choices' => array_keys($this->_gateways)));
+ }
+
+ /**
* Process the gateway selection.
*
* @return sfPaymentTransactionInterface
*/
public function process ()
{
- throw new BadMethodCallException('Not yet implemented');
+ if ( ! $this->isValid())
+ {
+ throw $this->errorSchema;
+ }
+
+ return $this->_gateways[$this->getValue('gateway')]
+ ->getTransaction();
}
}
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.