Skip to content

Instantly share code, notes, and snippets.

@emodric
Created September 6, 2012 16:17
Show Gist options
  • Save emodric/3658045 to your computer and use it in GitHub Desktop.
Save emodric/3658045 to your computer and use it in GitHub Desktop.
eZ Publish Summer Camp 2012 / REST API v2 examples
<?php
require_once '../bootstrap.php';
$repository = require '../eZ/Publish/Core/REST/common.php';
$section = $repository->getSectionService()->loadSectionByIdentifier( 'standard' );
var_dump( $section );
<?php
require_once '../bootstrap.php';
$repository = require '../eZ/Publish/Core/REST/common.php';
$sectionService = $repository->getSectionService();
$sectionCreate = $sectionService->newSectionCreateStruct();
$sectionCreate->identifier = 'new_section';
$sectionCreate->name = 'New section';
$section = $sectionService->createSection( $sectionCreate );
var_dump( $section );
<?php
require_once '../bootstrap.php';
$repository = require '../eZ/Publish/Core/REST/common.php';
$sectionService = $repository->getSectionService();
$sectionUpdate = $sectionService->newSectionUpdateStruct();
$sectionUpdate->identifier = 'updated_section';
$sectionUpdate->name = 'Updated section';
$section = $sectionService->loadSectionByIdentifier( 'new_section' );
$section = $sectionService->updateSection( $section, $sectionUpdate );
var_dump( $section );
<?php
require_once '../bootstrap.php';
$repository = require '../eZ/Publish/Core/REST/common.php';
$sectionService = $repository->getSectionService();
$section = $sectionService->loadSectionByIdentifier( 'updated_section' );
$sectionService->deleteSection( $section );
try
{
$sectionService->loadSectionByIdentifier( 'updated_section' );
echo "Section {$section->identifier} exists after deleting, someone probably messed up!\n";
}
catch ( Exception $e )
{
echo "Section {$section->identifier} successfully deleted\n";
}
<?php
require_once '../bootstrap.php';
$repository = require '../eZ/Publish/Core/REST/common.php';
$sections = $repository->getSectionService()->loadSections();
var_dump( $sections );
<?php
require_once '../bootstrap.php';
$repository = require '../eZ/Publish/Core/REST/common.php';
$role = $repository->getRoleService()->loadRoleByIdentifier( 'Editor' );
var_dump( $role );
<?php
require_once '../bootstrap.php';
$repository = require '../eZ/Publish/Core/REST/common.php';
$roleService = $repository->getRoleService();
$roleCreate = $roleService->newRoleCreateStruct( 'New role' );
$role = $roleService->createRole( $roleCreate );
var_dump( $role );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment