示例#1
0
 /**
  * Get a manipulable image instance.
  *
  * @param string $file the image path
  *
  * @return ImageHandler a manipulable image instance
  */
 public function open($file)
 {
     if (strlen($file) >= 1 && $file[0] == '@') {
         $file = $this->fileLocator instanceof FileLocatorInterface ? $this->fileLocator->locate($file) : $this->fileLocator->locateResource($file);
     }
     return $this->createInstance($file);
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $configFile = $this->kernel->locateResource('@OroFormBundle/Resources/config/config_icon.yml');
     $config = Yaml::parse($configFile);
     $choices = array_flip($config['oro_icon_select']);
     $resolver->setDefaults(['placeholder' => 'oro.form.choose_value', 'choices' => $choices, 'empty_value' => '', 'configs' => ['placeholder' => 'oro.form.choose_value', 'result_template_twig' => 'OroFormBundle:Autocomplete:icon/result.html.twig', 'selection_template_twig' => 'OroFormBundle:Autocomplete:icon/selection.html.twig']]);
 }
 /**
  * @param PreMigrationEvent $event
  */
 public function onPreUp(PreMigrationEvent $event)
 {
     if ($event->isTableExist(CreateMigrationTableMigration::MIGRATION_TABLE)) {
         $data = $event->getData(sprintf('select * from %s where id in (select max(id) from %s group by bundle)', CreateMigrationTableMigration::MIGRATION_TABLE, CreateMigrationTableMigration::MIGRATION_TABLE));
         foreach ($data as $val) {
             $event->setLoadedVersion($val['bundle'], $val['version']);
         }
     } else {
         $event->addMigration(new CreateMigrationTableMigration());
         // load MigrationTable initial data for BAP and OroCRM bundles installed before migrations is introduced
         // @todo: this transient solution can be removed in a future
         // when we ensure RC1 and RC2 are updated for all clients
         if ($event->isTableExist('oro_installer_bundle_version')) {
             $oroTableDataConfig = $this->kernel->locateResource('@OroMigrationBundle/EventListener/MigrationTableData/Oro.yml');
             $bundleVersions = Yaml::parse(realpath($oroTableDataConfig));
             $oroCrmTableDataConfig = $this->kernel->locateResource('@OroMigrationBundle/EventListener/MigrationTableData/OroCRM.yml');
             if ($event->isTableExist('orocrm_account')) {
                 $bundleVersions = array_merge($bundleVersions, Yaml::parse(realpath($oroCrmTableDataConfig)));
             }
             foreach ($bundleVersions as $bundleName => $version) {
                 $event->setLoadedVersion($bundleName, $version);
             }
             $event->addMigration(new UpdateBundleVersionMigration($bundleVersions));
             $event->addMigration(new UpdateEntityConfigMigration());
         }
     }
 }
 /**
  * Imports units.
  *
  * @return array An array with the keys "skipped" and "imported" which contain the number of units skipped and imported
  * @throws \Exception If an error occured
  */
 public function importUnits()
 {
     $path = $this->kernel->locateResource(self::UNIT_PATH . self::UNIT_DATA);
     $yaml = new Parser();
     $data = $yaml->parse(file_get_contents($path));
     $count = 0;
     $skipped = 0;
     foreach ($data as $unitName => $unitData) {
         $unit = $this->getUnit($unitName);
         if ($unit === null) {
             $unit = new Unit();
             $unit->setName($unitName);
             $unit->setSymbol($unitData["symbol"]);
             if (array_key_exists("prefixes", $unitData)) {
                 if (!is_array($unitData["prefixes"])) {
                     throw new \Exception($unitName . " doesn't contain a prefix list, or the prefix list is not an array.");
                 }
                 foreach ($unitData["prefixes"] as $name) {
                     $prefix = $this->getSiPrefix($name);
                     if ($prefix === null) {
                         throw new \Exception("Unable to find SI Prefix " . $name);
                     }
                     $unit->getPrefixes()->add($prefix);
                 }
             }
             $this->entityManager->persist($unit);
             $this->entityManager->flush();
             $count++;
         } else {
             $skipped++;
         }
     }
     return array("imported" => $count, "skipped" => $skipped);
 }
示例#5
0
 /**
  * @return array
  */
 public function getConfigurations()
 {
     if ($this->configuration !== null) {
         return $this->configuration;
     }
     $bundles = $this->kernel->getBundles();
     $configuration = [];
     foreach ($bundles as $bundle) {
         try {
             $class = get_class($bundle);
             $classParts = explode('\\', $class);
             $bundleName = array_pop($classParts);
             $file = $this->kernel->locateResource(sprintf('@%s/Resources/config/search.yml', $bundleName));
         } catch (\Exception $e) {
             continue;
         }
         $data = $this->parseFile($file);
         if (is_array($data)) {
             foreach ($data as $class => $config) {
                 $configuration[$class] = $config;
             }
         }
     }
     $this->configuration = $configuration;
     return $configuration;
 }
 /**
  * @param string $filename
  * @throws \InvalidArgumentException
  */
 public function setFilename($filename)
 {
     if ($filename && $filename[0] == '@') {
         $filename = $this->kernel->locateResource($filename);
     }
     if (!is_file($filename)) {
         throw new \InvalidArgumentException('Specified file does not exist: ' . $filename);
     }
     $this->filename = $filename;
 }
 /**
  * @return \XMLSecurityKey
  */
 public function getPrivateKey()
 {
     if (!$this->_key) {
         $filename = $this->keyFile;
         if ($filename[0] == '@') {
             $filename = $this->kernel->locateResource($filename);
         }
         $this->_key = KeyHelper::createPrivateKey($filename, $this->keyPass, true, false);
     }
     return $this->_key;
 }
 /**
  * Format the string config to array config with "file" attribute and translations.
  *
  * @param string|array    $config The config
  * @param KernelInterface $kernel The kernel
  *
  * @return array
  */
 public static function formatTranslationConfig($config, KernelInterface $kernel)
 {
     $config = static::formatConfig($config);
     $config['file'] = $kernel->locateResource($config['file']);
     if (isset($config['translations']) && is_array($config['translations'])) {
         /* @var array $translation */
         foreach ($config['translations'] as &$translation) {
             $translation['file'] = $kernel->locateResource($translation['file']);
         }
     }
     return $config;
 }
 /**
  * Gets all fixtures files
  */
 protected function loadFixtureFiles()
 {
     foreach ($this->bundles as $bundle) {
         $file = '*';
         if (strpos($bundle, '/')) {
             list($bundle, $file) = explode('/', $bundle);
         }
         $path = $this->kernel->locateResource('@' . $bundle);
         $files = glob($path . $this->directory . '/' . $file . '.yml');
         $this->fixture_files = array_unique(array_merge($this->fixture_files, $files));
     }
 }
 /**
  * @param $name
  *
  * @return array
  * @throws \Exception
  */
 private function getRawData($name)
 {
     if (isset($this->presets[$name])) {
         return $this->presets[$name];
     }
     if (false === strpos($name, ':')) {
         throw new \Exception(sprintf('Malformed namespaced configuration name "%s" (expecting "namespace:pagename").', $name));
     }
     list($namespace, $name) = explode(':', $name, 2);
     $path = $this->kernel->locateResource('@' . $namespace . '/Resources/config/pagetemplates/' . $name . '.yml');
     $rawData = Yaml::parse(file_get_contents($path));
     return $rawData;
 }
 protected function createManufacturer($manufacturerName, $manufacturerData)
 {
     $manufacturer = new Manufacturer();
     $manufacturer->setName($manufacturerName);
     if (array_key_exists('iclogos', $manufacturerData)) {
         foreach ($manufacturerData['iclogos'] as $icLogo) {
             $manufacturerIcLogo = new ManufacturerICLogo();
             $file = $this->kernel->locateResource(self::MANUFACTURER_PATH . $icLogo);
             $this->uploadedFileService->replaceFromFilesystem($manufacturerIcLogo, new File($file));
             $manufacturer->addIcLogo($manufacturerIcLogo);
         }
     }
     $this->entityManager->persist($manufacturer);
 }
 /**
  * @param \Symfony\Component\DependencyInjection\ContainerInterface $container_stub
  * @param \Symfony\Component\HttpKernel\KernelInterface $kernel_stub
  */
 function let($container_stub, $kernel_stub)
 {
     $template_path = realpath(__DIR__ . '/../../../../Action/Template/');
     $kernel_stub->locateResource(Argument::any())->willReturn($template_path);
     $container_stub->get(Argument::any())->willReturn($kernel_stub);
     $this->setContainer($container_stub);
 }
示例#13
0
 /**
  * @param Item $item
  *
  * @return string
  */
 protected function getOriginCover(Item $item)
 {
     if (!$this->origin_dir) {
         $this->origin_dir = $this->kernel->locateResource('@AnimeDbCatalogBundle/Resources/private/images/');
     }
     return $this->origin_dir . $item->getItem()->getCover();
 }
 public function __construct(SecureRandomInterface $rng, KernelInterface $kernel, array $languages)
 {
     parent::__construct($rng);
     $this->resource = $kernel->locateResource('@TweedeGolfGeneratorBundle/Resources/wordlists');
     $this->setLanguages($languages);
     $this->setSeparator(' ');
 }
示例#15
0
 public function __construct(EntityManagerInterface $em, KernelInterface $kernel, ContainerInterface $container, VersionAccessor $versionAccessor, $migrationConfigPath)
 {
     $this->em = $em;
     $this->migrations = Yaml::parse($kernel->locateResource($migrationConfigPath));
     $this->container = $container;
     $this->versionAccessor = $versionAccessor;
 }
示例#16
0
 /**
  * {@inheritdoc}
  */
 public function resolveFixtures(KernelInterface $kernel, array $fixtures)
 {
     $resolvedFixtures = [];
     // Get real fixtures path
     foreach ($fixtures as $index => $fixture) {
         if ($fixture instanceof \SplFileInfo) {
             $filePath = $fixture->getRealPath();
             if (false === $filePath) {
                 throw new \RuntimeException(sprintf('The file %s pointed by a %s instance was not found.', (string) $fixture, get_class($fixture)));
             }
             $fixture = $filePath;
         }
         if (false === is_string($fixture)) {
             throw new \InvalidArgumentException('Expected fixtures passed to be either strings or a SplFileInfo instances.');
         }
         if ('@' === $fixture[0]) {
             // If $kernel fails to resolve the resource, will throw a \InvalidArgumentException exception
             $realPath = $kernel->locateResource($fixture, null, true);
         } else {
             $realPath = realpath($fixture);
         }
         if (false === $realPath || false === file_exists($realPath)) {
             throw new \InvalidArgumentException(sprintf('The file "%s" was not found', $fixture));
         }
         if (false === is_file($realPath)) {
             throw new \InvalidArgumentException(sprintf('Expected "%s to be a fixture file, got a directory instead.', $fixture));
         }
         $resolvedFixtures[$realPath] = true;
     }
     return array_keys($resolvedFixtures);
 }
 /**
  * @param $responsePath
  * @param $type
  * @param $statusCode
  * @return callable
  * @throws \RuntimeException
  */
 private function getControllerResponseByResource($responsePath, $type, $statusCode)
 {
     $path = $this->kernel->locateResource($responsePath);
     $content = file_get_contents($path);
     // Override controller with fake response
     switch (strtolower($type)) {
         // JSON
         case ApiSandboxResponseTypeEnum::JSON_RESPONSE:
             $content = json_decode($content, 1);
             $controller = function () use($content, $statusCode) {
                 return new JsonResponse($content, $statusCode);
             };
             break;
             // XML
         // XML
         case ApiSandboxResponseTypeEnum::XML_RESPONSE:
             $controller = function () use($content, $statusCode) {
                 $response = new Response($content, $statusCode);
                 $response->headers->set('Content-Type', 'text/xml');
                 return $response;
             };
             break;
             // Unknown
         // Unknown
         default:
             throw new RuntimeException('Unknown type of SandboxApiResponse');
     }
     return [$controller, $content];
 }
示例#18
0
 public function __construct(KernelInterface $kernel, ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, OperationPathResolverInterface $operationPathResolver, ContainerInterface $container, array $formats)
 {
     $this->fileLoader = new XmlFileLoader(new FileLocator($kernel->locateResource('@ApiPlatformBundle/Resources/config/routing')));
     $this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
     $this->resourceMetadataFactory = $resourceMetadataFactory;
     $this->operationPathResolver = $operationPathResolver;
     $this->container = $container;
     $this->formats = $formats;
 }
示例#19
0
 /**
  * Get a manipulable image instance.
  *
  * @param string $file the image path
  *
  * @return ImageHandler a manipulable image instance
  */
 public function open($file)
 {
     if (strlen($file) >= 1 && $file[0] == '@') {
         try {
             if ($this->fileLocator instanceof FileLocatorInterface) {
                 $file = $this->fileLocator->locate($file);
             } else {
                 $this->fileLocator->locateResource($file);
             }
         } catch (\InvalidArgumentException $exception) {
             if ($this->throwException || false == $this->fallbackImage) {
                 throw $exception;
             }
             $file = $this->fallbackImage;
         }
     }
     return $this->createInstance($file);
 }
 /**
  * getMimetypeImage
  *
  * @param string  $filename
  * @param integer $size
  *
  * @return array|null|string
  *
  * @SuppressWarnings("PMD")
  */
 public function getMimetypeImage($filename, $size)
 {
     $mimetype = $this->getMimeType($filename);
     $sizes = array(16, 22, 24, 32, 48, 64, 96);
     $iconSize = null;
     foreach ($sizes as $allowedSize) {
         if ($size < $allowedSize) {
             $iconSize = $allowedSize;
             break;
         }
     }
     if (null === $iconSize) {
         $iconSize = max($sizes);
     }
     $icon = null;
     $extension = pathinfo($filename, PATHINFO_EXTENSION);
     $extensionMap = array('eps' => 'image-x-eps', 'psd' => 'image-x-psd', 'gif' => 'image-gif', 'bmp' => 'gnome-mime-image-x-portable-bitmap', 'doc' => 'application-msword', 'docx' => 'application-msword', 'xls' => 'spreadsheet', 'xlt' => 'spreadsheet', 'xlsx' => 'spreadsheet', 'dot' => 'spreadsheet', 'gzip' => 'gnome-mime-application-x-compressed-tar', 'txt' => 'txt', 'avi' => 'video', 'm4v' => 'video', 'mov' => 'video', 'mp4' => 'video', 'mp3' => 'video', 'html' => 'html', 'csv' => 'spreadsheet', 'flv' => 'video', 'rar' => 'gnome-mime-application-x-rar');
     if (isset($extensionMap[$extension])) {
         try {
             $icon = $this->kernel->locateResource('@ErichardDmsBundle/Resources/public/img/mimetypes/' . $iconSize . '/' . $extensionMap[$extension] . '.png');
         } catch (\InvalidArgumentException $e) {
         }
     } elseif (null !== $mimetype) {
         $mimetypes = array(str_replace('/', '-', $mimetype), explode('/', $mimetype)[0]);
         foreach ($mimetypes as $mimetype) {
             try {
                 $icon = $this->kernel->locateResource('@ErichardDmsBundle/Resources/public/img/mimetypes/' . $iconSize . '/' . $mimetype . '.png');
                 break;
             } catch (\InvalidArgumentException $e) {
             }
         }
     }
     if (null === $icon) {
         try {
             $icon = $this->kernel->locateResource('@ErichardDmsBundle/Resources/public/img/mimetypes/' . $iconSize . '/unknown.png');
         } catch (\InvalidArgumentException $e) {
         }
     }
     return $icon;
 }
 private function getValue($name)
 {
     if (isset($this->presets[$name])) {
         return $this->presets[$name];
     }
     $nameParts = explode(':', $name);
     if (2 !== sizeof($nameParts)) {
         throw new \Exception(sprintf('Malformed namespaced configuration name "%s" (expecting "namespace:pagename").', $name));
     }
     list($namespace, $name) = $nameParts;
     $path = $this->kernel->locateResource('@' . $namespace . '/Resources/config/pageparts/' . $name . '.yml');
     $value = Yaml::parse(file_get_contents($path));
     return $value;
 }
 protected function createFootprint($footprintName, $footprintData)
 {
     /**
      * @var FootprintCategory
      */
     $footprintCategoryRootNode = $this->footprintCategoryService->getRootNode();
     $footprint = new Footprint();
     $footprint->setName($footprintName);
     if (array_key_exists('description', $footprintData)) {
         $footprint->setDescription($footprintData['description']);
     }
     if (array_key_exists('category', $footprintData)) {
         $footprintCategory = $this->addFootprintCategoryPath(explode('/', $footprintData['category']), $footprintCategoryRootNode);
         $footprint->setCategory($footprintCategory);
     }
     if (array_key_exists('image', $footprintData)) {
         $footprintImage = new FootprintImage();
         $file = $this->kernel->locateResource(self::FOOTPRINT_PATH . $footprintData['image']);
         $this->uploadedFileService->replaceFromFilesystem($footprintImage, new File($file));
         $footprint->setImage($footprintImage);
     }
     $this->entityManager->persist($footprint);
 }
 /**
  * Imports or updates the existing si prefixes.
  *
  * @return array An array with the keys "skipped" and "imported" which contain the number of si prefixes skipped and imported
  */
 public function importSiPrefixes()
 {
     $path = $this->kernel->locateResource(self::SIPREFIX_PATH . self::SIPREFIX_DATA);
     $yaml = new Parser();
     $data = $yaml->parse(file_get_contents($path));
     $count = 0;
     $updated = 0;
     foreach ($data as $prefixName => $prefixData) {
         $prefix = $this->getSiPrefix($prefixName);
         if ($prefix === null) {
             $prefix = new SiPrefix();
             $prefix->setPrefix($prefixName);
             $this->entityManager->persist($prefix);
             $count++;
         }
         $prefix->setExponent($prefixData["exponent"]);
         $prefix->setSymbol($prefixData["symbol"]);
         $prefix->setBase($prefixData["base"]);
         $updated++;
     }
     $this->entityManager->flush();
     return array("updated" => $updated - $count, "imported" => $count);
 }
 /**
  * Start a monitor stream with a placeholder image
  *
  * @param YouTubeEvent $event
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastInputException
  */
 protected function startMonitorStream(YouTubeEvent $event)
 {
     $placeholderImage = $this->kernel->locateResource('@LiveBroadcastBundle') . '/Resources/images/placeholder.png';
     $inputMedia = new MediaMonitorStream();
     $inputMedia->setMonitorImage($placeholderImage);
     $inputService = new InputMonitorStream();
     $inputService->setMedia($inputMedia);
     $streamUrl = $this->getYouTubeApiService()->getStreamUrl($event->getBroadcast(), $event->getChannel());
     $outputService = new OutputYouTube();
     $outputService->setChannel($event->getChannel());
     $outputService->setStreamUrl($streamUrl);
     $metadata = array('broadcast_id' => $event->getBroadcast()->getBroadcastId(), 'channel_id' => $event->getChannel()->getChannelId(), 'monitor_stream' => 'yes');
     try {
         $this->logger->info('YouTube start monitor stream', array('broadcast_id' => $metadata['broadcast_id']));
         $this->commands->startProcess($inputService->generateInputCmd(), $outputService->generateOutputCmd(), $metadata);
     } catch (LiveBroadcastOutputException $e) {
         return;
     }
 }
 protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bundle = null)
 {
     $aclSchema = new \SplFileInfo($kernel->locateResource('@PropelBundle/Resources/acl_schema.xml'));
     return array((string) $aclSchema => array($kernel->getBundle('PropelBundle'), $aclSchema));
 }
 public function testFetchDefinitionResolvesProperlyAndFetchesXml()
 {
     $this->kernel->locateResource('@AppBundle/Resources/emails/path/to/mail.xml.twig')->willReturn('/path/to/mail.xml.twig')->shouldBeCalled();
     $this->twig->render('/path/to/mail.xml.twig', ['param1' => 'wuhuuuu'])->willReturn('<email></email>')->shouldBeCalled();
     $this->assertEquals('<email></email>', $this->fixture->fetchMailDefinition('App:path/to/mail', ['param1' => 'wuhuuuu']));
 }
示例#27
0
 /**
  * Create Twig_Environment object
  *
  * @return \Twig_Environment
  */
 protected function createTwigEnvironment()
 {
     $entityTemplateDir = $this->kernel->locateResource('@OroEmailBundle/Resources/cache/Entity');
     return new \Twig_Environment(new \Twig_Loader_Filesystem($entityTemplateDir));
 }
 /**
  * @return array
  */
 protected function getMappingData()
 {
     $filePath = $this->kernel->locateResource('@OroMigrationBundle/EventListener/data/1.0.0/platform.yml');
     return Yaml::parse(realpath($filePath));
 }
示例#29
0
 /**
  * Returns the contents of a file to the template.
  *
  * @param string $path A logical path to the file (e.g '@AcmeFooBundle:Foo:resource.txt').
  *
  * @return string         The contents of a file.
  */
 public function file($path)
 {
     $path = $this->kernel->locateResource($path, null, true);
     return file_get_contents($path);
 }
示例#30
0
 public function __construct(ResourceCollectionInterface $resourceCollection, KernelInterface $kernel)
 {
     $this->resourceCollection = $resourceCollection;
     $this->fileLoader = new XmlFileLoader(new FileLocator($kernel->locateResource('@DunglasApiBundle/Resources/config/routing')));
 }