Development

#481 ([PATCH] getRawObject method on sfOutputEscaperObjectDecorator)

You must first sign up to be able to contribute.

Ticket #481 (closed enhancement: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] getRawObject method on sfOutputEscaperObjectDecorator

Reported by: zorloc@imperium.org Assigned to:
Priority: major Milestone: 0.6.3
Component: Version: 0.6.2
Keywords: Cc:
Qualification:

Description

For checks it would be useful to run 'instanceof' calls on the object decorated by the sfOutputEscaperObjectDecorator. So it would work like:

<?php if ($state->getRawObject() instanceof DevState): ?>
<!-- content to insert -->
<?php endif; ?>

Change History

05/05/06 12:28:11 changed by Mike Squire

You should be able to do:

<?php if ($sf_data->getRaw('state') instanceof DevState?): ?> <!-- content to insert --> <?php endif; ?>

I'll leave the ticket open in case anyone has further comments on this. I think perhaps this is a (lack of) documentation issue (which I am working on - promise!)

05/05/06 23:57:11 changed by zorloc@imperium.org

Mike, your example works if it is an item in the array held by $sf_data. But if:

$dev = $sf_data['dev'];
$state = $dev->getDevState();

# Now what?

In this case I don't think there is a way to get the raw $state object, unless there is a get() method that knows what to do...

05/08/06 13:04:49 changed by Mike Squire

You do:

$dev = $sf_data['dev'];
$state = $dev->getDevState(ESC_RAW);

# $state is now the raw object

Or:

$dev = $sf_data->getRaw('dev');
$state = $dev->getDevState();

# Both $dev and $state are the original object

05/09/06 16:50:47 changed by fabien

  • milestone set to 0.6.3.

05/10/06 16:06:01 changed by Mike Squire

In that case, I suggest the following which adds the functionality for all decorated values (i.e. arrays as well as objects):

Index: lib/view/escaper/sfOutputEscaper.class.php
===================================================================
--- lib/view/escaper/sfOutputEscaper.class.php  (revision 1334)
+++ lib/view/escaper/sfOutputEscaper.class.php  (working copy)
@@ -114,6 +114,19 @@
     // it must be a resource; cannot escape that.
     throw new sfException(sprintf('Unable to escape value "%s"', print_r($value, true)));
   }
+
+  /**
+   * Return the raw value associated with this instance.
+   *
+   * Concrete instances of sfOutputEscaper classes decorate a value which is
+   * stored by the constructor. This returns that original, unescaped, value.
+   *
+   * @return mixed the original value used to construct the decorator
+   */
+  public function getRawValue()
+  {
+    return $this->value;
+  }
 }

 ?>
\ No newline at end of file

05/10/06 18:25:34 changed by

  • summary changed from getRawObject method on sfOutputEscaperObjectDecorator to [PATCH] getRawObject method on sfOutputEscaperObjectDecorator.

06/09/06 15:39:30 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

r 1411