| 784 | | <para></para> |
| | 784 | <para>Agavi is an OOP application framework. All Agavi |
| | 785 | applications, at least where they communicate with Agavi, |
| | 786 | consist of classes and configuration. Configuration is the glue |
| | 787 | between different components of your application. Much of what |
| | 788 | would be expressed as code in other cases is expressed as |
| | 789 | configuration in Agavi.</para> |
| | 790 | |
| | 791 | <para>To achieve such kind of flexibility, Agavi provides and |
| | 792 | uses an XML-to-PHP compiler which serves as the configuration |
| | 793 | engine for the framework and its applications. The configuration |
| | 794 | engine is smart about XML files and reads them only when needed, |
| | 795 | most of the time relying on the compiled PHP code instead. Note |
| | 796 | that despite being quite an advanced feat for a PHP application, |
| | 797 | this engine is in principle replaceable.</para> |
| | 798 | |
| | 799 | <para>Before further discussion ensues, it must be made clear |
| | 800 | that when this manual makes reference to Agavi and Agavi |
| | 801 | applications, it does so relating to the stock Agavi framework |
| | 802 | configuration. Many Agavi components can be replaced, and some |
| | 803 | are replaced often by application developers wishing to |
| | 804 | implement unique features specific to their particular |
| | 805 | project. Stock Agavi is an MVC Web application framework, but it |
| | 806 | can be reconfigured for applications that transcend both MVC and |
| | 807 | Web. The manual does not make attempts at guessing towards the |
| | 808 | extent of these use cases and refers specifically to your usual, |
| | 809 | as-from-the-box framework and Web applications.</para> |
| | 810 | |
| | 811 | <para>Agavi encompasses your application and serves as the |
| | 812 | dispatcher and the front controller for it. The core logic of |
| | 813 | your application (domain logic) is expressed as a freeform API |
| | 814 | through Models, which are invoked by your Actions (Controllers) |
| | 815 | and Views. When a Web request arrives, Agavi selects and |
| | 816 | executes Actions relevant for that request; every Action names a |
| | 817 | View that should be responsible for its output; the resulting |
| | 818 | output is collected and returned to the client. Some Actions can |
| | 819 | be empty and only their View counterparts would be |
| | 820 | processed.</para> |
| | 821 | |
| | 822 | <para>Actions are determined through Routing, which is an |
| | 823 | extremely powerful mechanism for mapping Web requests (and any |
| | 824 | kind of requests in general) to Actions. One request may require |
| | 825 | more than one Action to execute and render its output. For this |
| | 826 | reason, a general response layout management mechanism and a |
| | 827 | layered output mechanism is provided to your application.</para> |
| | 828 | |
| | 829 | <para>Note that unlike most of other frameworks, especially |
| | 830 | Rails and it's sprout-offs, <emphasis>Agavi makes a clear |
| | 831 | distinction between views and templating, and between models and |
| | 832 | database</emphasis>. In Agavi, the templating mechanism is |
| | 833 | abstracted away through adapters to the point a single |
| | 834 | application can successfully use different templating engines |
| | 835 | simultaneosly - even on the same page. You can connect any |
| | 836 | template library - or any template source - as one of the |
| | 837 | rendering mechanisms used in your Agavi application. Same goes |
| | 838 | for models: an Agavi Model is just an empty class. Agavi does |
| | 839 | not have its own database library, instead providing a global |
| | 840 | database connection service to your application, including an |
| | 841 | unified configuration mechanism and adapter classes for |
| | 842 | different fashions of talking to databases. You can use your |
| | 843 | custom database library or grab a third party one. Doctrine and |
| | 844 | Propel are especially nice when working hand-in-hand with Agavi |
| | 845 | mentality. The point is, you have the choice, and Agavi Models |
| | 846 | in no way imply "database".</para> |
| | 847 | |
| | 848 | <para>Agavi is environment and execution path. As an |
| | 849 | environment, it provides configuration and a way to communicate |
| | 850 | with the outside world. As an execution path, it provides a |
| | 851 | predictable flow of events, facilitated through it's front-end |
| | 852 | routing/dispatching facilities. These are assured through |
| | 853 | Filters, which are plugins that are executed by |
| | 854 | FilterChains. Filters are actually responsible for most of |
| | 855 | Agavi's internal logic. As everything else in Agavi, they are |
| | 856 | replaceable.</para> |
| | 857 | |
| | 858 | <para>Additionally, Agavi has support facilities: security and |
| | 859 | validation, handling of multiple request and response types, a |
| | 860 | Form Population Filter (an unique Agavi feature), |
| | 861 | internationalization and localization features, logging, ways to |
| | 862 | express your application as a Web API to the rest of the world, |
| | 863 | facilities to hook up third party libraries, session management |
| | 864 | and persistent storage, caching and a bunch of other |
| | 865 | helpful tools that make your life so much easier.</para> |
| 796 | | <para>models and global models</para> |
| | 904 | <para>Models are where your application actually takes |
| | 905 | place. Actions and Views are just user interface glue that maps |
| | 906 | UI requests to actual things that happen inside your |
| | 907 | application. Agavi Models are completely unrelated to database; |
| | 908 | thus, in an Agavi application, you may have two different kinds |
| | 909 | of models: the Agavi Models, which are wrappers around your |
| | 910 | domain logic, and the application's models, which may or may not |
| | 911 | be additional levels of indirection, with or without ORM or any |
| | 912 | other persistence, and with or without any database access at |
| | 913 | all. Agavi deals exclusively with its own high level Models. The |
| | 914 | difference is easy to illustrate on an imaginary reporting |
| | 915 | application that needs to render reports into PDFs and email |
| | 916 | them to users: one Model would be dealing with creating a |
| | 917 | Report, one would know how to convert it to PDF, and the final |
| | 918 | one would know how to email people. Actions and Views would glue |
| | 919 | the whole thing together.</para> |
| 798 | | <para>config files</para> |
| | 921 | <para>The central place of your application is the configuration |
| | 922 | files. The configuration files let Agavi know what goes where in |
| | 923 | your applications. Most of things in Agavi are configurable: for |
| | 924 | instance, your configuration defines whether the application is |
| | 925 | active or not, is in debug mode or not, what to do when a |
| | 926 | security problem occurs, how to arrange your log files, how to |
| | 927 | perform localization, translation, validation of actions and |
| | 928 | many other aspects of your applications. Agavi solves most of |
| | 929 | the typical Web application problems for you, and all you need |
| | 930 | to do is to describe the solution. The XML configuration files |
| | 931 | are not actually examined on every request: they are compiled |
| | 932 | into PHP code and stored in the cache. The configuration engine, |
| | 933 | together with Agavi's autoloading and factory mechanisms, |
| | 934 | provides a generic way to spawn objects and glue them together.</para> |