GithubHelp home page GithubHelp logo

classicvalues / quark Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qybercom/quark

0.0 1.0 0.0 5.4 MB

PHP SaaS framework

License: GNU Lesser General Public License v3.0

PHP 92.93% JavaScript 5.68% CSS 1.38%

quark's Introduction

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-php

Additional
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 Quark\Quark;
use Quark\QuarkConfig;

$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 Quark\IQuarkGetService;

use Quark\QuarkDTO;
use Quark\QuarkSession;

/**
 * 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 Extensions\Quark\WebDAV

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 Quark\IQuarkGetService;
use Quark\IQuarkServiceWithCustomProcessor;

use Quark\QuarkDTO;
use Quark\QuarkSession;

/**
 * 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

quark's People

Contributors

chief93 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.