function main() { try { if (!empty($_SERVER['REQUEST_URI'])) { throw new Exception("Please use this tool from command line"); } $options = $this->extended_getopt(array('-i', '-e')); if (isset($options['i'])) { $this->include_path($options['i']); } $this->require_phptal(); if (isset($options['--filenames--'])) { $paths = $options['--filenames--']; } if (!count($paths)) { $this->usage(); exit(1); } $lint = new PHPTAL_Lint(); if (empty($options['i'])) { $lint->skipUnknownModifiers(true); } $custom_extensions = NULL; if (isset($options['e'])) { $custom_extensions = preg_split('/[\\s,.]+/', $options['e'][0]); $lint->acceptExtensions($custom_extensions); echo "Looking for *.", implode(', *.', $custom_extensions), " files:\n"; } foreach ($paths as $arg) { if (is_dir($arg)) { $lint->scan(rtrim($arg, DIRECTORY_SEPARATOR)); } else { $lint->testFile($arg); } } echo "\n\n"; echo "Checked " . $this->plural($lint->checked, 'file') . "."; if ($lint->skipped) { echo " Skipped " . $this->plural($lint->skipped, "non-template file") . "."; } echo "\n"; if (!$custom_extensions && count($lint->skipped_filenames)) { echo "Skipped file(s): ", implode(', ', array_keys($lint->skipped_filenames)), ".\n"; } if (count($lint->errors)) { echo "Found " . $this->plural(count($lint->errors), "error") . ":\n"; $this->display_erorr_array($lint->errors); echo "\n"; exit(2); } else { if (count($lint->warnings)) { echo "Found " . $this->plural(count($lint->warnings), "warning") . ":\n"; $this->display_erorr_array($lint->warnings); echo "\n"; exit(0); } else { echo "No errors found!\n"; exit($lint->checked ? 0 : 1); } } } catch (Exception $e) { fwrite(STDERR, $e->getMessage() . "\n"); $errcode = $e->getCode(); exit($errcode ? $errcode : 1); } }
if (isset($options['e'])) { $custom_extensions = array_merge($custom_extensions, preg_split('/[\\s,.]+/', $options['e'][0])); } if (isset($options['--filenames--'])) { $paths = $options['--filenames--']; } if (!count($paths)) { usage(); exit(1); } $lint = new PHPTAL_Lint(); if (empty($options['i'])) { $lint->skipUnknownModifiers(); } if ($custom_extensions) { $lint->acceptExtensions($custom_extensions); echo "Using *.", implode(', *.', $custom_extensions), "\n"; } foreach ($paths as $arg) { if (is_dir($arg)) { $lint->scan($arg); } else { $lint->testFile($arg); } } echo "\n\n"; echo "Checked " . plural($lint->checked, 'file') . "."; if ($lint->skipped) { echo " Skipped " . plural($lint->skipped, "non-template file") . "."; } echo "\n";