Skip to content

Commit

Permalink
Merge pull request #62 from fduarte42/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
lochmueller committed Jun 20, 2016
2 parents cba17a0 + 82d716b commit 7e6a63b
Show file tree
Hide file tree
Showing 615 changed files with 84,122 additions and 206 deletions.
1 change: 1 addition & 0 deletions Classes/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Loader implements SingletonInterface
'TypeConverter',
'BackendLayout',
'SoapServer',
'JsonServer',
'LanguageOverride',
'Icon',
'Gridelement',
Expand Down
83 changes: 83 additions & 0 deletions Classes/Loader/JsonServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Loading JsonServer
*
* @author Tim Lochmüller
* @author Tito Duarte <duartito@gmail.com>
*/

namespace HDNET\Autoloader\Loader;

use HDNET\Autoloader\Loader;
use HDNET\Autoloader\LoaderInterface;
use HDNET\Autoloader\Utility\ClassNamingUtility;
use HDNET\Autoloader\Utility\FileUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Loading JsonServer
*/
class JsonServer implements LoaderInterface
{

/**
* Get all the complex data for the loader.
* This return value will be cached and stored in the database
* There is no file monitoring for this cache
*
* @param Loader $autoLoader
* @param int $type
*
* @return array
*/
public function prepareLoader(Loader $autoLoader, $type)
{
$servicePath = ExtensionManagementUtility::extPath($autoLoader->getExtensionKey()) . 'Classes/Service/Json/';
$serviceClasses = FileUtility::getBaseFilesRecursivelyInDir($servicePath, 'php');

$info = [];
foreach ($serviceClasses as $service) {
$serviceClass = ClassNamingUtility::getFqnByPath(
$autoLoader->getVendorName(),
$autoLoader->getExtensionKey(),
'Service/Json/' . $service
);
$info[lcfirst($service)] = $serviceClass;
}

return $info;
}

/**
* Run the loading process for the ext_tables.php file
*
* @param Loader $autoLoader
* @param array $loaderInformation
*
* @return NULL
*/
public function loadExtensionTables(Loader $autoLoader, array $loaderInformation)
{
foreach ($loaderInformation as $key => $class) {
$GLOBALS['TYPO3_CONF_VARS']['AUTOLOADER']['Json'][$key] = $class;
}
return null;
}

/**
* Run the loading process for the ext_localconf.php file
*
* @param Loader $autoLoader
* @param array $loaderInformation
*
* @return NULL
*/
public function loadExtensionConfiguration(Loader $autoLoader, array $loaderInformation)
{
foreach ($loaderInformation as $key => $class) {
$GLOBALS['TYPO3_CONF_VARS']['AUTOLOADER']['Json'][$key] = $class;
}
return null;
}
}
124 changes: 124 additions & 0 deletions Classes/Service/JsonServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

/**
* Json server handling
*
* @author Tim Lochmüller
* @author Tito Duarte <duartito@gmail.com>
*/

namespace HDNET\Autoloader\Service;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use Zend\Json\Server\Server;
use Zend\Json\Server\Smd;


/**
* Json server handling
*/
class JsonServer
{

/**
* Server key
*
* @var string
*/
protected $serverKey = '';

/**
* Server class
*
* @var string
*/
protected $serverClass = '';

/**
* Check if the WSDL should rendered
*
* @var bool
*/
protected $renderSmd = false;

/**
* Build up the object
*
* @param string $server
* @param boolean $smd
* @todo move to hook logic
*/
public function __construct($server, $smd)
{
$this->serverKey = $server;
if (isset($GLOBALS['TYPO3_CONF_VARS']['AUTOLOADER']['Json'][$server])) {
$this->serverClass = $GLOBALS['TYPO3_CONF_VARS']['AUTOLOADER']['Json'][$server];
}
$this->renderSmd = (bool)$smd;
}

/**
* Handle the request
*/
public function handle()
{
header('Content-Type: application/json');
if (!class_exists($this->serverClass)) {
$server = new Server();
$server->fault(
'No valid server class name for the given server key: "' . $this->serverClass . '"',
2342358923745
);
return;
}
if ($this->renderSmd) {
$this->renderSmd();
} else {
$this->handleRequest();
}
}

/**
* Handle the service request
*/
protected function handleRequest()
{
$server = new Server();

$server->setClass($this->serverClass);
try {
$server->handle();
} catch (\Exception $ex) {
$server->fault($ex->getMessage(), $ex->getCode());
}
}

/**
* Handle the SMD request
*/
protected function renderSmd()
{
$server = new Server();
$server->setClass($this->serverClass);

$smd = $server->getServiceMap();
$smd->setTarget($this->getServiceUri());
$smd->setEnvelope(Smd::ENV_JSONRPC_2);

echo $smd;
}

/**
* Get the Service URI
*
* @return string
*/
protected function getServiceUri()
{
$uri = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
$parts = parse_url($uri);
$parts['query'] = 'eID=JsonServer&amp;server=' . $this->serverKey;
return HttpUtility::buildUrl($parts);
}
}
1 change: 1 addition & 0 deletions Classes/Service/SoapServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use TYPO3\CMS\Core\Utility\HttpUtility;
use WSDL\WSDLCreator;


/**
* Soap server handling
*/
Expand Down
5 changes: 4 additions & 1 deletion Resources/Private/Contrib/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"require": {
"piotrooo/wsdl-creator": "1.4.2"
"piotrooo/wsdl-creator": "1.4.2",
"zendframework/zend-http": "2.*",
"zendframework/zend-server": "2.*",
"zendframework/zend-json": "2.*"
}
}

0 comments on commit 7e6a63b

Please sign in to comment.