<?php // enable error reporting error_reporting(E_ALL); ini_set('display_errors', 1); /** * provide simple autoloader */ spl_autoload_register(function ($className) { $pathParts = explode('\\', $className); $className = array_pop($pathParts); $patternFolder = camelCaseToUnderscore(array_shift($pathParts)); $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $patternFolder . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR; for ($i = 0; $i < count($pathParts); $i++) { $path .= camelCaseToUnderscore($pathParts[$i]) . DIRECTORY_SEPARATOR; } $path .= $className . '.php'; require_once $path; }); /** * Convert given string in CamelCase to underscore: camel_case * @param string $str * @return string */ function camelCaseToUnderscore($str) { $str[0] = strtolower($str[0]); $func = create_function('$c', 'return "_" . strtolower($c[1]);'); return preg_replace_callback('/([A-Z])/', $func, $str); }
/** * Make all command output array for given fields * * @param Symfony\Component\Console\Output\OutputInterface $output, string $word, array $exploded_line * @return array */ protected function makeAllOutputArray(OutputInterface $output, $word, array $exploded_line) { $answer = []; $answer['word'] = strtolower($word); array_shift($exploded_line); $arpabet_array = array_filter($exploded_line); foreach ($this->options['method_names'] as $answer_field => $method) { if (!method_exists($this, $method)) { $output->writeln("<error>Incorret field input</error>"); $output->writeln("<info>Field options: </info><comment>word,arpabet,ipa,spelling</comment>"); $GLOBALS['status'] = 1; exit; } $answer_field = camelCaseToUnderscore($answer_field); $answer[$answer_field] = $this->{$method}($word, $exploded_line, $arpabet_array); } return $answer; }