kassko / data-mapper-bundle
Integrates data-mapper in Symfony projects.
Installs: 20 825
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 2
Open Issues: 1
Requires
- php: >=5.5.0
- doctrine/common: ^2.4|^3.0
- kassko/class-resolver-bundle: ^1.0
- kassko/data-mapper: ^1.0
- symfony/framework-bundle: ^2.6|^3.0|^4.0|^5.0
- symfony/twig-bundle: ^2.4|^3.0|^4.0|^5.0
- zendframework/zend-stdlib: ^2.3|^3.0
- 1.0.x-dev
- v1.0.2
- v1.0.1
- v1.0.0
- dev-master / 0.15.0.x-dev
- v0.15.0.0
- 0.14.x-dev
- v0.14.4.0
- v0.14.3.0
- v0.14.2.0
- v0.14.1.0
- v0.14.0.0
- v0.13.0.1-alpha
- v0.13.0.0-alpha
- v0.12.0.0-alpha
- v0.11.1.0-alpha
- v0.11.0.0-alpha
- v0.10.0.0-alpha
- v0.9.0.1-alpha
- v0.9.0.0-alpha
- v0.8.0.0-alpha
- v0.7.0.0-alpha
- v0.6.0.0-alpha
- v0.5.0.1-alpha
- v0.5.0.0-alpha
- v0.4.0.0-alpha
- v0.3.0.0-alpha.1
- v0.2.0-alpha.11
- v0.2.0-alpha.10
- v0.2.0-alpha.9
- v0.2.0-alpha.8
- 0.2.0-alpha.7
- 0.2.0-alpha.6
- 0.2.0-alpha.5
- 0.2.0-alpha.4
- 0.2.0-alpha.3
- 0.2.0-alpha.2
- 0.2.0-alpha.1
- 0.1.4-alpha
- 0.1.3-alpha
- 0.1.2-alpha
- 0.1.1-alpha
- 0.1.0-alpha
- dev-kassko-compat-sf-5
- dev-kassko-sf54-compliance
- dev-kassko-class_resolver_config
- dev-kassko-expression_language
- dev-allow_nested_objects_hydration
- dev-move_provider_to_data_source_concept
This package is auto-updated.
Last update: 2024-10-28 03:32:17 UTC
README
This bundle integrates the data-mapper component into Symfony applications. Which is a mapper that provides a lot of features to represent some raw data as objects.
To know more about this component and how to use it, please read the data-mapper documentation reference.
Installation on Symfony 2
Note that:
- The second version number is used when compatibility is broken
- The third for new feature
- The fourth for hotfix
- The first for new API or to go from pre-release to release (from 0 to 1)
Using a version in 0.14
is recommended.
Versions in 0.15
are no longer maintained.
You can install the library with composer and here is a good requirement:
composer require kassko/data-mapper-bundle:"~0.14.4"
Register the bundle in app/AppKernel.php
:
public function registerBundles() { $bundles = array( new Kassko\Bundle\DataMapperBundle\KasskoDataMapperBundle(), new Kassko\Bundle\ClassResolverBundle\KasskoClassResolverBundle(), ); }
- DataMapper service
- Configuration reference
- Expression language integration
- Object listener
- Custom loader
DataMapper service
Get the service from your controller:
$this->get('kassko_data_mapper');
It represents a Kassko\DataMapper\DataMapper
instance. To know more about this component and how to use it, please read the data-mapper documentation reference.
Configuration reference
kassko_data_mapper: mapping: default_resource_type: annotations # Default is "annotations" or other type (1). default_resource_dir: # Optional. default_provider_method: # Optional. bundles: #optional section some_bundle: resource_type: annotations # Default is "annotations" or other type (1). resource_dir: # The resource dir of the given bundle. provider_method: ~ # Required. Default value is null. objects: # Optional section. some_object: resource_type: # Optional. resource_path: # Optional. The resource directory with the resource name. If not defined, data-mapper fallback to resource_name and prepend to it resource_dir (or default_resource_dir). So if resource_path is not defined, case resource_name and resource_dir (or default_resource_dir) must be defined. resource_name: # Optional. Only the resource name (so without the directory). provider_method: # Optional. Override default_provider_method. object_class: # Required (full qualified object class name). cache: metadata_cache: # Optional section class: # Optional. id: # Optional. life_time: # Default is 0 is_shared: # Default is false adapter_class: # Default is "Kassko\Bundle\DataMapperBundle\Adapter\Cache\DoctrineCacheAdapter" result_cache: # Optional section and same as metadata_cache logger_service: # Optional. A logger service name. Il will be used for logging in data-mapper component.
(1) availables types are annotations, yaml, php, php_file, yaml_file. And maybe others, feel free to add custom mapping loaders.
Expression language integration
Expression language services
Add a provider
<service id="my_provider" class="Kassko\Sample\SomeExpressionFunctionProvider"> <tag name="kassko_data_mapper.expression_function_provider" variable_key="container" variable_value="service_container"/> </service>
With the code above, the container is available in your provider. You can use it:
use Kassko\DataMapper\Expression\ExpressionFunction; use Kassko\DataMapper\Expression\ExpressionFunctionProviderInterface; class ExpressionFunctionProvider implements ExpressionFunctionProviderInterface { public function getFunctions() { return [ new ExpressionFunction( 'granted', function ($arg) { return sprintf('container.get(%s)', $arg); }, function (array $context, $value) { return $context['container']->get($value); } ), ]; } }
Object listener
The data-mapper needs to be able to retrieve an object listener from its full qualified class name. In order to do that, you have to register your object listener as a service and tag it with kassko_data_mapper.listener
.
To know more about object listener, please read the data-mapper documentation reference.
Custom loader
DataMapper provide three formats for mapping: annotations
, yaml
and php
. But you can use a custom mapping loader.
For more details about how to implement your custom loader, please read the data-mapper documentation reference.
Use a service in a persistent object without injecting it
You need to add it in the registry. You can do that by this way.
Tag your service:
<service id="logger"> <tag name="kassko_data_mapper.registry_item" key="logger"> </service>
And then you can get your service from your persistent object:
trait LoggableTrait { private function getLogger() { return Registry::getInstance()['logger']; } }
class Person { use LoggableTrait; private $id; private $name; private $address; public function getName() { if (! isset($this->address)) { $this->getLogger()->warning(sprintf('No address for %s', $this->name)); } } }