SkillAgentSearch skills...

Ding

DI ( Dependency Injection: Setter, Constructor, Method), AOP ( Aspect Oriented Programming ), Events support, xml, yaml, and annotations (including some JSR 250 and JSR 330, like @Configuration and @Bean ala java configuration) , lightweight, simple, and quick MVC ( Model View Controller ), syslog, tcp client and server, with non blocking sockets, custom error, signal, and exception handling through events. Needs PHP 5.3, very similar to seasar, spring ( java ) . Can be deployed as a PHAR file.

Install / Use

/learn @marcelog/Ding
About this skill

Quality Score

0/100

Category

Operations

Supported Platforms

Universal

README

Introduction

Please contact me if you have any comments, doubts, or any kind of feedback. Send an email to: marcelog@gmail.com

Checkout the api (phpdoc) at: http://marcelog.github.com/Ding/php-doc/html/index.html

In the homepage, you can find the user manual: http://marcelog.github.com/Ding

Ding is also the winner of the 2011 Binpress programming contest :)

See these articles for a complete application example:

  • http://marcelog.github.com/articles/php_applications_with_doctrine2_orm_and_ding_di_container.html
  • http://marcelog.github.com/articles/php_asterisk_listener_example_using_pami_and_ding.html
  • Some more articles can be found here http://marcelog.github.com/articles/articles.html

Please see inside docs/examples for code samples. A good place to start are the "basic", "aop", "quickstart", "doctrine", and "mvc" examples.

Upgrading note

If you are upgrading from <= 1.1 to 1.3, please see README.1.3.x.

Supported Dependency Injection annotations:

  • JSR-250: @PostConstruct, @PreDestroy, @Resouce
  • JSR-330: @Inject, @Named, @Singleton
  • Spring specific: @Configuration, @Primary, @Value, @Scope, @Component, @Aspect, @Required, @Bean, @Controller, @RequestMapping
  • Own specific: @Prototype, @InitMethod, @DestroyMethod, @ListensOn, @MethodInterceptor, @ExceptionInterceptor

INSTALLATION

See http://marcelog.github.com/articles/ding_how_to_install_configure_tutorial_introduction.html for an indepth look of how to install.

CI Server

Take a look at the Jenkins CI Server (http://ci.marcelog.name/) to check out the docs, metrics, and pear and phar packages available.

Available via Composer

Just add the package "marcelog/ding": { "require": { "marcelog/ding": "dev-master" }, "repositories": [ { "type": "pear", "url": "http://pear.apache.org/log4php/" }] } Packagist URL: http://packagist.org/packages/marcelog/ding

Available via PEAR

You can now easily install Ding by issuing:

pear channel-discover pear.marcelog.name

pear install marcelog/Ding

or

pear install marcelog/Ding-1.6.3

just replace 1.6.3 by the release version you'd like to install :) See: http://pear.marcelog.name/

Note: A version 1.2.x was erroneously released because of a misconfiguration of the pear channel. To avoid more confusions about the correct versions, 1.2.x will not have any releases. So versions jump from 1.1.x to 1.3.0. If you happen to have a 1.2.0 version installed, please update the pear channel and download the latest version.

PHAR File

Just go to the Jenkins server at http://ci.marcelog.name and grab the latest phar distribution from the Ding job.

Supported bean definitions providers

  • XML
  • YAML
  • Annotations (like JSR 250 and 330)

Supported annotations

Remember that using annotations is completely optional. Not using them will benefit performance. Annotations CAN be cached. Use the 'annotations' cache with any of the implementations below ;)

See these: http://marcelog.github.com/articles/ding_component_bean_annotations.html http://marcelog.github.com/articles/ding_component_bean_annotations_di_dependency_injection.html

  • @Configuration and @Bean just like Java Configuration. So you dont even need a beans.xml (@Scope, @InitMethod, @DestroyMethod) for this annotated bean definitions.
  • @Component (used in classes, supports same annotations as @Bean)
  • @Required
  • @Resource
  • @Named
  • @Inject
  • @Singleton
  • @Prototype
  • @Scope
  • @PostConstruct
  • @PreDestroy
  • @Value
  • @Bean
  • @Primary
  • @Controller (When using the MVC through http).
  • @RequestMapping (When using the MVC through http).
  • @InitMethod(method=xxx)
  • @DestroyMethod(method=xxx)
  • @Aspect for classes and @ExceptionInterceptor/@MethodInterceptor for methods.
  • @ListensOn

CACHE

Ding supports this cache implementations out of the box.

  • APC.
  • File.
  • Zend Cache.
  • Memcache through memcached php extension (needs libmemcached).
  • DUMMY.

Each one of the implementations can be used for bean caching, beandefinition caching, or proxy caching. Actually, caching beans is a little trickier in the php world. In the java world, the application server is always "up & running", whilst in php everything is created from scratch for every request. So it may be better to not cache the bean itself, but everything else, like definintions and proxies definitions.

DI

  • Import other beans.xml files anywhere inside your already existant files. This let you split your beans among several configuration files.
  • Setter injection (php evaluated code, arrays, values, and/or references to other beans).
  • Constructor injection (php evaluated code, arrays, values, and/or references to other beans).
  • Method injection (ala spring lookup-method) allows you to have singletons that can deliver prototypes scoped beans.
  • A bean can be: singleton or prototype (multiple instances).
  • Can create beans by specifying a static method of the bean class itself.
  • Can create beans by specifying another bean (and its method) as a factory.
  • Properties for your beans.xml, like: ${log.dir}/alog.log. You can also have the container setup any php options by specifying a property with the name "php." (i.e: php.date.timezone).
  • Optional init-method will be called right after assembling a bean. (Can also be specified via the @InitMethod(method=xxx) annotation).
  • Optional destroy-method will be called when the container is shutting down. (Can also be specified via the @DestroyMethod(method=xxx) annotation).
  • Supports bean inheritance, via OOP and via xml and yaml definitions.
  • Supports bean aliasing, via xml, yaml, and annotations.

Aware Interfaces

IContainerAware: Whenever ding is going to instantiate a bean whose class implements IContainerAware interface, it will inject the container instace to this bean.

IBeanNameAware: Whenever ding is going to instantiate a bean whose class implements IBeanNameAware interface, it will inject the bean name.

IAspectManagerAware: Whenever ding is going to instantiate a bean whose class implements IAspectManagerAware interface, it will inject the current instance of the aspect manager (giving the ability to inject pointcuts, aspects, and general aop management).

IResourceLoaderAware: Whenever ding is going to instantiate a bean whose class implements IResourceLoaderAware interface, it will inject the instance of the resource loader in use, which is usually the container itself.

ILoggerAware: Whenever ding is going to instantiate a bean whose class implements ILoggerAware interface, it will inject the instance of the logger (log4php) in use by the container, so you can log there. The returned logger will be of class CLASS (where \ are replaced with .).

IReflectionFactoryAware: Whenever ding is going to instantiate a bean whose class implements IReflectionFactoryAware interface, it will inject the instance of the reflection factory in use.

Extension points

You can easily hook in the bean lifecycle by just implementing one of:

  • Ding\Bean\Lifecycle\IAfterDefinition
  • Ding\Bean\Lifecycle\IBeforeCreate
  • Ding\Bean\Lifecycle\IAfterCreate
  • Ding\Bean\Lifecycle\IBeforeAssemble
  • Ding\Bean\Lifecycle\IAfterAssemble
  • Ding\Bean\Lifecycle\IAfterConfig This will allow you to extend the container functionality as much as you like :)

If you want to provider beans yourself, just have a bean implement the Ding\Bean\IBeanDefinitionProvider interface, it will automatically be registered in the container and will be called whenever a new bean definition is demanded.

If you want to provide aspects and pointcuts, just implement one or all of:

  • Ding\Aspect\IAspectProvider
  • Ding\Aspect\IPointcutProvider

The container will automatically register your bean in the aspect manager and will be called to get any new aspects/pointcuts when needed.

Events

The container natively supports events. This means that you can register beans (either programatically or via the xml, yaml, or annotations drivers) and then asynchronously trigger (dispatch) these events along some data object. The container will then instantiate the needed beans (the listeners) and notify them. Please see docs/examples/events for an example using xml, yaml, and annotations.

You can also see this article about working with events: http://marcelog.github.com/articles/ding_event_listen_dispatch_bean.html

AOP

Aspects work via an implementation of the interceptor pattern. There are 2 available interceptors, both of them available in xml, yaml, and annotation drivers.

  • Method: Use this one to be called before every method execution (use proceed() to continue the chained execution), resuming your own afterwards.

  • Exception: Use this one to be called when an asp

Related Skills

View on GitHub
GitHub Stars119
CategoryOperations
Updated9mo ago
Forks26

Languages

PHP

Security Score

87/100

Audited on Jun 25, 2025

No findings