{"id":16389280,"url":"https://github.com/marcelog/ding","last_synced_at":"2025-04-10T05:08:42.717Z","repository":{"id":1239131,"uuid":"1177396","full_name":"marcelog/Ding","owner":"marcelog","description":"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.","archived":false,"fork":false,"pushed_at":"2018-06-30T15:29:24.000Z","size":18341,"stargazers_count":121,"open_issues_count":25,"forks_count":26,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-10T05:08:41.726Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://marcelog.github.com/Ding","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcelog.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-12-17T15:03:33.000Z","updated_at":"2024-12-26T02:07:19.000Z","dependencies_parsed_at":"2022-07-20T16:49:03.137Z","dependency_job_id":null,"html_url":"https://github.com/marcelog/Ding","commit_stats":null,"previous_names":[],"tags_count":105,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2FDing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2FDing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2FDing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2FDing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcelog","download_url":"https://codeload.github.com/marcelog/Ding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161270,"owners_count":21057555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T04:32:13.620Z","updated_at":"2025-04-10T05:08:42.690Z","avatar_url":"https://github.com/marcelog.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Introduction\n============\nPlease contact me if you have any comments, doubts, or any kind of feedback.\nSend an email to: marcelog@gmail.com\n\nCheckout the api (phpdoc) at: http://marcelog.github.com/Ding/php-doc/html/index.html\n\nIn the homepage, you can find the user manual: http://marcelog.github.com/Ding\n\nDing is also the winner of the 2011 Binpress programming contest :)\n\nSee these articles for a complete application example:\n * http://marcelog.github.com/articles/php_applications_with_doctrine2_orm_and_ding_di_container.html\n * http://marcelog.github.com/articles/php_asterisk_listener_example_using_pami_and_ding.html\n * Some more articles can be found here http://marcelog.github.com/articles/articles.html\n\nPlease see inside docs/examples for code samples. A good place to start are\nthe \"basic\", \"aop\", \"quickstart\", \"doctrine\", and \"mvc\" examples.\n--------------------------------------------------------------------------------\nUpgrading note\n--------------------------------------------------------------------------------\nIf you are upgrading from \u003c= 1.1 to 1.3, please see README.1.3.x.\n--------------------------------------------------------------------------------\nSupported Dependency Injection annotations:\n * JSR-250: @PostConstruct, @PreDestroy, @Resouce\n * JSR-330: @Inject, @Named, @Singleton\n * Spring specific: @Configuration, @Primary, @Value, @Scope, @Component, @Aspect, @Required, @Bean, @Controller, @RequestMapping\n * Own specific: @Prototype, @InitMethod, @DestroyMethod, @ListensOn, @MethodInterceptor, @ExceptionInterceptor\n--------------------------------------------------------------------------------\nINSTALLATION\n------------\nSee http://marcelog.github.com/articles/ding_how_to_install_configure_tutorial_introduction.html\nfor an indepth look of how to install.\n--------------------------------------------------------------------------------\nCI Server\n---------\nTake a look at the Jenkins CI Server (http://ci.marcelog.name/) to check out the\ndocs, metrics, and pear and phar packages available.\n--------------------------------------------------------------------------------\nAvailable via Composer\n----------------------\nJust add the package \"marcelog/ding\":\n{\n    \"require\": {\n        \"marcelog/ding\": \"dev-master\"\n    },\n    \"repositories\": [\n    {\n      \"type\": \"pear\",\n      \"url\": \"http://pear.apache.org/log4php/\"\n    }]\n}\nPackagist URL: http://packagist.org/packages/marcelog/ding\n-------------------------------------------------------------------------------\nAvailable via PEAR\n------------------\nYou can now easily install Ding by issuing:\n# pear channel-discover pear.marcelog.name\n# pear install marcelog/Ding\n\nor\n\n\n# pear install marcelog/Ding-1.6.3\njust replace 1.6.3 by the release version you'd like to install :)\nSee: http://pear.marcelog.name/\n\nNote: A version 1.2.x was erroneously released because of a misconfiguration of\nthe pear channel. To avoid more confusions about the correct versions, 1.2.x \nwill not have any releases. So versions jump from 1.1.x to 1.3.0. If you happen\nto have a 1.2.0 version installed, please update the pear channel and download\nthe latest version.\n--------------------------------------------------------------------------------\nPHAR File\n=========\nJust go to the Jenkins server at http://ci.marcelog.name and grab the latest\nphar distribution from the Ding job.\n--------------------------------------------------------------------------------\nSupported bean definitions providers\n====================================\n* XML\n* YAML\n* Annotations (like JSR 250 and 330)\n--------------------------------------------------------------------------------\nSupported annotations\n=====================\nRemember that using annotations is completely optional. Not using them will\nbenefit performance. Annotations CAN be cached. Use the 'annotations' cache with\nany of the implementations below ;)\n\nSee these:\nhttp://marcelog.github.com/articles/ding_component_bean_annotations.html\nhttp://marcelog.github.com/articles/ding_component_bean_annotations_di_dependency_injection.html\n\n* @Configuration and @Bean just like Java Configuration. So you dont even need\na beans.xml (@Scope, @InitMethod, @DestroyMethod) for this annotated bean\ndefinitions.\n* @Component (used in classes, supports same annotations as @Bean)\n* @Required\n* @Resource\n* @Named\n* @Inject\n* @Singleton\n* @Prototype\n* @Scope\n* @PostConstruct\n* @PreDestroy\n* @Value\n* @Bean\n* @Primary\n* @Controller (When using the MVC through http).\n* @RequestMapping (When using the MVC through http).\n* @InitMethod(method=xxx)\n* @DestroyMethod(method=xxx)\n* @Aspect for classes and @ExceptionInterceptor/@MethodInterceptor for methods.\n* @ListensOn\n--------------------------------------------------------------------------------\nCACHE\n=====\nDing supports this cache implementations out of the box.\n* APC.\n* File.\n* Zend Cache.\n* Memcache through memcached php extension (needs libmemcached).\n* DUMMY.\n\nEach one of the implementations can be used for bean caching, beandefinition\ncaching, or proxy caching. Actually, caching beans is a little trickier in\nthe php world. In the java world, the application server is always \"up \u0026 running\",\nwhilst in php everything is created from scratch for every request. So it may\nbe better to not cache the bean itself, but everything else, like definintions\nand proxies definitions.\n--------------------------------------------------------------------------------\nDI\n==\n* Import other beans.xml files anywhere inside your already existant files. This\nlet you split your beans among several configuration files.\n* Setter injection (php evaluated code, arrays, values, and/or references to\n other beans).\n* Constructor injection (php evaluated code, arrays, values, and/or references\n to other beans).\n* Method injection (ala spring lookup-method) allows you to have singletons that\ncan deliver prototypes scoped beans.\n* A bean can be: singleton or prototype (multiple instances).\n* Can create beans by specifying a static method of the bean class itself.\n* Can create beans by specifying another bean (and its method) as a factory.\n* Properties for your beans.xml, like: ${log.dir}/alog.log. You can also have\nthe container setup any php options by specifying a property with the name \n\"php.\" (i.e: php.date.timezone).\n* Optional init-method will be called right after assembling a bean. (Can also\nbe specified via the @InitMethod(method=xxx) annotation).\n* Optional destroy-method will be called when the container is shutting down.\n(Can also be specified via the @DestroyMethod(method=xxx) annotation).\n* Supports bean inheritance, via OOP and via xml and yaml definitions.\n* Supports bean aliasing, via xml, yaml, and annotations.\n\nAware Interfaces\n================\nIContainerAware: Whenever ding is going to instantiate a bean whose class\nimplements IContainerAware interface, it will inject the container instace to\nthis bean.\n\nIBeanNameAware: Whenever ding is going to instantiate a bean whose class\nimplements IBeanNameAware interface, it will inject the bean name.\n\nIAspectManagerAware: Whenever ding is going to instantiate a bean whose class\nimplements IAspectManagerAware interface, it will inject the current instance\nof the aspect manager (giving the ability to inject pointcuts, aspects, and\ngeneral aop management).\n\nIResourceLoaderAware: Whenever ding is going to instantiate a bean whose class\nimplements IResourceLoaderAware interface, it will inject the instance of the\nresource loader in use, which is usually the container itself.\n\nILoggerAware: Whenever ding is going to instantiate a bean whose class\nimplements ILoggerAware interface, it will inject the instance of the\nlogger (log4php) in use by the container, so you can log there. The returned\nlogger will be of class __CLASS__ (where \\ are replaced with .).\n\nIReflectionFactoryAware: Whenever ding is going to instantiate a bean whose class\nimplements IReflectionFactoryAware interface, it will inject the instance of the\nreflection factory in use.\n\nExtension points\n================\nYou can easily hook in the bean lifecycle by just implementing one of:\n * Ding\\Bean\\Lifecycle\\IAfterDefinition\n * Ding\\Bean\\Lifecycle\\IBeforeCreate\n * Ding\\Bean\\Lifecycle\\IAfterCreate\n * Ding\\Bean\\Lifecycle\\IBeforeAssemble\n * Ding\\Bean\\Lifecycle\\IAfterAssemble\n * Ding\\Bean\\Lifecycle\\IAfterConfig\nThis will allow you to extend the container functionality as much as you like :)\n\nIf you want to provider beans yourself, just have a bean implement the\nDing\\Bean\\IBeanDefinitionProvider interface, it will automatically be registered\nin the container and will be called whenever a new bean definition is demanded.\n\nIf you want to provide aspects and pointcuts, just implement one or all of:\n * Ding\\Aspect\\IAspectProvider\n * Ding\\Aspect\\IPointcutProvider\n\nThe container will automatically register your bean in the aspect manager and\nwill be called to get any new aspects/pointcuts when needed.\n--------------------------------------------------------------------------------\nEvents\n======\nThe container natively supports events. This means that you can register beans\n(either programatically or via the xml, yaml, or annotations drivers) and then\nasynchronously trigger (dispatch) these events along some data object. The container\nwill then instantiate the needed beans (the listeners) and notify them. Please\nsee docs/examples/events for an example using xml, yaml, and annotations.\n\nYou can also see this article about working with events:\nhttp://marcelog.github.com/articles/ding_event_listen_dispatch_bean.html\n--------------------------------------------------------------------------------\nAOP\n===\nAspects work via an implementation of the interceptor pattern. There are 2\navailable interceptors, both of them available in xml, yaml, and annotation\ndrivers.\n\n* Method: Use this one to be called before every method\n execution (use proceed() to continue the chained execution), resuming your\n own afterwards.\n\n* Exception: Use this one to be called when an aspected\n method throws an exception.\n\n* Can apply aspects to parent classes\n\nSee this article for more information: \nhttp://marcelog.github.com/articles/ding_php_aop_aspect_oriented_programming.html\n--------------------------------------------------------------------------------\nMVC\n===\nThe mvc is work in progress, but you can sneak peek it in docs/examples/mvc. \nYou will need a rewrite rule, like (for lighttpd): \n\n  url.rewrite-if-not-file = (\n    \".*\\?(.*)$\" =\u003e \"/example.php?$1\",\n    \"\" =\u003e \"/example.php\"\n  )\n  \nFor Apache:\nRewriteRule ^(.*)$ /example.php/$1\n\nThe example is mapped to /Some/Mapped/Path/MyController/some (hint: try it with\n?optional=value). If you press the button, the form will be submitted and handled by another\naction that will print the same data, but now for the post instead of the\ninitial get.\n\nAlso, if you want to trigger an exception to see the exception handler in\naction, point your browser to: /Some/Mapped/Path/MyController/someException\n\nTo try a redirect (no view render, just headers sent), point your browser to \n/Some/Mapped/Path/MyController/redirect\nThis uses an http header 302.\n\nTo try an internal redirect (forward), point your browser to \n/Some/Mapped/Path/MyController/forward.\nThis will internally forward the request to another controller/action.\n\nTo try annotated controllers (see below), point your browser to \n/Some/Mapped/Path/MyAnnotatedController/an.\n\nMVC Annotations\n---------------\n\nYou can use @Controller and @RequestMapping in your classes and not declare\nthem in beans.xml file. see docs/examples/mvc/annotatedController\n\nYou can also use Twig to render the views. see docs/examples/mvc-twig\nYou can also use Smarty to render the views. see docs/examples/mvc-smarty\n\nPre And Post Dispatch Interceptors\n----------------------------------\nYou can hook before dispatching a request to a controller and also after. A\ndispatcher will chain all preHandle() and postHandle() from all the \nIHandlerInterceptor you configure.\n\nA preHandle() interceptor returning true will continue the chain execution. To\nstop the chained execution, false can be returned, and also a ModelAndView\n(thus, triggering redirects, view renders, etc).\n\nYou can find an example in docs/examples/mvc-interceptors\n--------------------------------------------------------------------------------\nTCPClient\n=========\nYou can use the helper TCPClientHelper as just another bean. Via callbacks and\ncombining the helpers for error and signal handling, you can easily create a\nvery complete tcp client, using non blocking sockets. Available callbacks:\n* Before the connection.\n* As soon as the connection establishes\n* If the connection failed because of a timeout.\n* When data is available to be read.\n* When the connection is closed by either one of the peers.\n\nYou can specify the connection timeout, the read timeout (both in milliseconds)\nand the minimum needed bytes in the socket before considering it as available\ndata to be read.\n\nsee docs/examples/tcp for an example of use.\n\nWhen using non blocking connects, be aware that php will call your error\nhandler with an \"operation in progress\" message that is completely normal but\nit seems there is no way to disable it without interferring with other \nmessages :(\n--------------------------------------------------------------------------------\nTCPServer\n=========\nYou can use the helper TCPServerHelper as just another bean. Via callbacks and\ncombining the helpers for error and signal handling, you can easily create a\nvery complete tcp server, using non blocking sockets. Available callbacks:\n* Before opening the socket.\n* Before binding and listening the socket.\n* As soon as a connection establishes or closes.\n* When data is available to be read.\n* When the connection is closed by either one of the peers.\n* When there is a read timeout on any of the clients.\n\nYou can specify the connection timeout, the read timeout (both in milliseconds)\nand the minimum needed bytes in the socket before considering it as available\ndata to be read.\n\nsee docs/examples/tcp for an example of use.\n--------------------------------------------------------------------------------\nError Handling\n==============\nIf you declare a bean to listen for event \"dingError\", it will be called\nwhen the container receives an error (same effect as using set_error_handler()\nby yourself, only much easier!)\n--------------------------------------------------------------------------------\nSignal Handling\n===============\nIf you declare a bean to listen for event \"dingSignal\", it will be called\nwhen the container receives a signal, the signal number will be passed as\nthe argument. Only available for SAPI's cli and cgi. Requires the pcntl\nextension.\n--------------------------------------------------------------------------------\nShutdown Handling\n=================\nIf you declare a bean to listen for event \"dingShutdown\", it will be called\nwhen the container shutdowns (same effect as using\nregister_shutdown_function()).\n--------------------------------------------------------------------------------\nHttpSession\n===========\nA helper so you can access the session from the mvc. You can setAttribute()'s\nand getAttribute()'s, destroy() it, etc. See the mvc example.\n--------------------------------------------------------------------------------\nPAMIHelper\n==========\nThis helper integrates PAMI (https://github.com/marcelog/PAMI) with Ding, \noffering a quick, easy, and effective way to access and manager asterisk\ninstallations via the asterisk manager interface (ami). \n\nSee: docs/examples/pami\n--------------------------------------------------------------------------------\nPAGIHelper\n==========\nThis helper integrates PAGI (https://github.com/marcelog/PAGI) with Ding, \noffering a quick, easy, and effective way to make agi (Asterisk Gateway\nInterface) applications (PrePaid systems, voicemail's, etc). \n\nSee: docs/examples/pagi\n\nIn order to run the example, you need something like this in your dialplan:\n\n[default]\nexten =\u003e _X,1,AGI(/tmp/Ding/docs/examples/pagi/run.sh,a,b,c,d)\nexten =\u003e _X,n,Hangup\n\nCall to extension 1 and extension 2 (modify the example if you want another\nextensions). Use other digit to invoke the default extension.\n--------------------------------------------------------------------------------\nSyslog\n======\nTry the SyslogHelper to easily add syslogging to your own application.\nSee docs/examples/syslog.\n--------------------------------------------------------------------------------\nIntegration with other frameworks\n=================================\nSee our doctrine2 integration:\nhttps://github.com/marcelog/Ding/tree/master/docs/examples/doctrine\n--------------------------------------------------------------------------------\nDevelopers\n==========\n* build.xml is a phing build file, not ant.\n* It's very possible that you may need to edit build.properties.\n* Available main targets: all, build, test, report.\n* Tools run: phpdoc, phploc, phpcs, phpmd, phpcpd, phpdepend, phpunit.\n* Setup your installation by editing pear and php paths in build.properties\n* Run phing install-dependencies this will install pear and everything needed\nto run ding tests and metrics.\n* Run phing all\n--------------------------------------------------------------------------------\nDebugging, logging\n==================\nYou need log4php (http://logging.apache.org/log4php/).\nJust make sure you copy it to the include_path and Ding will pick it up from there.\n\nOf course it is recommended that you do not set DEBUG output in your log4php\nconfiguration (or remove it from the include path so Ding will notice and not\nuse it). This *will* create a difference in performance.\n--------------------------------------------------------------------------------\nPerformance tips\n================\n* Try to have small include paths. Ding will use the include path for finding\nresources and autoload your own classes.\n* Configure the rootLogger and ding logger in ERROR level.\n* If your code is running on the php module for apache or iis, use apc for\nall the cache subsytems. Otherwise, use memcached or file.\n* Do not use annotations at all. Only use the XML or even better, YAML.\n* If you are using annotations (good for you! just dont abuse ;)) use the\nannotations cache with apc or memcached or file (in that order).\n* Do not abuse the aop feature.\n--------------------------------------------------------------------------------\n Collaborators:\n ============\nagvstin | agu.gutierrez@gmail.com\n--------------------------------------------------------------------------------\nThanksTo\n--------\njonathaningram for his issue reports.\nBinPress and all the people involved in the 2011 BinPress Programming Contest.\nValery Dubrava for his thoughts, contributions and useful ideas.\nAlberto Sanchez (jaehoo)\n--------------------------------------------------------------------------------\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelog%2Fding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcelog%2Fding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelog%2Fding/lists"}