예제 #1
0
 /**
  * Removes keys that should not be public from a data seed array.
  * Renames keys to be underscored (like serializer does),
  *
  * @param array &$array
  * @param bool  $underscore
  *
  * @return array
  */
 public function mockSerialize(array $array, $underscore = false)
 {
     foreach ($array as $k => $v) {
         if (is_array($v)) {
             unset($array[$k]);
             $k = $underscore ? (string) String::create($k)->underscored() : $k;
             $array[$k] = $this->mockSerialize($v);
         }
     }
     foreach ($this->getPrivateFields() as $key) {
         if (array_key_exists($key, $array)) {
             unset($array[$key]);
         }
     }
     return $array;
 }
 /**
  * @todo Move into trait or dependency.
  * @param string $fileName
  */
 protected function updateDIFile($fileName)
 {
     $loaderInput = PHP_EOL . "\t\t\$xmlLoader = new Loader\\XmlFileLoader(\$container, new FileLocator(__DIR__ . '/../Resources/config'));";
     $toInput = PHP_EOL . "\t\t\$xmlLoader->load('managers.xml');" . PHP_EOL . "\t";
     $text = file_get_contents($fileName);
     if (!String::create($text)->contains($loaderInput)) {
         $toInput = $loaderInput . $toInput;
     }
     if (strpos($text, "managers.xml") == false) {
         $position = strpos($text, "}", strpos($text, "function load("));
         $newContent = substr_replace($text, $toInput, $position, 0);
         file_put_contents($fileName, $newContent);
     }
 }
 /**
  * Probably a better way to do this but I have the flu and i'm tired :P
  * @param $toRemove
  * @return bool
  */
 protected function removeConfiguration($toRemove)
 {
     $contents = null;
     if (false == ($contents = file_get_contents($this->routingFile))) {
         throw new IOException('Error reading routing file.');
     }
     $contents = String::create($contents);
     if ($contents->contains($toRemove)) {
         $newContent = (string) $contents->subStrUntil($toRemove, true);
         $newContent .= (string) $contents->subStrAfter($toRemove, true);
         $this->addConfiguration($newContent, true);
     }
 }
예제 #4
0
 /**
  * @param $template
  * @param $parameters
  *
  * @return string
  */
 protected function render($template, $parameters)
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Filesystem($this->skeletonDirs), ['debug' => true, 'cache' => false, 'strict_variables' => true, 'autoescape' => false]);
     $twig->addFilter(new \Twig_SimpleFilter('addslashes', 'addslashes'));
     $twig->addFilter(new \Twig_SimpleFilter('lowerfirst', function ($input) {
         return (string) String::create($input)->lowerCaseFirst();
     }));
     $twig->addFilter(new \Twig_SimpleFilter('pluralize', function ($input) {
         return (string) String::create($input)->pluralize();
     }));
     return $twig->render($template, $parameters);
 }