Example #1
0
 /**
  * Class init.
  *
  * @param string $path
  * @param string $root
  */
 public function __construct($path, $root)
 {
     $this->root = $root;
     $this->path = ltrim(str_replace(realpath($root), '', realpath($path)), '/\\');
     $this->fileInfo = new \SplFileInfo($root . '/' . $path);
     $this->name = File::stripExtension($this->fileInfo->getBasename());
     $this->type = $this->fileInfo->getExtension();
 }
Example #2
0
 /**
  * Returns the details about Communicator (current) file
  * w/o any kind of verification of file existance
  *
  * @param string $fileGiven
  * @return array
  */
 protected function getFileDetailsRaw($fileGiven)
 {
     $info = new \SplFileInfo($fileGiven);
     $aFileBasicDetails = ['File Extension' => $info->getExtension(), 'File Group' => $info->getGroup(), 'File Inode' => $info->getInode(), 'File Link Target' => $info->isLink() ? $info->getLinkTarget() : '-', 'File Name' => $info->getBasename('.' . $info->getExtension()), 'File Name w. Extension' => $info->getFilename(), 'File Owner' => $info->getOwner(), 'File Path' => $info->getPath(), 'Name' => $info->getRealPath(), 'Type' => $info->getType()];
     $aDetails = array_merge($aFileBasicDetails, $this->getFileDetailsRawStatistic($info, $fileGiven));
     ksort($aDetails);
     return $aDetails;
 }
Example #3
0
 /**
  * Interpolates a string by substituting tokens in a string
  * 
  * Default interpolations:
  * - `:webroot` Path to the webroot folder
  * - `:model` The current model e.g images
  * - `:field` The database field
  * - `:filename` The filename
  * - `:extension` The extension of the file e.g png
  * - `:id` The record id
  * - `:style` The current style e.g thumb
  * - `:hash` Generates a hash based on the filename
  * 
  * @param string $string The string to be interpolated with data.
  * @param string $name The name of the model e.g. Image
  * @param int $id The id of the record e.g 1
  * @param string $field The name of the database field e.g file
  * @param string $style The style to use. Should be specified in the behavior settings.
  * @param array $options You can override the default interpolations by passing an array of key/value
  *              pairs or add extra interpolations. For example, if you wanted to change the hash method
  *              you could pass `array('hash' => sha1($id . Configure::read('Security.salt')))`
  * @return array Settings array containing interpolated strings along with the other settings for the field.
  */
 public static function run($string, $name, $id, $field, $filename, $style = 'original', $data = array())
 {
     $info = new SplFileInfo($filename);
     $data += array('webroot' => preg_replace('/\\/$/', '', WWW_ROOT), 'model' => Inflector::tableize($name), 'field' => strtolower($field), 'filename' => $info->getBasename($info->getExtension()), 'extension' => $info->getExtension(), 'id' => $id, 'style' => $style, 'hash' => md5($info->getFilename() . Configure::read('Security.salt')));
     foreach (static::$_interpolations as $name => $closure) {
         $data[$name] = $closure($info);
     }
     return String::insert($string, $data);
 }
 /**
  *
  * @param string $filename
  *
  * @return \CSanquer\FakeryGenerator\Model\Config
  *
  * @throws \InvalidArgumentException
  */
 public function load($filename)
 {
     $file = new \SplFileInfo($filename);
     if (!in_array($file->getExtension(), ['json', 'xml'])) {
         throw new \InvalidArgumentException('The config file must be an XML or a JSON file.');
     }
     if (!file_exists($file->getRealPath())) {
         throw new \InvalidArgumentException('The config file must exist.');
     }
     return $this->serializer->deserialize(file_get_contents($file->getRealPath()), 'CSanquer\\FakeryGenerator\\Model\\Config', $file->getExtension());
 }
 /**
  * @param \SplFileInfo $fileInfo
  * @return mixed|string
  */
 private function getFileExtension(\SplFileInfo $fileInfo)
 {
     if ($fileInfo instanceof UploadedFile) {
         return pathinfo($fileInfo->getClientOriginalName(), PATHINFO_EXTENSION);
     }
     return $fileInfo->getExtension();
 }
Example #6
0
 /**
  * Performs a check of file
  *
  * @param \SplFileInfo $file File to check
  *
  * @return bool
  */
 public function __invoke(\SplFileInfo $file)
 {
     $rootDirectory = $this->rootDirectory;
     $includePaths = $this->includePaths;
     $excludePaths = $this->excludePaths;
     if ($file->getExtension() !== 'php') {
         return false;
     }
     $realPath = $file->getRealPath();
     // Do not touch files that not under rootDirectory
     if (strpos($realPath, $rootDirectory) !== 0) {
         return false;
     }
     if ($includePaths) {
         $found = false;
         foreach ($includePaths as $includePath) {
             if (strpos($realPath, $includePath) === 0) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             return false;
         }
     }
     foreach ($excludePaths as $excludePath) {
         if (strpos($realPath, $excludePath) === 0) {
             return false;
         }
     }
     return true;
 }
 public function crop()
 {
     $input = Input::all();
     $quality = 90;
     $sizes = $this->getSizes($input['ratio']);
     $sourceImage = $this->uploadsDirectory . $input['directory'] . '/' . $input['image'];
     $fileInfo = new \SplFileInfo($sourceImage);
     $fileExtension = $fileInfo->getExtension();
     foreach ($sizes as $sizeKey => $size) {
         $croppedImageName = preg_replace('/^(.*)\\.' . $fileExtension . '$/', '$1_' . $sizeKey . '.' . $fileExtension, $input['image']);
         $croppedImageFullPath = $this->uploadsDirectory . $input['directory'] . '/' . $croppedImageName;
         if ($fileExtension === 'jpg' || $fileExtension === 'jpeg') {
             $jpgImage = imagecreatefromjpeg($sourceImage);
             $jpgTempImage = imagecreatetruecolor($size[0], $size[1]);
             imagecopyresampled($jpgTempImage, $jpgImage, 0, 0, $input['x'], $input['y'], $size[0], $size[1], $input['w'], $input['h']);
             imagejpeg($jpgTempImage, $croppedImageFullPath, $quality);
         } else {
             if ($fileExtension === 'png') {
                 $pngImage = imagecreatefrompng($sourceImage);
                 $pngTempImage = imagecreatetruecolor($size[0], $size[1]);
                 imagecopyresampled($pngTempImage, $pngImage, 0, 0, $input['x'], $input['y'], $size[0], $size[1], $input['w'], $input['h']);
                 imagepng($pngTempImage, $croppedImageFullPath, round((100 - $quality) * 0.09));
             }
         }
     }
     $previewSize = isset($input['preview_size']) ? $input['preview_size'] : 't';
     $imageUrl = asset('images/uploads' . $input['directory'] . '/' . ImageHelper::getImage($input['image'], $previewSize));
     return redirect()->route('image_done', ['target' => $input['target'], 'id' => $input['id'], 'directory' => base64_encode($input['directory']), 'image' => base64_encode($input['image']), 'url' => base64_encode($imageUrl)]);
 }
Example #8
0
 /**
  *
  */
 public function uploadFromurl($url = null)
 {
     $uploadOk = 1;
     $opts = array('http' => array('method' => 'GET', 'max_redirects' => '0', 'ignore_errors' => '1'));
     $context = stream_context_create($opts);
     $info = new SplFileInfo($url);
     if (strtolower($info->getExtension()) != "jpg") {
         $uploadOk = 0;
         $this->error = "Only JPG";
     } else {
         $imageFileType = "jpg";
     }
     if ($uploadOk) {
         $result = file_get_contents($url, false, $context);
         if ($result) {
             //   $temp = tempnam(sys_get_temp_dir(), 'TMP_');
             //  $imageFileType = pathinfo($temp, PATHINFO_EXTENSION);
             $new_file = $this->getFilename($imageFileType);
             $new_file_th = $this->getFilenameth($imageFileType);
             if (file_exists($new_file)) {
                 unlink($new_file);
             }
             if (file_exists($new_file_th)) {
                 unlink($new_file_th);
             }
             file_put_contents($new_file, $result);
             $this->greateTH($new_file, $new_file_th);
             return true;
         } else {
             $this->error = "Невозможно скачать файл";
         }
     }
 }
 /**
  * @param \SplFileInfo $file
  *
  * @return NodeParserInterface|null
  */
 public function resolve(\SplFileInfo $file)
 {
     if ('php' === strtolower($file->getExtension())) {
         return $this->getPhpClassExtractor();
     }
     return null;
 }
Example #10
0
 public function deployProcess(\SplFileInfo $file, $name = NULL)
 {
     $builder = new DeploymentBuilder($name === NULL ? $file->getFilename() : $name);
     $builder->addExtensions($file->getExtension());
     $builder->addResource($file->getFilename(), $file);
     return $this->deploy($builder);
 }
Example #11
0
 /**
  * Load config data. Support php|ini|yml config formats.
  *
  * @param string|\SplFileInfo $configFile
  * @throws ConfigException
  */
 public function loadConfig($configFile)
 {
     if (!$configFile instanceof \SplFileInfo) {
         if (!is_string($configFile)) {
             throw new ConfigException('Mismatch type of variable.');
         }
         $path = realpath($this->basePath . $configFile);
         // check basePath at mutation
         if (strpos($configFile, '..') || !strpos($path, realpath($this->basePath))) {
             throw new ConfigException('Config file name: ' . $configFile . ' isn\'t correct.');
         }
         if (!is_file($path) || !is_readable($path)) {
             throw new ConfigException('Config file: ' . $path . ' not found of file isn\'t readable.');
         }
         $configFile = new \SplFileInfo($path);
     }
     $path = $configFile->getRealPath();
     $ext = $configFile->getExtension();
     $key = $configFile->getBasename('.' . $ext);
     if ('php' === $ext) {
         $this->data[$key] = (include $path);
     } elseif ('ini' === $ext) {
         $this->data[$key] = parse_ini_file($path, true);
     } elseif ('yml' === $ext) {
         if (!function_exists('yaml_parse_file')) {
             throw new ConfigException("Function `yaml_parse_file` isn't supported.\n" . 'http://php.net/manual/en/yaml.requirements.php');
         }
         $this->data[$key] = yaml_parse_file($path);
     }
 }
 function getCustomWidgets($dir)
 {
     $customwidgets = array();
     $widgetdir = get_option('widgetdir');
     if (file_exists($dir)) {
         $cdir = scandir($dir);
     } else {
         return;
     }
     foreach ($cdir as $d) {
         if ($d == "." || $d == ".." || $d == ".svn") {
             continue;
         }
         if (is_dir($widgetdir . '/' . $d) == TRUE) {
             $dirFile = scandir($widgetdir . '/' . $d);
             foreach ($dirFile as $dir) {
                 $info = new SplFileInfo($dir);
                 if (is_dir($dir) == FALSE && $info->getExtension() == 'php') {
                     $file = $d . '/' . $dir;
                     array_push($customwidgets, $file);
                 }
             }
         } else {
             if (is_dir($d) == FALSE) {
                 array_push($customwidgets, $d);
             }
         }
     }
     return $customwidgets;
 }
Example #13
0
 public function src($src, $ext = null)
 {
     if (!is_file($src)) {
         throw new FileNotFoundException($src);
     }
     $this->src = $src;
     if (!$ext) {
         $info = new \SplFileInfo($src);
         $this->ext = strtoupper($info->getExtension());
     } else {
         $this->ext = strtoupper($ext);
     }
     if (is_file($src) && ($this->ext == "JPG" or $this->ext == "JPEG")) {
         $this->image = ImageCreateFromJPEG($src);
     } else {
         if (is_file($src) && $this->ext == "PNG") {
             $this->image = ImageCreateFromPNG($src);
         } else {
             throw new FileNotFoundException($src);
         }
     }
     $this->input_width = imagesx($this->image);
     $this->input_height = imagesy($this->image);
     return $this;
 }
Example #14
0
 /**
  * todo - добавить проверки и исключения
  * todo - вывести пути в конфиги
  *
  * @param $result
  * @throws \Exception
  */
 protected function postSave($result)
 {
     if (is_array($result)) {
         $data = $this->getData();
         $id = $data['id'];
     } elseif ($result) {
         $id = (int) $result;
     } else {
         $id = 0;
     }
     if (!empty($_FILES['file']['name']) && $id) {
         $configTwigUpload = App::getInstance()->getConfigParam('upload_files');
         if (!isset($configTwigUpload['images_category_and_product'])) {
             throw new \Exception('Неверные Параметры конфигурации upload_files');
         }
         $prefix = $configTwigUpload['images_category_and_product'] . '/category/';
         $uploaddir = App::getInstance()->getCurrDir() . '/web' . $prefix;
         $info = new \SplFileInfo($_FILES['file']['name']);
         $fileExtension = $info->getExtension();
         $uploadfile = $uploaddir . $id . '.' . $fileExtension;
         $uploadfileDB = $prefix . $id . '.' . $fileExtension;
         if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
             $tbl = $this->getDataClass();
             $tbl->update(array('file' => $uploadfileDB), array('id' => $id));
         } else {
             throw new \Exception('Ошибка при сохранении изображения');
         }
     }
 }
 /**
  * Extract the zip archive to be imported
  *
  * @throws \RuntimeException When archive cannot be opened or extracted or does not contain exactly one file file
  */
 protected function extractZipArchive()
 {
     $archive = new \ZipArchive();
     $status = $archive->open($this->filePath);
     if (true !== $status) {
         throw new \RuntimeException(sprintf('Error "%d" occurred while opening the zip archive.', $status));
     }
     $path = $this->fileInfo->getPath();
     $filename = $this->fileInfo->getBasename('.' . $this->fileInfo->getExtension());
     $targetDir = sprintf('%s/%s', $path, $filename);
     if (!$archive->extractTo($targetDir)) {
         throw new \RuntimeException('Error occurred while extracting the zip archive.');
     }
     $archive->close();
     $this->archivePath = $targetDir;
     $finder = new Finder();
     $files = $finder->in($targetDir)->name('/\\.' . $this->type . '$/i');
     $count = $files->count();
     if (1 !== $count) {
         throw new \RuntimeException(sprintf('Expecting the root directory of the archive to contain exactly 1 file file, found %d', $count));
     }
     $filesIterator = $files->getIterator();
     $filesIterator->rewind();
     $this->filePath = $filesIterator->current()->getPathname();
 }
Example #16
0
 public function __construct($path, $source = null)
 {
     if (!file_exists($path)) {
         throw new \Exception("{$path} file Not Found");
     }
     $this->time_create = time();
     $this->name = session_id() . '_' . md5($path);
     $file = new \SplFileInfo($path);
     $this->file_name_no_extension = str_replace('.' . $file->getExtension(), '', $file->getFilename());
     $this->type = $file->getExtension();
     $this->file_name = $file->getFilename();
     $this->path = $path;
     $this->dir = dirname($path);
     $this->modefy = $file->getMTime();
     $this->source = $source;
 }
 function it_cuts_the_filename_if_it_is_too_long(\SplFileInfo $file)
 {
     $file->getFilename()->willReturn('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.pdf');
     $file->getExtension()->willReturn('pdf');
     $pathInfo = $this->generate($file);
     $pathInfo->shouldBeValidPathInfo('Lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit__sed_do_eiusmod_tempor_incididunt_ut_la.pdf');
 }
 /**
  * @param \SplFileInfo $data
  * @return bool
  */
 public function supports($data)
 {
     if (!$data instanceof \SplFileInfo) {
         return false;
     }
     return strtolower($data->getExtension()) == "php";
 }
Example #19
0
 /**
  * Upload an image to local server then return new image path after upload success
  * 
  * @param array $file [tmp_name, name, error, type, size] 
  * @param string image path for saving (this may constain filename)
  * @param string image filename for saving
  * @return string Image path after uploaded
  * @throws Exception If upload failed
  */
 public function upload($file, $newImagePath = '.', $newImageName = NULL)
 {
     if (!empty($file['error'])) {
         $this->_throwException(':method: Upload error. Number: :number', array(':method' => __METHOD__, ':number' => $file['error']));
     }
     if (getimagesize($file['tmp_name']) === FALSE) {
         $this->_throwException(':method: The file is not an image file.', array(':method' => __METHOD__));
     }
     $fileInfo = new \SplFileInfo($newImagePath);
     if (!$fileInfo->getRealPath() or !$fileInfo->isDir()) {
         $this->_throwException(':method: The ":dir" must be a directory.', array(':method' => __METHOD__, ':dir' => $newImagePath));
     }
     $defaultExtension = '.jpg';
     if (empty($newImageName)) {
         if (!in_array($fileInfo->getBasename(), array('.', '..')) and $fileInfo->getExtension()) {
             $newImageName = $fileInfo->getBasename();
         } else {
             $newImageName = uniqid() . $defaultExtension;
         }
     }
     if (!$fileInfo->isWritable()) {
         $this->_throwException(':method: Directory ":dir" is not writeable.', array(':method' => __METHOD__, ':dir' => $fileInfo->getRealPath()));
     }
     $destination = $fileInfo->getRealPath() . DIRECTORY_SEPARATOR . $newImageName;
     if (move_uploaded_file($file['tmp_name'], $destination)) {
         return $destination;
     } else {
         $this->_throwException(':method: Cannot move uploaded file to :path', array(':method' => __METHOD__, ':path' => $fileInfo->getRealPath()));
     }
 }
Example #20
0
 function __construct(\SplFileInfo $file, $contentType, $filename = null, $fileExtension = null)
 {
     $this->file = $file;
     $this->filename = $filename ?: $file->getBasename();
     $this->contentType = $contentType;
     $this->fileExtension = $fileExtension ?: $file->getExtension();
 }
Example #21
0
 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 protected static function boot()
 {
     parent::boot();
     static::saving(function (\Eloquent $model) {
         // If a new download file is uploaded, could be create or edit...
         $dirty = $model->getDirty();
         if (array_key_exists('filename', $dirty)) {
             $file = new \SplFileInfo($model->getAbsolutePath());
             $model->filesize = $file->getSize();
             $model->extension = strtoupper($file->getExtension());
             // Now if editing only...
             if ($model->exists) {
                 $oldFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('filename');
                 $newFilename = $dirty['filename'];
                 // Delete the old file if the filename is different to the new one, and it therefore hasn't been replaced
                 if ($oldFilename != $newFilename) {
                     $model->deleteFile($oldFilename);
                 }
             }
         }
         // If a download is edited and the image is changed...
         if (array_key_exists('image', $dirty) && $model->exists) {
             $oldImageFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('image');
             $model->deleteImageFiles($oldImageFilename);
         }
     });
     static::deleted(function ($model) {
         $model->deleteFile();
         $model->deleteImageFiles();
     });
 }
Example #22
0
 public function __construct($file, $app = null)
 {
     $env = $app->environment;
     $info = new \SplFileInfo($file);
     $this->type = $info->getExtension();
     $file_text = file_get_contents($file);
     $file_header = substr($file_text, 0, strpos($file_text, '}') + 1);
     $file_header = json_decode($file_header, true);
     $page_path = ltrim(str_replace($env['PAGES_ROOT_PATH'], '', $file), '/');
     $this->id = str_replace('.' . $this->type, '', $page_path);
     $this->header = $file_header;
     if (!isset($this->header['order'])) {
         $this->header['order'] = '';
     }
     $file_body = substr_replace($file_text, '', 0, strpos($file_text, '}') + 2);
     $this->contents = $file_body;
     if ($this->type == 'md') {
         $this->contents = str_replace('@@siteurl@@', $env['ROOT_PATH'], $this->contents);
         $this->contents = Markdown::defaultTransform($this->contents);
     } else {
         if ($this->type == 'html') {
             $this->contents = str_replace('@@siteurl@@', $env['ROOT_PATH'], $this->contents);
         } else {
             if ($this->type == 'txt') {
                 $this->contents = '<p>' . str_replace("\n", '</p><p>', $this->contents) . '</p>';
             }
         }
     }
 }
Example #23
0
 function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
 {
     if ($file->getExtension() == 'twital' && ($adapter = $this->twitalLoader->getSourceAdapter((string) $file))) {
         $source = $this->twitalLoader->getTwital()->compile($adapter, file_get_contents((string) $file));
         $ast = $this->twig->parse($this->twig->tokenize($source, (string) $file));
         $this->visitTwigFile($file, $catalogue, $ast);
     }
 }
 /**
  * @dataProvider imageExtensionsProvider
  *
  * @param string $extension
  * @param string $expectedResult
  */
 public function testImageExtensions($extension, $expectedResult)
 {
     $filePath = $this->faker->someImage(10, 10, [DummyImage::OPTION_DIR => null, DummyImage::OPTION_FULL_PATH => true, DummyImage::OPTION_EXTENSION => $extension]);
     $this->assertTrue(file_exists($filePath), "File not found {$filePath}");
     $fileInfo = new SplFileInfo($filePath);
     $this->assertEquals($expectedResult, $fileInfo->getExtension());
     unlink($filePath);
 }
 /**
  * {@inheritdoc}
  */
 public function loadMessages(\SplFileInfo $file, $locale, $domain, $format = null)
 {
     $format = $format ?: $file->getExtension();
     if (!isset($this->loaders[$format])) {
         throw new \InvalidArgumentException(sprintf('Unable to import file %s: ' . 'there is no loader associated with format "%s".', $file->getFilename(), $format));
     }
     return $this->loaders[$format]->load($file->getPathname(), $locale, $domain);
 }
Example #26
0
 /**
  * @param \SplFileInfo $file
  *
  * @return string
  */
 public function name(\SplFileInfo $file)
 {
     $name = uniqid(null, true);
     $extension = $this->escape($file->getExtension());
     if (!empty($extension)) {
         $name = sprintf('%s.%s', $name, $extension);
     }
     return $name;
 }
Example #27
0
 /**
  * Get a mimetype from a filename
  *
  * @param string $filename Filename to generate a mimetype from
  *
  * @return null|string
  */
 public static function getMimeFromFilename($filename = "")
 {
     $file = new \SplFileInfo($filename);
     // Get extension
     $ext = $file->getExtension();
     unset($file);
     // Try to get mime type
     return self::getMimeFromExtension($ext);
 }
 /**
  * Validate that the file is correctly encoded in the provided charset.
  *
  * @throws CharsetException
  * @throws \Exception
  */
 public function validate()
 {
     $file = new \SplFileInfo($this->filePath);
     if (!in_array($file->getExtension(), $this->whiteListExtension)) {
         $this->validateEncoding();
     } else {
         $this->stepExecution->addSummaryInfo('charset_validator.title', 'job_execution.summary.charset_validator.skipped');
     }
 }
Example #29
0
 /**
  * 
  * @param \SplFileInfo $file
  * @return boolean
  */
 protected function isVideo(\SplFileInfo $file)
 {
     if ($file->isDir()) {
         return false;
     }
     $ext = strtolower($file->getExtension());
     $videos = explode(',', 'wmv,ogg,avi,mpg,divx,flv');
     return in_array($ext, $videos);
 }
 /**
  *
  * @return multitype:\SplFileInfo \Symfony\Component\Finder\Finder
  *         \Symfony\Component\HttpFoundation\mixed
  */
 protected function getModel()
 {
     // $model = new Model();
     $model = array();
     $request = $this->getRequest();
     $model['request'] = $request;
     $model['currentRoute'] = $request->get('_route');
     $path = $request->get('path', '');
     $rootDir = $this->get('kernel')->getRootDir();
     $rootDirInfo = new \SplFileInfo($rootDir);
     $filesystemPath = sprintf("%s/%s", $rootDirInfo->getPath(), $path);
     $filesystemInfo = new \SplFileInfo($filesystemPath);
     // $pathInfo->getPathname()
     $model['path'] = $path;
     $model['filesystemPath'] = $filesystemPath;
     $model['filesystemPathInfo'] = $filesystemInfo;
     if (is_dir($filesystemPath)) {
         $model['finder'] = $this->getFinder($filesystemPath);
     } else {
         $source = file_get_contents($filesystemPath);
         $extention = $filesystemInfo->getExtension();
         $language = $filesystemInfo->getExtension();
         switch ($language) {
             case '':
                 $language = "txt";
                 break;
             case 'js':
                 $language = "javascript";
                 break;
             case 'yml':
                 $language = "yaml";
                 break;
             case 'xmi':
             case 'xsd':
             case 'wsdl':
                 $language = "xml";
                 break;
         }
         $geshi = new \GeSHi($source, $language);
         $model['highlight'] = $geshi->parse_code();
         $model['source'] = $source;
     }
     return array('model' => $model);
 }