simpleserv/webfiles-framework

This package is abandoned and no longer maintained. The author suggests using the webfiles-framework/framework package instead.

v0.3.0-alpha 2021-07-31 20:53 UTC

README

https://www.webfiles-framework.org/

Join the chat at https://gitter.im/sebastianmonzel/webfiles-framework-php Build status Code Climate Test Coverage

Api-Documentation: http://sebastianmonzel.github.io/webfiles-framework-php-api/
Documentation: http://sebastianmonzel.github.io/webfiles-framework-php-doc/ (github-repo)
Packagist: https://packagist.org/packages/webfiles-framework/framework

Access and describe data in a generalized way. Interact with remote data.
developer & contact: Sebastian Monzel (mail@sebastianmonzel.de)

What is webfiles framework for?

The purpose of webfiles framework is to provide a lightweight libary to interoperate with data on a standarized way: the webfiles.

The webfiles framework generalizes data access to database system, to file system and accessing data on the remote site. Through an webfile definition and the standarized api you can access the different systems in the same way.

First Steps

  • add webfiles-framework as dependency webfiles-framework/framework to your composer.json
  • define your datastucture as webfile definition
  • save and read data in database or filesystem via the datastore api

Sample use cases

Define your first webfile definition

use webfilesframework\core\datasystem\file\format\MWebfile;

class Contact extends MWebfile
{

    private $m_sFirstname; // attributes has to be in the given scheme - all attributes with "m_" as prefix gets persisted - "s" defines the type of the attribute (string)
    private $m_sLastname;
    private $m_sCity;

    
    public function setFirstname($m_sFirstname)
    {
        $this->m_sFirstname = $m_sFirstname;
    }
    
    public function getFirstname()
    {
        return $this->m_sFirstname;
    }

    public function setLastname($m_sLastname)
    {
        $this->m_sLastname = $m_sLastname;
    }
    
    public function getFirstname()
    {
        return $this->m_sFirstname;
    }

    public function setCity($m_sCity)
    {
        $this->m_sCity = $m_sCity;
    }
    
    public function getCity($m_sCity)
    {
        $this->m_sCity = $m_sCity;
    }

}

Store a webfile in a datastore:

via directory:

<?php
use webfilesframework\core\datastore\types\directory\MDirectoryDatastore;
use webfilesframework\core\datasystem\file\system\MDirectory;

$directoryDatastore = new MDirectoryDatastore(new MDirectory("yourDirectoryToStoreWebfiles"));
$contact = new Contact();
$contact->setId(1);
$contact->setFirstname("Sebastian");
$contact->setLastname("Monzel");

$directoryDatastore->storeWebfile($contact);

or via database:

<?php
use webfilesframework\core\datastore\types\directory\MDirectoryDatastore;
use webfilesframework\core\datasystem\file\system\MDirectory;

$databaseDatastore = new MDatabaseDatastore(
                          new MDatabaseConnection(
                              "localhost",
                              "yourDatabaseToStoreWebfiles",
                              "tablePrefixInDatabaseForActualDatastore", // will add this string before every created table name 
                              "username",
                              "password"
                              )
                      );
$contact = new Contact();
$contact->setFirstname("Sebastian");
$contact->setLastname("Monzel");

$databaseDatastore->storeWebfile($contact);

Read from DirectoryDatastore

<?php
use webfilesframework\core\datastore\types\directory\MDirectoryDatastore;
use webfilesframework\core\datasystem\file\system\MDirectory;

$directoryDatastore = new MDirectoryDatastore(new MDirectory("yourDirectoryToStoreWebfiles"));
$directoryDatastore->getAllWebfiles();

Read from DatabaseDatastore (actually mysql only)

<?php
use webfilesframework\core\datastore\types\database\MDatabaseDatastore;
use webfilesframework\core\datasystem\database\MDatabaseConnection;

$databaseDatastore = new MDatabaseDatastore(
    new MDatabaseConnection(
        "localhost",
        "yourDatabaseToStoreWebfiles",
        "tablePrefixInDatabaseForActualDatastore", // will add this string before every created table name 
        "username",
        "password"
        )
);
$databaseDatastore->getAllWebfiles();

Search by template in a datastore

TODO

Transfer data from one datastore to another

<?php
use webfilesframework\core\datastore\types\directory\MDirectoryDatastore;
use webfilesframework\core\datasystem\file\system\MDirectory;
use webfilesframework\core\datastore\MDatastoreTransfer;

$source = new MDirectoryDatastore(new MDirectory("sourceDir"));
$target = new MDatabaseDatastore(new MDatabaseConnection("localhost","wonderfulDatabasename","mytableprefix","myuser","mypassword"));

$datastoreTransfer = new MDatastoreTransfer($source, $target);
$datastoreTransfer->transfer();

Read from RemoteDatastore

You can make a datastore accessible from remote via http(s). MRemoteDatastoreEndpoint encapsulates the datastore to make it accessible. On the other site you can use MRemoteDatastore to access the encapsulated datastore.

Serverside to provide access to the datastore:

<?php
use webfilesframework\core\datastore\types\remote\MRemoteDatastoreEndpoint; 
use webfilesframework\core\datastore\types\directory\MDirectoryDatastore;
use webfilesframework\core\datasystem\file\system\MDirectory;

$remoteDatastoreEndpoint = new MRemoteDatastoreEndpoint(
    new MDirectoryDatastore(new MDirectory("localDirectory"))
);
$remoteDatastoreEndpoint->handleRemoteCall();

Clientside to access the datastore:

<?php
use webfilesframework\core\datastore\types\remote\MRemoteDatastore;

// url on which the method $remoteDatastoreEndpoint->handleRemoteCall(); is reachable:
$datastoreUrl = "http://localhost:1234/datastore/";

$remoteDatastore = new MRemoteDatastore($datastoreUrl);
$remoteDatastore->getAllWebfiles();