コード例 #1
0
 public function testToString()
 {
     $obj = new AgaviVirtualArrayPath("path");
     $this->assertEquals('path', $obj->__toString());
     $obj2 = new AgaviVirtualArrayPath("");
     $this->assertEquals(NULL, $obj2->__toString());
     $obj3 = new AgaviVirtualArrayPath(0);
     $this->assertEquals('0', $obj3->__toString());
     $obj = new AgaviVirtualArrayPath('one[two]');
     $this->assertEquals('one[two]', $obj->__toString());
     $obj = new AgaviVirtualArrayPath('one[two][three]');
     $this->assertEquals('one[two][three]', $obj->__toString());
 }
コード例 #2
0
 /**
  * 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);
     }
 }