当前位置: 首页>>代码示例>>PHP>>正文


PHP AssetCollection::setContent方法代码示例

本文整理汇总了PHP中Assetic\Asset\AssetCollection::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetCollection::setContent方法的具体用法?PHP AssetCollection::setContent怎么用?PHP AssetCollection::setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Assetic\Asset\AssetCollection的用法示例。


在下文中一共展示了AssetCollection::setContent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate

 /**
  * This method is used instead of APY\JsFormValidationBundle\Generator\FormValidationScriptGenerator::generate
  * to return inline client-side form validation javascript
  *
  * @param FormView $formView
  * @param boolean  $overwrite
  *
  * @return string
  */
 public function generate(FormView $formView, $overwrite = true)
 {
     $validationBundle = $this->getValidationBundle();
     $javascriptFramework = strtolower($this->container->getParameter('apy_js_form_validation.javascript_framework'));
     $template = $this->container->get('templating')->render("{$validationBundle}:Frameworks:JsFormValidation.js.{$javascriptFramework}.twig", $this->generateValidationParameters($formView));
     // Js compression
     if ($this->container->getParameter('apy_js_form_validation.yui_js')) {
         // Create asset and compress it
         $asset = new AssetCollection();
         $asset->setContent($template);
         return $asset->getContent();
     }
     return $template;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:23,代码来源:FormValidationScriptGenerator.php

示例2: testSetContent

 public function testSetContent()
 {
     $coll = new AssetCollection();
     $coll->setContent('asdf');
     $this->assertEquals('asdf', $coll->getContent(), '->setContent() sets the content');
 }
开发者ID:richardmiller,项目名称:assetic,代码行数:6,代码来源:AssetCollectionTest.php

示例3: generate


//.........这里部分代码省略.........
                 //Get Default group ?
                 $constraintsTarget = $constraintsTarget[0]->fields;
             }
         }
         if (!empty($constraintsTarget)) {
             // we look through each field of the form
             foreach ($formView->children as $formField) {
                 $names = array();
                 $names[] = $formField;
                 if (!empty($formField->children)) {
                     foreach ($formField->children as $nextLevelChildren) {
                         $names[] = $nextLevelChildren;
                     }
                 }
                 foreach ($names as $formFieldN) {
                     /* @var $formField \Symfony\Component\Form\FormView */
                     // Fields with property_path=false must be excluded from validation
                     if (isset($formFieldN->vars['property_path']) && $formFieldN->vars['property_path'] === false) {
                         continue;
                     }
                     //Setting "property_path" to "false" is deprecated since version 2.1 and will be removed in 2.3.
                     //Set "mapped" to "false" instead
                     if (isset($formFieldN->vars['mapped']) && $formFieldN->vars['mapped'] === false) {
                         continue;
                     }
                     // we look for constraints for the field
                     if (!isset($constraintsTarget[$formFieldN->vars['name']])) {
                         continue;
                     }
                     $constraintList = isset($entityName) ? $constraintsTarget[$formFieldN->vars['name']]->getConstraints() : $constraintsTarget[$formFieldN->vars['name']]->constraints;
                     //Adds entity level constraints that have been provided for this field
                     if (!empty($aConstraints[$formFieldN->vars['name']])) {
                         $constraintList = array_merge($constraintList, $aConstraints[$formFieldN->vars['name']]);
                     }
                     // we look through each field constraint
                     foreach ($constraintList as $constraint) {
                         $constraintName = end(explode(chr(92), get_class($constraint)));
                         $constraintProperties = get_object_vars($constraint);
                         // Groups are no longer needed
                         unset($constraintProperties['groups']);
                         if (!$fieldsConstraints->hasLibrary($constraintName)) {
                             $librairy = "APYJsFormValidationBundle:Constraints:{$constraintName}Validator.js.twig";
                             $fieldsConstraints->addLibrary($constraintName, $librairy);
                         }
                         $constraintParameters = array();
                         //We need to know entity class for the field which is applied by UniqueEntity constraint
                         if ($constraintName == 'UniqueEntity' && !empty($formFieldN->parent)) {
                             $entity = isset($formFieldN->parent->vars['value']) ? $formFieldN->parent->vars['value'] : null;
                             if (isset($formView->children[$this->getParameter('identifier_field')])) {
                                 $id = json_encode($formView->children[$this->getParameter('identifier_field')]->vars['id']);
                             } else {
                                 $id = json_encode($formFieldN->vars['id']);
                             }
                             $constraintParameters += array('entity:' . json_encode(get_class($entity)), 'identifier_field_id:' . $id);
                         }
                         foreach ($constraintProperties as $variable => $value) {
                             if (is_array($value)) {
                                 $value = json_encode($value);
                             } else {
                                 // regex
                                 if (stristr('pattern', $variable) === false) {
                                     $value = json_encode($value);
                                 }
                             }
                             $constraintParameters[] = "{$variable}:{$value}";
                         }
                         $fieldsConstraints->addFieldConstraint($formFieldN->vars['id'], array('name' => $constraintName, 'parameters' => '{' . join(', ', $constraintParameters) . '}'));
                     }
                 }
             }
         }
         // Dispatch JsfvEvents::postProcess event
         $postProcessEvent = new PostProcessEvent($formView, $fieldsConstraints);
         $dispatcher->dispatch(JsfvEvents::postProcess, $postProcessEvent);
         // Retrieve validation mode from configuration
         $check_modes = array('submit' => false, 'blur' => false, 'change' => false);
         foreach ($this->container->getParameter('apy_js_form_validation.check_modes') as $check_mode) {
             $check_modes[$check_mode] = true;
         }
         // Render the validation script
         $validation_bundle = $this->getValidationBundle();
         $javascript_framework = strtolower($this->container->getParameter('apy_js_form_validation.javascript_framework'));
         $dataTemplate = array('formName' => $formName, 'fieldConstraints' => $fieldsConstraints->getFieldsConstraints(), 'librairyCalls' => $fieldsConstraints->getLibraries(), 'check_modes' => $check_modes, 'getterHandlers' => $gettersLibraries->all(), 'gettersConstraints' => $aGetters, 'translation_group' => $this->container->getParameter('apy_js_form_validation.translation_group'));
         $template = $this->container->get('templating')->render("{$validation_bundle}:Frameworks:JsFormValidation.js.{$javascript_framework}.twig", $dataTemplate);
         // Create asset and compress it
         $asset = new AssetCollection();
         $asset->setContent($template);
         $asset->setTargetPath($scriptRealPath . $scriptFile);
         // Js compression
         if ($this->container->getParameter('apy_js_form_validation.yui_js')) {
             $yui = new JsCompressorFilter($this->container->getParameter('assetic.filter.yui_js.jar'), $this->container->getParameter('assetic.java.bin'));
             $yui->filterDump($asset);
         }
         $this->container->get('filesystem')->mkdir($scriptRealPath);
         if (false === @file_put_contents($asset->getTargetPath(), $asset->getContent())) {
             throw new \RuntimeException('Unable to write file ' . $asset->getTargetPath());
         }
     }
     return $this->container->get('templating.helper.assets')->getUrl($scriptPath . $scriptFile);
 }
开发者ID:ismailbaskin,项目名称:APYJsFormValidationBundle,代码行数:101,代码来源:FormValidationScriptGenerator.php


注:本文中的Assetic\Asset\AssetCollection::setContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。