GithubHelp home page GithubHelp logo

kuzzleio / sdk-php Goto Github PK

View Code? Open in Web Editor NEW
6.0 13.0 1.0 1.18 MB

Official php SDK for Kuzzle

Home Page: http://docs.kuzzle.io/sdk-reference

License: Apache License 2.0

PHP 100.00%
kuzzle-sdk php kuzzle swig offline-first

sdk-php's Introduction

Build Status codecov.io

Official Kuzzle PHP SDK

About Kuzzle

A backend software, self-hostable and ready to use to power modern apps.

You can access the Kuzzle repository on Github

SDK Documentation

The complete SDK documentation is available here

Installation

This SDK can be used in any project using composer:

composer require kuzzleio/kuzzle-sdk

Basic usage

<?php

use \Kuzzle\Kuzzle;
use \Kuzzle\Document;

$kuzzle = new Kuzzle('localhost');
$collection = $kuzzle->collection('bar', 'foo');

$firstDocument = new Document($collection, 'john', ['name' => 'John', 'age' => 42]);
$secondDocument = new Document($collection, 'michael', ['name' => 'Michael', 'age' => 36]);

$firstDocument->save(['refresh' => 'wait_for']);
$secondDocument->save(['refresh' => 'wait_for']);

$result = $collection->search(['sort' => [['age' => 'asc']]]);
foreach ($result->getDocuments() as $document) {
    $content = $document->getContent();
    echo "Name: {$content['name']}, age: {$content['age']}\n";
}

Running Tests

php ./vendor/bin/phpcs -p -n --standard=PSR2 src
php ./vendor/bin/phpunit

License

Apache 2

sdk-php's People

Contributors

alexandrebouthinon avatar aschen avatar benoitvidis avatar berthieresteban avatar dbengsch avatar jenow avatar samniisan avatar scottinet avatar stafyniaksacha avatar tyki avatar xbill82 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

vkey

sdk-php's Issues

Support Plugins Routes

Hello,

I need to use query() function in SDK PHP to call my custom plugin routes.
To do this I must update routes.json file... I think it's not a good solution.

Perhaps add a method to add custom Routes ?

Cheers,

Debug mode

Implement a debug mode to retrieve requests history between kuzzle-sdk & kuzzle

Factory methods and class names refactoring

After a long discussion, we decided to rename some methods and class names in the Kuzzle SDKs.

Class Names

  • KuzzleDataCollection 👉 Collection
  • KuzzleDataMapping 👉 CollectionMapping

Methods

  • dataCollectionFactory 👉 collection
  • dataMappingFactory 👉 collectionMapping
  • roleFactory 👉 role
  • profileFactory 👉 profile
  • userFactory 👉 user
  • documentFactory 👉 document
  • getRole 👉 fetchRole
  • getProfile 👉 fetchProfile
  • getUser 👉 fetchUser

Subscription Management API

  • subscribe/list returns a list of the existing subscription rooms
  • admin/removeRooms removes a list of rooms. Takes a mandatory collection name and optionnal array of room IDs.
  • join joins a specific room by ID

Problem with insert

Hi,

I have a problem to create a document with PHP-SDK. The exception message is :

"ErrorException' with message '[mapper_parsing_exception] failed to parse".

I have compared data's type with the collection mapping : it's correct. I tried to create my document directly in BO : OK. I tried with a REST request (with POSTMAN) and the document have been created. It's the first time I can't create a document with PHP SDK.
Our JSON

{       
       "id":45,
        "title":"Test daily tip",
        "status":1,"type_message":6,
        "challengeInstanceId":null,
        "theme":"Message de f\u00e9licitations et renforcement",
        "userId":410,
        "date":"2016-08-05 12:25:34",
        "programDate":null,
        "subTheme":"Bilan quotidien",
        "catchPhrase":"accroche test daily tip",
        "addText":"texte test daily tip",
        "body":"did you know test daily tip",
        "messageId":"daily_tip_in_progress",
        "icon":"",
        "fromUserId":null,
        "notifId":null,
        "notifText":null,
        "notifState":null,
        "notifParams":null
}

In PHP :

$this->kuzzle->save($message, $this->container->getParameter('kuzzle.index'));
    /**
     * @param AbstractKuzzleDocument $document
     * @param $index
     * @return AbstractKuzzleDocument
     */
    public function save(AbstractKuzzleDocument $document, $index)
    {
        $collection = $document::getKuzzleCollectionName();
        if (is_null($document->getKuzzleId())) {
            return $this->create($document, $index, $collection);
        }
        return $this->update($document, $index, $collection);
    }

And method create (in a class who override Kuzzle.php from Symfony-bridge) :

    /**
     * Create a document in Kuzzle from object implementing KuzzleDocumentInterface
     *
     * @param KuzzleDocumentInterface $document
     * @param string $index
     * @param string $collection
     * @return KuzzleDocumentInterface
     */
    public function create(KuzzleDocumentInterface $document, $index, $collection)
    {
        if (method_exists($document, 'setId')) {
            $document->setId($this->getUniqueId($index, $collection));
        }
        var_dump($document->toKuzzleDocument());
        return $document::fromKuzzleDocument(parent::createDocument($document->toKuzzleDocument(), $index, $collection)->serialize());
    }

And parent::createDocument() is the method in Symfony-Kuzzle-Bridge.

Thank you

Implement debug mode

Implement a debug mode to retrieve requests history between kuzzle-sdk & kuzzle

Add missing getters

Could you add getters for "content" and "headers" attributes of the \Kuzzle\Document class ?

Thanks.

Rename the updateIfExist option

Currently, the Collection.createDocument method allows the updateIfExist option. Which does a document replacement if it exists in Kuzzle's database.

Since this option is misleading, and because we may want to add a createOrUpdate API route later, we propose the following:

  • remove the updateIfExist option
  • add a ifExist option, taking the following values: error (default), replace

Allow to connect to Kuzzle via SSL

For the time being, the php sdk forces an http only connection.

We should give the ability to connect to ssl.
Additional configuration options are very likely to be required too:

At the very minimum:

  • ssl version support
  • certificate check (CURLOPT_SSL_VERIFYPEER)

Other CURLOPT_SSLxx may also be required.

Problem with search after bulk import

I have imported my data into back-office from a bulk import in Postman.

Here's an exemple of document (in JSON format):

{
  "type": "Feature",
  "messier_id": "M1",
  "messier_order": 1,
  "properties": {
    "name": "M1",
    "desig": "NGC 1952",
    "alt": "Crab Nebula",
    "alt_fr": "Nébuleuse du crabe",
    "type": "snr",
    "type_label": "Supernova Remnant",
    "mag": 8.4,
    "const_id": "TAU",
    "dim": "6x4",
    "cl": ""
  },
  "geometry": {
    "type": "Point",
    "coordinates": [
      83.625,
      22.0167
    ]
  }
}

All my documents created with bul aven't got "meta" property. So, with kuzzle-php-sdk, when i make a search(), i have this error :

ContextErrorExceptionNotice: Undefined index: _meta
--
in Collection.php (line 70)

image

CreateDocument does not generate an id

When using createDocument method, the id is not automatically generated. Instead a string ':_id' is used as ID of document

Expected Behavior

A UUIDV4 as documentID

Current Behavior

string '_id' as documentID

Possible Solution

Steps to Reproduce

  1. Setup SDK PHP
  2. Get a collection object
  3. Try to create a document without providing the second parameter 'id'

Context (Environment)

Kuzzle 1.5
SDK PHP 3.0.4

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.