/**
  * Exports a value back into the request.
  *
  * Exports data into the request at the index given in the parameter
  * 'export'. If there is no such parameter, then the method returns
  * without exporting.
  *
  * Similar to getData() you should always use export() to submit data to
  * the request because it pays attention to paths and otherwise you could
  * overwrite stuff you don't want to.
  *
  * @param      mixed The value to be exported.
  * @param      string An optional name which should be used for exporting 
  *                    instead of the export parameter.
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 protected function export($value, $name = null)
 {
     if ($name === null) {
         $name = $this->getParameter('export');
     }
     if (!is_string($name) || $name === '') {
         return;
     }
     $paramType = $this->getParameter('source');
     $array =& $this->validationParameters->getAll($paramType);
     $currentParts = $this->curBase->getParts();
     if (count($currentParts) > 0 && strpos($name, '%') !== false) {
         // this is a validator which actually has a base (<arguments base="xx">) set
         // and the export name contains sprintf syntax
         $name = vsprintf($name, $currentParts);
     }
     // CAUTION
     // we had a feature here during development that would allow [] at the end to append values to an array
     // that would, however, mean that we have to cast the value to an array, and, either way, a user would be able to manipulate the keys
     // example: we export to foo[], and the user supplies ?foo[28] in the URL. that means our export will be in foo[29]. foo[28] will be removed by the validation, but the keys are still potentially harmful
     // that's why we decided to remove this again
     $cp = new AgaviVirtualArrayPath($name);
     $cp->setValue($array, $value);
     if ($this->parentContainer !== null) {
         // make sure the parameter doesn't get removed by the validation manager
         if (is_array($value)) {
             // for arrays all child elements need to be marked as not processed
             foreach (AgaviArrayPathDefinition::getFlatKeyNames($value) as $keyName) {
                 $this->parentContainer->addArgumentResult(new AgaviValidationArgument($cp->pushRetNew($keyName)->__toString(), $this->getParameter('source')), AgaviValidator::SUCCESS, $this);
             }
         }
         $this->parentContainer->addArgumentResult(new AgaviValidationArgument($cp->__toString(), $this->getParameter('source')), AgaviValidator::SUCCESS, $this);
     }
 }
 /**
  * Puts a list of tokens into the dependency cache.
  * 
  * @param      array  The list of new tokens.
  * @param      AgaviVirtualArrayPath The base path to which all tokens are 
  *                                   appended.
  * 
  * @author     Uwe Mesecke <*****@*****.**>
  * @since      0.11.0
  */
 public function addDependTokens(array $tokens, AgaviVirtualArrayPath $base)
 {
     $currentParts = $base->getParts();
     foreach ($tokens as $token) {
         if ($currentParts && strpos($token, '%') !== false) {
             // the depends attribute contains sprintf syntax
             $token = vsprintf($token, $currentParts);
         }
         $path = new AgaviVirtualArrayPath($token);
         $path->setValue($this->depData, true);
     }
 }
 /**
  * Puts a list of tokens into the dependency cache.
  * 
  * @param      array  The list of new tokens.
  * @param      AgaviVirtualArrayPath The base path to which all tokens are 
  *                                   appended.
  * 
  * @author     Uwe Mesecke <*****@*****.**>
  * @since      0.11.0
  */
 public function addDependTokens(array $tokens, AgaviVirtualArrayPath $base)
 {
     foreach ($tokens as $token) {
         $base->setValueByChildPath($token, $this->depData, true);
     }
 }
 public function testHasValueByChildPath()
 {
     $array = array("path" => array("jump" => array("sip" => "whatever")));
     $obj = new AgaviVirtualArrayPath("path[jump]");
     $this->assertTrue($obj->hasValueByChildPath('[sip]', $array));
     $obj2 = new AgaviVirtualArrayPath("path");
     $this->assertTrue($obj2->hasValueByChildPath("", $array));
     // true
     $obj3 = new AgaviVirtualArrayPath("path");
     $this->assertTrue($obj3->hasValueByChildPath("[jump]", $array));
     // true
     $obj4 = new AgaviVirtualArrayPath("path[foo]");
     $this->assertFalse($obj4->hasValueByChildPath("foo", $array));
     // false
     $obj5 = new AgaviVirtualArrayPath("");
     $this->assertTrue($obj5->hasValueByChildPath("path", $array));
     // true
 }