Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bigperson/exchange1c
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Kartsev committed Oct 19, 2018
2 parents 9388390 + a2f0759 commit fdd7876
Show file tree
Hide file tree
Showing 37 changed files with 1,880 additions and 1,845 deletions.
113 changes: 56 additions & 57 deletions examples/exchange1c.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
<?php
/**
* This file is part of bigperson/exchange1c package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

require_once './../vendor/autoload.php';

$configValues = [
'import_dir' => '1c_exchange',
'login' => 'admin',
'password' => 'admin',
'use_zip' => false,
'file_part' => 0,
'models' => [
\Bigperson\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class,
\Bigperson\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class,
\Bigperson\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class,
],
];
$config = new \Bigperson\Exchange1C\Config($configValues);
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$modelBuilder = new \Bigperson\Exchange1C\ModelBuilder();
$loaderService = new \Bigperson\Exchange1C\Services\FileLoaderService($request, $config);
$authService = new \Bigperson\Exchange1C\Services\AuthService($request, $config);
$categoryService = new \Bigperson\Exchange1C\Services\CategoryService($request, $config, $dispatcher, $modelBuilder);
$offerService = new \Bigperson\Exchange1C\Services\OfferService($request, $config, $dispatcher, $modelBuilder);
$catalogService = new \Bigperson\Exchange1C\Services\CatalogService($request, $config, $authService, $loaderService, $categoryService, $offerService);


$mode = $request->get('mode');
$type = $request->get('type');

try {
if ($type == 'catalog') {
if (!method_exists($catalogService, $mode)) {
throw new Exception('not correct request, mode=' . $mode);
}
$body = $catalogService->$mode();
$response = new \Symfony\Component\HttpFoundation\Response($body, 200, ['Content-Type', 'text/plain']);
$response->send();
} else {
throw new \LogicException(sprintf('Logic for method %s not released', $type));
}
} catch (\Exception $e) {
$body = "failure\n";
$body .= $e->getMessage() . "\n";
$body .= $e->getFile() . "\n";
$body .= $e->getLine() . "\n";

$response = new \Symfony\Component\HttpFoundation\Response($body, 500, ['Content-Type', 'text/plain']);
$response->send();
}
<?php
/**
* This file is part of bigperson/exchange1c package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

require_once './../vendor/autoload.php';

$configValues = [
'import_dir' => '1c_exchange',
'login' => 'admin',
'password' => 'admin',
'use_zip' => false,
'file_part' => 0,
'models' => [
\Bigperson\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class,
\Bigperson\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class,
\Bigperson\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class,
],
];
$config = new \Bigperson\Exchange1C\Config($configValues);
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$modelBuilder = new \Bigperson\Exchange1C\ModelBuilder();
$loaderService = new \Bigperson\Exchange1C\Services\FileLoaderService($request, $config);
$authService = new \Bigperson\Exchange1C\Services\AuthService($request, $config);
$categoryService = new \Bigperson\Exchange1C\Services\CategoryService($request, $config, $dispatcher, $modelBuilder);
$offerService = new \Bigperson\Exchange1C\Services\OfferService($request, $config, $dispatcher, $modelBuilder);
$catalogService = new \Bigperson\Exchange1C\Services\CatalogService($request, $config, $authService, $loaderService, $categoryService, $offerService);

$mode = $request->get('mode');
$type = $request->get('type');

try {
if ($type == 'catalog') {
if (!method_exists($catalogService, $mode)) {
throw new Exception('not correct request, mode='.$mode);
}
$body = $catalogService->$mode();
$response = new \Symfony\Component\HttpFoundation\Response($body, 200, ['Content-Type', 'text/plain']);
$response->send();
} else {
throw new \LogicException(sprintf('Logic for method %s not released', $type));
}
} catch (\Exception $e) {
$body = "failure\n";
$body .= $e->getMessage()."\n";
$body .= $e->getFile()."\n";
$body .= $e->getLine()."\n";

$response = new \Symfony\Component\HttpFoundation\Response($body, 500, ['Content-Type', 'text/plain']);
$response->send();
}
Loading

0 comments on commit fdd7876

Please sign in to comment.