cosmos-cms/cosmos-php

The PHP SDK for CosMoS, the universal cms.

dev-master 2018-04-27 17:26 UTC

This package is not auto-updated.

Last update: 2025-04-26 23:10:43 UTC


README

This library is still in beta, just like cosmos-cms.com.

Using this library it's extremely easy to fetch and decrypt your content from CosMoS, The Universal CMS. For detailed documentation, please go to: cosmos-cms.com/docs

Instalation

CosMoS uses Composer to require its dependencies.

composer require "cosmos-cms/cosmos-php"

Setup

Your init.php file.

<?php
// Require the autoload.php file that's generated by Composer
require 'vendor/autoload.php';

// Use the correct namespace for CosMoS
use Cosmos\Cosmos;

// Create a new instance of the Cosmos object
$cosmos = new Cosmos();

// Setup the path to your private key
// This key was only displayed once when your Application was created
$cosmos->setPrivateKey('key.txt');

// Set your API key, which can be found in your Application Settings
$cosmos->setApiKey("9d25d2d0053b22fdfa1b4becdfdfa9a4");

// Give up the path for the folder where your cache files will be stored
$cosmos->setCachePath('cache');

// You can set a custom refresh rate in seconds, default is 1 day
$cosmos->setRefreshRate(60);

Usage

<?php
// Require your bootstrap or init file
require 'init.php';

// Display your content
// In this case the content with API name 'welcome' is fetched from the API or cache
echo $cosmos->get('welcome');

// Display your content's title or type
echo $cosmos->get('welcome')->name();
echo $cosmos->get('welcome')->type(); // Returns either 'html' or 'plain'