/** * {@inheritdoc} */ public function getProxyFactoryCode(Definition $definition, $id) { $instantiation = 'return'; if ($definition->isShared()) { $instantiation .= " \$this->services['{$id}'] ="; } if (func_num_args() >= 3) { $methodName = func_get_arg(2); } else { @trigger_error(sprintf('You must use the third argument of %s to define the method to call to construct your service since version 3.1, not using it won\'t be supported in 4.0.', __METHOD__), E_USER_DEPRECATED); $methodName = 'get' . Container::camelize($id) . 'Service'; } $proxyClass = $this->getProxyClassName($definition); $generatedClass = $this->generateProxyClass($definition); $constructorCall = $generatedClass->hasMethod('staticProxyConstructor') ? $proxyClass . '::staticProxyConstructor' : 'new ' . $proxyClass; return <<<EOF if (\$lazyLoad) { {$instantiation} {$constructorCall}( function (&\$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface \$proxy) { \$wrappedInstance = \$this->{$methodName}(false); \$proxy->setProxyInitializer(null); return true; } ); } EOF; }
/** * {@inheritdoc} */ public function getProxyFactoryCode(Definition $definition, $id) { $instantiation = 'return'; if ($definition->isShared()) { $instantiation .= " \$this->services['{$id}'] ="; } $methodName = 'get' . Container::camelize($id) . 'Service'; $proxyClass = $this->getProxyClassName($definition); return <<<EOF if (\$lazyLoad) { {$instantiation} new {$proxyClass}( function (&\$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface \$proxy) { \$wrappedInstance = \$this->{$methodName}(false); \$proxy->setProxyInitializer(null); return true; } ); } EOF; }
/** * {@inheritdoc} */ public function getProxyFactoryCode(Definition $definition, $id) { $instantiation = 'return'; if ($definition->isShared()) { $instantiation .= " \$this->services['{$id}'] ="; if (defined('Symfony\\Component\\DependencyInjection\\ContainerInterface::SCOPE_CONTAINER') && ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition->getScope(false))) { $instantiation .= " \$this->scopedServices['{$scope}']['{$id}'] ="; } } $methodName = 'get' . Container::camelize($id) . 'Service'; $proxyClass = $this->getProxyClassName($definition); $generatedClass = $this->generateProxyClass($definition); $constructorCall = $generatedClass->hasMethod('staticProxyConstructor') ? $proxyClass . '::staticProxyConstructor' : 'new ' . $proxyClass; return <<<EOF if (\$lazyLoad) { \$container = \$this; {$instantiation} {$constructorCall}( function (&\$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface \$proxy) use (\$container) { \$wrappedInstance = \$container->{$methodName}(false); \$proxy->setProxyInitializer(null); return true; } ); } EOF; }
/** * {@inheritdoc} */ public function getProxyFactoryCode(Definition $definition, $id) { $instantiation = 'return'; if (ContainerInterface::SCOPE_CONTAINER === $definition->getScope()) { $instantiation .= " \$this->services['{$id}'] ="; } elseif (ContainerInterface::SCOPE_PROTOTYPE !== ($scope = $definition->getScope())) { $instantiation .= " \$this->services['{$id}'] = \$this->scopedServices['{$scope}']['{$id}'] ="; } $methodName = 'get' . Container::camelize($id) . 'Service'; $proxyClass = $this->getProxyClassName($definition); return <<<EOF if (\$lazyLoad) { \$container = \$this; {$instantiation} new {$proxyClass}( function (&\$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface \$proxy) use (\$container) { \$wrappedInstance = \$container->{$methodName}(false); \$proxy->setProxyInitializer(null); return true; } ); } EOF; }
/** * Constructs a ViewsPluginManager object. * * @param string $type * The plugin type, for example filter. * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations, * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * Cache backend instance to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. */ public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { $plugin_definition_annotation_name = 'Drupal\\views\\Annotation\\Views' . Container::camelize($type); parent::__construct("Plugin/views/{$type}", $namespaces, $module_handler, 'Drupal\\views\\Plugin\\views\\ViewsPluginInterface', $plugin_definition_annotation_name); $this->defaults += array('parent' => 'parent', 'plugin_type' => $type, 'register_theme' => TRUE); $this->alterInfo('views_plugins_' . $type); $this->setCacheBackend($cache_backend, "views:{$type}"); }
/** * @inheritdoc */ public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { $plugin_definition_annotation_name = 'Drupal\\geocoder\\Annotation\\GeocoderPlugin'; parent::__construct('Plugin/Geocoder/' . Container::camelize($type), $namespaces, $module_handler, 'Drupal\\geocoder\\Plugin\\GeocoderPluginInterface', $plugin_definition_annotation_name); $this->defaults += array('plugin_type' => strtolower($type)); $this->alterInfo('geocoder_plugins_' . $type); $this->setCacheBackend($cache_backend, 'geocoder:' . $type); }
public function __construct(array $defaults = array(), $router = null, $templateRoute = null) { $this->setRouter($router, $templateRoute); foreach ($defaults as $key => $val) { $method = 'set' . \Symfony\Component\DependencyInjection\Container::camelize($key); $this->{$method}($val); } }
/** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { foreach ($this->context->getMetadata()->properties as $propertyMetadata) { /* @var PropertyMetadata $propertyMetadata */ foreach ($propertyMetadata->getConstraints() as $constraint) { if ($constraint instanceof ContentFile) { $method = 'get' . Container::camelize($constraint->mapping) . 'MappingType'; if (!method_exists($value, $method)) { throw new \RuntimeException(sprintf('Method "%s" should be defined in class %s', $method, get_class($value))); } $accessor = PropertyAccess::createPropertyAccessor(); $propertyName = $propertyMetadata->getPropertyName(); $content = $accessor->getValue($value, $propertyName); // check also translations if ($translations = $accessor->getValue($value, 'translations')) { foreach ($translations as $translation) { if ($translation->getField() == $propertyName) { $content .= $translation->getContent(); } } } $content = trim($content); if (mb_strlen($content) == 0) { return; } $mappingType = $value->{$method}(); $files = $this->contentFileManager->findFilesByMappingType($mappingType); // extract all images from content property preg_match_all('/src=[\'\\"]*(.+?)[\'\\"]/', $content, $matches); array_shift($matches); if (count($matches[0]) > 0) { $matches = $matches[0]; foreach ($matches as $imgFile) { $imgFile = preg_replace('/\\?.*$/', '', $imgFile); $imgFile = pathinfo($imgFile, PATHINFO_BASENAME); foreach ($files as $key => $file) { /* @var \SciGroup\TinymcePluploadFileManagerBundle\Model\ContentFile $file */ if ($file->getFileName() == $imgFile) { $file->setIsSubmitted(true); unset($files[$key]); continue 2; } } // remove file $pathResolver = $this->mappingResolver->resolve($mappingType); $imgFile = $pathResolver->getDirectory(true) . '/' . $imgFile; if (file_exists($imgFile)) { unlink($imgFile); } } } foreach ($files as $file) { $this->contentFileManager->remove($file); } } } } }
/** * {@inheritdoc} * * @param string $type * The plugin type, for example 'color_selector'. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, $type, ConfigFactoryInterface $config_factory) { $path = Container::camelize($type); $this->config = $config_factory->get('image_effects.settings'); parent::__construct("Plugin/image_effects/{$path}", $namespaces, $module_handler); $this->alterInfo("image_effects_{$type}_plugin_info"); $this->setCacheBackend($cache_backend, "image_effects_{$type}_plugins"); $this->defaults += ['plugin_type' => $type]; }
/** * Constructs a ViewsHandlerManager object. * * @param string $handler_type * The plugin type, for example filter. * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations, * @param \Drupal\views\ViewsData $views_data * The views data cache. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * Cache backend instance to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. */ public function __construct($handler_type, \Traversable $namespaces, ViewsData $views_data, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { $plugin_definition_annotation_name = 'Drupal\\views\\Annotation\\Views' . Container::camelize($handler_type); parent::__construct("Plugin/views/{$handler_type}", $namespaces, $module_handler, $plugin_definition_annotation_name); $this->setCacheBackend($cache_backend, "views:{$handler_type}", array('extension' => array(TRUE, 'views'))); $this->viewsData = $views_data; $this->handlerType = $handler_type; $this->defaults = array('plugin_type' => $handler_type); }
/** {@inheritdoc} */ public function getCodeBlocks() { // Convert keys to camelCase. $config = []; foreach ($this->config['resolve_loader'] as $key => $value) { $config[lcfirst(Container::camelize($key))] = $value; } return [(new CodeBlock())->set(CodeBlock::RESOLVE_LOADER, $config)]; }
/** {@inheritdoc} */ public function getCodeBlocks() { // Convert keys to camelCase. $config = []; foreach ($this->config['output'] as $key => $value) { $config[lcfirst(Container::camelize($key))] = $value; } return [(new CodeBlock())->set(CodeBlock::OUTPUT, $config)]; }
/** * @param ContainerBuilder $container */ public function process(ContainerBuilder $container) { foreach ($container->getDefinitions() as $id => $definition) { $className = strtr(Container::camelize($id), '_', '\\'); /** @var \Symfony\Component\DependencyInjection\Definition $definition */ if ($definition->getClass() === NULL && !$definition->isAbstract() && (class_exists($className) || interface_exists($className))) { $definition->setClass($className); } } }
/** * {@inheritdoc} */ public function getWhereSnippet(FilterDataInterface $filterData) { $values = $filterData->getValue(); $clauses = []; $parameters = []; foreach ($values as $value) { $parameter = Container::camelize($this->getConfig()['field'] . '_' . $value); $clauses[] = sprintf("%s = :%s", $this->getConfig()['field'], $parameter); $parameters[$parameter] = $value; } return ['snippet' => '(' . implode(' OR ', $clauses) . ')', 'parameters' => $parameters]; }
private function camelizeKeys($array) { $result = []; foreach ($array as $key => $value) { $key = lcfirst(Container::camelize($key)); if (is_array($value)) { $value = $this->camelizeKeys($value); } $result[$key] = $value; } return $result; }
private function processConfigValue($value, $model, &$res) { if (is_array($value) && isset(reset($value)['getter'])) { $invoker = reset($value)['getter']; $fieldName = key($value); } else { $invoker = 'get' . $value; $fieldName = $value; } $invoker = \Symfony\Component\DependencyInjection\Container::camelize($invoker); $data = $model->{$invoker}(); $res[$fieldName] = $this->serializer->serialize($data); }
public function bindForm(Form $form) { $fields = $form->getIterator(); /** @var \Symfony\Component\Form\Form $field */ foreach ($fields as $field) { $functionName = sprintf("set%s", Container::camelize($field->getName())); if (method_exists($this, $functionName)) { $this->{$functionName}($field->getData()); } else { $this->{$field->getName()} = $field->getData(); } } }
protected function initDriver() { $this->driver = $this->container->getParameter('vitre_php_console.driver'); $driverName = Container::camelize($this->driver); $class = __NAMESPACE__ . '\\Drivers\\' . $driverName . '\\Driver'; if (class_exists($class)) { $this->driver = new $class($this); $this->driver->connect(); return $this->driver; } else { trigger_error('PHP console driver "' . $class . '" not exists.', \E_USER_ERROR); } }
/** * Calls the setters. * * @param array $options * @param OptionsInterface $class * * @throws Exception */ public static function callingSettersWithOptions(array $options, OptionsInterface $class) { $methods = get_class_methods($class); foreach ($options as $key => $value) { $key = Container::camelize($key); $method = 'set' . ucfirst($key); if (in_array($method, $methods)) { $class->{$method}($value); } else { throw new Exception('callingSettersWithOptions(): ' . $method . ' invalid method name'); } } }
/** * {@inheritdoc} */ public function getFieldHandler($entity, $entity_type, $field_name) { $reflection = new \ReflectionClass($this); $core_namespace = $reflection->getShortName(); $field_types = $this->getEntityFieldTypes($entity_type); $camelized_type = Container::camelize($field_types[$field_name]); $default_class = sprintf('\\Drupal\\Driver\\Fields\\%s\\DefaultHandler', $core_namespace); $class_name = sprintf('\\Drupal\\Driver\\Fields\\%s\\%sHandler', $core_namespace, $camelized_type); if (class_exists($class_name)) { return new $class_name($entity, $entity_type, $field_name); } return new $default_class($entity, $entity_type, $field_name); }
public function testEvent() { $this->loadClassFromVfs("Event/ExampleTableEvent"); $reflection = new \ReflectionClass("TheliaStudioTestModule\\Event\\ExampleTableEvent"); // Test mother classes $this->assertTrue($reflection->isSubclassOf("TheliaStudioTestModule\\Event\\Base\\ExampleTableEvent")); $this->assertTrue($reflection->isSubclassOf("Thelia\\Core\\Event\\ActionEvent")); $proprieties = array("id", "visible", "position", "exampleTable", "title", "locale", "description", "chapo", "postscriptum"); foreach ($proprieties as $propriety) { $this->assertTrue($reflection->hasProperty($propriety), "The class doesn't have the propriety {$propriety}"); $this->assertTrue($reflection->hasMethod("get" . Container::camelize($propriety)), "The class doesn't have the method 'get" . Container::camelize($propriety) . "'"); $this->assertTrue($reflection->hasMethod("set" . Container::camelize($propriety)), "The class doesn't have the method 'get" . Container::camelize($propriety) . "'"); } }
/** * @return Finder */ public function getFinder() { $finder = DefaultFinder::create()->in($this->finderDirs); if (isset($this->styleCIConfig['finder']) && is_array($this->styleCIConfig['finder'])) { $finderConfig = $this->styleCIConfig['finder']; foreach ($finderConfig as $key => $values) { $finderMethod = Container::camelize(str_replace('-', '_', $key)); foreach ($values as $value) { $finder->{$finderMethod}($value); } } } return $finder; }
/** * Constructs a ViewsHandlerManager object. * * @param string $handler_type * The plugin type, for example filter. * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations, * @param \Drupal\views\ViewsData $views_data * The views data cache. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * Cache backend instance to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. */ public function __construct($handler_type, \Traversable $namespaces, ViewsData $views_data, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { $plugin_definition_annotation_name = 'Drupal\\views\\Annotation\\Views' . Container::camelize($handler_type); $plugin_interface = 'Drupal\\views\\Plugin\\views\\ViewsHandlerInterface'; if ($handler_type == 'join') { $plugin_interface = 'Drupal\\views\\Plugin\\views\\join\\JoinPluginInterface'; } parent::__construct("Plugin/views/{$handler_type}", $namespaces, $module_handler, $plugin_interface, $plugin_definition_annotation_name); $this->setCacheBackend($cache_backend, "views:{$handler_type}"); $this->alterInfo('views_plugins_' . $handler_type); $this->viewsData = $views_data; $this->handlerType = $handler_type; $this->defaults = array('plugin_type' => $handler_type); }
/** * @param array $googleAuthUser * @return \FOS\UserBundle\Model\UserInterface */ public function build(array $googleAuthUser) { $user = $this->userManager->createUser(); foreach ($googleAuthUser as $key => $value) { $methodName = "set" . Container::camelize($key); if (method_exists($user, $methodName)) { $user->{$methodName}($value); } } $user->setEmail($googleAuthUser['email']); $user->setUsername($googleAuthUser['email']); $user->setEnabled(1); $user->setPassword(time()); return $user; }
public function guessOptions($class, $fieldName) { $options = array(); $classMetadata = $this->metadataFactory->getClassMetadata($class); // normal and camelized for getters foreach (array($fieldName, Container::camelize($fieldName)) as $name) { if ($classMetadata->hasMemberMetadatas($name)) { foreach ($classMetadata->getMemberMetadatas($name) as $memberMetadata) { foreach ($memberMetadata->getConstraints() as $constraint) { $options = array_merge($options, $this->guessOptionsForConstraint($constraint)); } } } } return $options; }
/** * @param string $name short name of serializer (ex.: php) or full class name * * @throws \Dmishh\SettingsBundle\Exception\UnknownSerializerException * * @return SerializerInterface */ public static function create($name) { $serializerClass = 'Dmishh\\SettingsBundle\\Serializer\\' . Container::camelize($name) . 'Serializer'; if (class_exists($serializerClass)) { return new $serializerClass(); } else { $serializerClass = $name; if (class_exists($serializerClass)) { $serializer = new $serializerClass(); if ($serializer instanceof SerializerInterface) { return $serializer; } } } throw new UnknownSerializerException($serializerClass); }
public function filter($collection_query, $filter) { if ($filter && is_array($filter)) { foreach ($filter as $key => $value) { if ($value === '') { continue; } $filter_method = (string) 'filterBy' . \Symfony\Component\DependencyInjection\Container::camelize($key); $int_value = (int) $value; if ((string) $int_value != $value) { $value = '%' . $value . '%'; } $collection_query->{$filter_method}($value); } } return $collection_query; }
/** * {@inheritdoc} */ public function getWhereSnippet(FilterDataInterface $filterData) { $values = explode(',', $filterData->getValue()); $from = $values[0]; $to = isset($values[1]) ? $values[1] : null; $parameters = []; $parameterFrom = Container::camelize($this->getConfig()['field'] . '_from'); $parameterTo = Container::camelize($this->getConfig()['field'] . '_to'); if ($from !== null && $to !== null) { $parameters[$parameterFrom] = $from; $parameters[$parameterTo] = $to; $snippet = sprintf("%s BETWEEN :%s AND :%s", $this->getConfig()['field'], $parameterFrom, $parameterTo); } elseif ($from !== null) { $parameters[$parameterFrom] = $from; $snippet = sprintf("%s >= :%s", $this->getConfig()['field'], $parameterFrom); } else { $parameters[$parameterTo] = $to; $snippet = sprintf("%s <= :%s", $this->getConfig()['field'], $parameterTo); } return ['snippet' => $snippet, 'parameters' => $parameters]; }
public function askOneColumn() { $column = new ConsoleColumn(); $name = $this->dialog->ask($this->output, '<info>Specify column name (press </info><comment><return></comment><info> to stop adding columns): </info> ', false, $this->propel_columns); if (!$name) { return false; } $column->setName($name); $label = $this->dialog->ask($this->output, '<info>Specify column label</info> <comment>[' . \Symfony\Component\DependencyInjection\Container::camelize($name) . ']</comment>: ', \Symfony\Component\DependencyInjection\Container::camelize($name)); $column->setLabel($label); $type = $this->dialog->ask($this->output, '<info>Specify column type</info> <comment>[string]</comment>: ', 'string', $this->available_types); $column->setType($type); $options = array(); $options['listable'] = $this->dialog->ask($this->output, '<info>Should column be listed in table?</info> <comment>[yes]</comment>: ', 'yes'); $options['editable'] = $this->dialog->ask($this->output, '<info>Should column be listed in edit form?</info> <comment>[yes]</comment>: ', 'yes'); $options['sortable'] = $this->dialog->ask($this->output, '<info>Should column be sortable?</info> <comment>[yes]</comment>: ', 'yes'); $options['filterable'] = $this->dialog->ask($this->output, '<info>Should column be filterable?</info> <comment>[yes]</comment>: ', 'yes'); $column->setOptions($this->toBoolean($options)); $this->configurator->addColumn($column); $this->output->writeln("\n" . 'Column was added.' . "\n"); return $column; }
/** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $bundleAlias = $this->getAlias(); $bundleName = substr(Container::camelize($bundleAlias), 8); $configurationClassName = 'Orkestro\\Bundle\\' . $bundleName . 'Bundle\\DependencyInjection\\Configuration'; $configuration = new $configurationClassName($bundleAlias, $container->getParameter('orkestro.db_driver')); $config = $this->processConfiguration($configuration, $configs); $container->setParameter($bundleAlias . '.model_manager_name', $config['model_manager_name']); switch ($config['db_driver']) { case 'orm': $container->setParameter($bundleAlias . '.backend_type_orm', true); break; case 'mongodb': $container->setParameter($bundleAlias . '.backend_type_mongodb', true); break; default: break; } $reflected = new \ReflectionObject($this); $path = dirname($reflected->getFileName()) . '/../Resources/config'; $loader = new Loader\XmlFileLoader($container, new FileLocator($path)); $loader->load('services.xml'); }