Quark
Quark is a PHP SaaS framework, designed for using in complex projects.
Requirements
PHP version 5.4 or higher NginX + php-fpm or Apache + mod-rewrite + mod-phpAdditional
Some parts (especially data providers) may require additional PHP extensions. The list of core extensions is represented in wiki.
Let's go!
Let's create simple HelloWorld.
First of all, we need to understand the best project file structure (D - directory, F - file):
[D] Services
[D] Models
[D] ViewModels
[D] Views
[D] storage
[D] static
[D] runtime
[F] .gitignore
[F] .htaccess
[F] index.php
Depending on project type, there can be no folders such as ViewModels
, Views
and static
, or storage
. The .htaccess
can be found in Quark repository. Of course, if You use NginX
+php-fpm
You need to put rewrite rule in your virtual host configuration.
In the .gitignore
can be runtime
and index.php
Now, let's take a look of index.php
. Minimal required set is:
<?php include '/path/to/quark/Quark.php'; use QuarkQuark; use QuarkQuarkConfig; $config = new QuarkConfig(); Quark::Run($config);
In this file You can configure all DataProviders
, AuthProviders
, Extensions
and application settings.
Let's create first service. Name convention requires that all services need to match the rule:
[any valid string with first letter in uppercase]Service
Example: IndexService
, CreateService
, MySuperService
etc.
Filenames of services must be formed as service' class name + .php
. E.g.: IndexService.php
, CreateService.php
, MySuperService.php
etc.
Services are atomic point of processing, therefore they contains only HTTP-methods hooks and auth settings.
Simple service which responds on GET requests at /
web path can look like this:
<?php namespace Services; use QuarkIQuarkGetService; use QuarkQuarkDTO; use QuarkQuarkSession; /** * Class IndexService * * @package Services */ class IndexService implements IQuarkGetService { /** * @param QuarkDTO $request * @param QuarkSession $session * * @return mixed */ public function Get (QuarkDTO $request, QuarkSession $session) { echo 'Hello World!'; } }
Put this code at file IndexService.php
and put it into the root of Services
directory. Your first service already done =)
As You can see, we've implemented IQuarkGetService
, which indicates that this service have hook for GET request. In Quark core also defined IQuarkPostService
. Other method services are deprecated for using in applications, that doesn't require support of WebDAV
, by security reasons.
For WebDAV applications there are many interfaces in
ExtensionsQuarkWebDAV
What's next?
As was sayed in the beginning, Quark was designed for using in complex web applications, that can be used such REST APIs. Of course, any API app need some communication data protocol (e.g. JSON). For this reasons, in main package is defined IQuarkIOProcessor
and some common processors (QuarkJSONIOProcessor
, QuarkXMLIOProcessor
, etc.).
Let's create a service, named HelloService
, which will respond with JSON string of {"hello":"world"}
:
<?php namespace Services; use QuarkIQuarkGetService; use QuarkIQuarkServiceWithCustomProcessor; use QuarkQuarkDTO; use QuarkQuarkSession; /** * Class HelloService * * @package Services */ class HelloService implements IQuarkGetService, IQuarkServiceWithCustomProcessor { /** * @return IQuarkIOProcessor */ public function Processor () { return new QuarkJSONIOProcessor(); } /** * @param QuarkDTO $request * @param QuarkSession $session * * @return mixed */ public function Get (QuarkDTO $request, QuarkSession $session) { return array( 'hello' => 'world' ); } }
As You can see, we only defined the data processor for this service and returned data, which need to be processed. Simple =)
Quark allows to define different processors for request and response. All what is need to do - implementing of corresponding interfaces
And that is only beginning!
More info about Quark parts can be found in Wiki.
Open source blog platform, based on Quark https://github.com/Qybercom/Thinkscape
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。