Esempio n. 1
0
 /**
  * getOptionListYaml returns a YAML dump of default options.
  *
  * @param \nochso\WriteMe\Placeholder\OptionList $optionList
  *
  * @return string
  */
 public function getOptionListYaml(OptionList $optionList)
 {
     $data = [];
     foreach ($optionList->getOptions() as $option) {
         Dot::set($data, $option->getPath(), $option->getDefault());
     }
     return Yaml::dump($data);
 }
Esempio n. 2
0
 /**
  * Format a string depending on a quantity.
  *
  * See the class documentation for defining `$format`.
  *
  * @param string $format
  * @param string $quantity
  *
  * @return mixed
  */
 public static function format($format, $quantity)
 {
     $quantity = Numeric::ensure($quantity);
     $callback = function ($matches) use($quantity) {
         // Get available choices
         $choices = preg_split('/\\|/', $matches[2]);
         // Assume plural
         $choice = 0;
         // Choose singular
         if ($quantity === 1.0 || $quantity === 1) {
             $choice = 1;
         }
         // Choose zero if it's defined, otherwise keep using plural format
         if (($quantity === 0 || $quantity === 0.0) && isset($choices[2])) {
             $choice = 2;
         }
         return Dot::get($choices, $choice, '');
     };
     $pattern = '/(?<!\\\\)(\\((.+?(?<!\\\\))\\))/';
     $out = preg_replace_callback($pattern, $callback, $format);
     $out = sprintf($out, $quantity);
     return $out;
 }
Esempio n. 3
0
 /**
  * Set a frontmatter value using dot.notation as a key/path.
  *
  * @param string $dotPath Dot notation path to set/replace a value
  * @param mixed  $value
  */
 public function set($dotPath, $value)
 {
     Dot::set($this->data, $dotPath, $value);
 }