예제 #1
0
 function __construct()
 {
     parent::__construct();
     $this->setReversible(true);
 }
예제 #2
0
 /**
  * Returns the value determined by the binding.
  *
  * @return mixed The value to use as determined by resolving the binding.
  * @throws Exception under various circumstances if the value cannot be determined.
  */
 final function valueForBinding($prop, $binding)
 {
     $exposedBindings = $this->exposedBindings();
     // Get a list of all options, coalesced with default value from the binding setup for this property.
     // the lack of documenting (ie exposing) a binding setup should simply assume that there are no options.
     // @todo can this block be relplaced with $binding->coalescedOptions()?
     $optionDefaults = array();
     $optionDefaults = $binding->bindingSetup()->options();
     $coalescedOptions = array_merge($optionDefaults, $binding->options());
     try {
         // get original value
         if (strpos($binding->bindToKeyPath(), '::') === false) {
             $boundValue = $binding->bindToObject()->valueForKeyPath($binding->bindToKeyPath());
         } else {
             $boundValue = $binding->bindToObject()->valueForStaticKeyPath($binding->bindToKeyPath());
         }
     } catch (WFUndefinedKeyException $e) {
         if ($binding->raisesForNotApplicableKeys()) {
             throw $e;
         }
         $func = WFFunction::create('return "undefined key: {$binding->bindToKeyPath()}, substituting " . WFPrettyPrint($binding->notApplicablePlaceholder());')->withArguments('binding')->curry($binding);
         WFLog::log($func, WFLog::TRACE_LOG);
         $boundValue = $binding->notApplicablePlaceholder();
     }
     // let class apply options to value
     $this->processBindingOptions($prop, $coalescedOptions, $boundValue);
     // process value transformer
     if ($binding->valueTransformerName()) {
         $func = WFFunction::create('return "Transforming value " . WFPrettyPrint($boundValue) . " with " . $binding->valueTransformerName();')->withArguments('boundValue', 'binding')->curry($boundValue, $binding);
         WFLog::log($func, WFLog::TRACE_LOG);
         $vt = WFValueTransformer::valueTransformerForName($binding->valueTransformerName());
         $boundValue = $vt->transformedValue($boundValue);
         $func = WFFunction::create('return "Transformed value: " . WFPrettyPrint($boundValue);')->withArguments('boundValue')->curry($boundValue);
         WFLog::log($func, WFLog::TRACE_LOG);
     }
     if ($binding->formatter()) {
         $func = WFFunction::create('return "Formatting value " . WFPrettyPrint($boundValue) . " with " . $binding->formatter();')->withArguments('boundValue', 'binding')->curry($boundValue, $binding);
         WFLog::log($func, WFLog::TRACE_LOG);
         $formatter = $this->page()->module()->valueForKey($binding->formatter());
         // automatically handle formatting of arrays of objects
         if (is_array($boundValue)) {
             // using foreach since for some f'd up reason array_walk($boundValue, array($formatter,"stringForValue")) didn't munge the values.
             foreach (array_keys($boundValue) as $k) {
                 $boundValue[$k] = $formatter->stringForValue($boundValue[$k]);
             }
         } else {
             $boundValue = $formatter->stringForValue($boundValue);
         }
         $func = WFFunction::create('return "Formatted value: " . WFPrettyPrint($boundValue);')->withArguments('boundValue')->curry($boundValue);
         WFLog::log($func, WFLog::TRACE_LOG);
     }
     $func = WFFunction::create('return "Using value " . WFPrettyPrint($boundValue) . " for binding " . $prop;')->withArguments('boundValue', 'prop')->curry($boundValue, $prop);
     WFLog::log($func, WFLog::TRACE_LOG);
     return $boundValue;
 }