1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-17 04:40:08 -07:00

Fix coding style

This commit is contained in:
David Hübner 2017-04-16 22:12:58 +02:00
parent e8c225c021
commit 30c4eb8c82
17 changed files with 65 additions and 113 deletions

View File

@ -13,7 +13,6 @@ use AppBundle\Api\Exception\ApiException;
use AppBundle\Api\Exception\AuthenticationFailedException; use AppBundle\Api\Exception\AuthenticationFailedException;
use AppBundle\Api\Exception\CallFailedException; use AppBundle\Api\Exception\CallFailedException;
use AppBundle\Api\Exception\EmptyResponseException; use AppBundle\Api\Exception\EmptyResponseException;
use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Debug\Exception\ContextErrorException; use Symfony\Component\Debug\Exception\ContextErrorException;
class Brickset extends \SoapClient class Brickset extends \SoapClient
@ -79,6 +78,7 @@ class Brickset extends \SoapClient
try { try {
$this->checkApiKey(); $this->checkApiKey();
return $this->__soapCall($method, [$parameters])->{$method.'Result'}; return $this->__soapCall($method, [$parameters])->{$method.'Result'};
} catch (\SoapFault $e) { } catch (\SoapFault $e) {
throw new CallFailedException(ApiException::BRICKSET); throw new CallFailedException(ApiException::BRICKSET);
@ -266,7 +266,7 @@ class Brickset extends \SoapClient
{ {
$parameters['apiKey'] = $this->apiKey; $parameters['apiKey'] = $this->apiKey;
if($this->__soapCall('checkKey', [$parameters])->checkKeyResult != 'OK') { if ($this->__soapCall('checkKey', [$parameters])->checkKeyResult != 'OK') {
throw new AuthenticationFailedException(ApiException::BRICKSET); throw new AuthenticationFailedException(ApiException::BRICKSET);
} }
} }

View File

@ -9,7 +9,6 @@ use AppBundle\Api\Exception\EmptyResponseException;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\ConnectException;
use Symfony\Component\Asset\Exception\LogicException;
class Rebrickable_v3 class Rebrickable_v3
{ {
@ -59,11 +58,11 @@ class Rebrickable_v3
} catch (ClientException $e) { } catch (ClientException $e) {
if ($e->getCode() == 404) { if ($e->getCode() == 404) {
throw new EmptyResponseException(ApiException::REBRICKABLE); throw new EmptyResponseException(ApiException::REBRICKABLE);
} else if ($e->getCode() == 401) { } elseif ($e->getCode() == 401) {
throw new AuthenticationFailedException(ApiException::REBRICKABLE); throw new AuthenticationFailedException(ApiException::REBRICKABLE);
} }
throw new ApiException(ApiException::REBRICKABLE,$e,$e->getCode()); throw new ApiException(ApiException::REBRICKABLE, $e, $e->getCode());
} }
} }
} }

View File

@ -48,15 +48,18 @@ class BricksetManager
return isset($sets[0]) ? $sets[0] : null; return isset($sets[0]) ? $sets[0] : null;
} }
public function getSetInstructions($id) { public function getSetInstructions($id)
{
return $this->bricksetClient->getInstructions($id); return $this->bricksetClient->getInstructions($id);
} }
public function getSetReviews($id) { public function getSetReviews($id)
{
return $this->bricksetClient->getReviews($id); return $this->bricksetClient->getReviews($id);
} }
public function getAdditionalImages($id) { public function getAdditionalImages($id)
{
return $this->bricksetClient->getAdditionalImages($id); return $this->bricksetClient->getAdditionalImages($id);
} }
} }

View File

@ -119,18 +119,19 @@ class RebrickableManager
return $this->serializer->deserialize($data, PartCategory::class, self::FORMAT); return $this->serializer->deserialize($data, PartCategory::class, self::FORMAT);
} }
public function getPartsByLDrawNumber($number) { public function getPartsByLDrawNumber($number)
{
$options = [ $options = [
'query' => [ 'query' => [
'ldraw_id' => $number 'ldraw_id' => $number,
], ],
]; ];
$response = $this->rebrickableClient->call('GET','lego/parts', $options); $response = $this->rebrickableClient->call('GET', 'lego/parts', $options);
$data = json_decode($response, true)['results']; $data = json_decode($response, true)['results'];
return $this->serializer->denormalize($data,Part::class.'[]',self::FORMAT); return $this->serializer->denormalize($data, Part::class.'[]', self::FORMAT);
} }
/** /**

View File

@ -2,13 +2,11 @@
namespace AppBundle\Controller; namespace AppBundle\Controller;
use AppBundle\Entity\LDraw\Model;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
/** /**

View File

@ -28,8 +28,7 @@ class ModelController extends Controller
{ {
$form = $this->get('form.factory')->create(ModelFilterType::class); $form = $this->get('form.factory')->create(ModelFilterType::class);
$filterBuilder = $this->get('repository.ldraw.model') $filterBuilder = $this->get('repository.ldraw.model')->getFilteredQueryBuilder();
->createQueryBuilder('model');
if ($request->query->has($form->getName())) { if ($request->query->has($form->getName())) {
// manually bind values from the request // manually bind values from the request
@ -62,7 +61,7 @@ class ModelController extends Controller
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
if($model = $this->get('manager.ldraw.model')->findByNumber($number)) { if ($model = $this->get('repository.ldraw.model')->findOneByNumber($number)) {
try { try {
$rbParts = $model != null ? $em->getRepository(Part::class)->findAllByModel($model) : null; $rbParts = $model != null ? $em->getRepository(Part::class)->findAllByModel($model) : null;
$sets = $model != null ? $em->getRepository(Set::class)->findAllByModel($model) : null; $sets = $model != null ? $em->getRepository(Set::class)->findAllByModel($model) : null;
@ -73,12 +72,11 @@ class ModelController extends Controller
'model' => $model, 'model' => $model,
'rbParts' => $rbParts, 'rbParts' => $rbParts,
'sets' => $sets, 'sets' => $sets,
'related' => $related 'related' => $related,
]); ]);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->addFlash('error', $e->getMessage()); $this->addFlash('error', $e->getMessage());
} }
} }
return $this->render('error/error.html.twig'); return $this->render('error/error.html.twig');

View File

@ -3,8 +3,8 @@
namespace AppBundle\Controller\Rebrickable; namespace AppBundle\Controller\Rebrickable;
use AppBundle\Entity\Rebrickable\Color; use AppBundle\Entity\Rebrickable\Color;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/** /**
* Part controller. * Part controller.
@ -14,10 +14,10 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class ColorController extends Controller class ColorController extends Controller
{ {
/** /**
*
* @Route("/", name="color_index") * @Route("/", name="color_index")
*/ */
public function indexAction() { public function indexAction()
{
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$colors = $em->getRepository(Color::class)->findAll(); $colors = $em->getRepository(Color::class)->findAll();
@ -26,4 +26,4 @@ class ColorController extends Controller
'colors' => $colors, 'colors' => $colors,
]); ]);
} }
} }

View File

@ -2,18 +2,13 @@
namespace AppBundle\Controller\Rebrickable; namespace AppBundle\Controller\Rebrickable;
use AppBundle\Api\Exception\EmptyResponseException;
use AppBundle\Entity\LDraw\Model;
use AppBundle\Entity\Rebrickable\Color; use AppBundle\Entity\Rebrickable\Color;
use AppBundle\Entity\Rebrickable\Inventory_Part; use AppBundle\Entity\Rebrickable\Inventory_Part;
use AppBundle\Entity\Rebrickable\Inventory_Set; use AppBundle\Entity\Rebrickable\Inventory_Set;
use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Part;
use AppBundle\Entity\Rebrickable\Set; use AppBundle\Entity\Rebrickable\Set;
use AppBundle\Entity\Rebrickable\Theme;
use AppBundle\Form\FilterSetType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
/** /**
@ -24,7 +19,8 @@ class SetController extends Controller
/** /**
* @Route("/{number}/parts", name="rebrickable_set_parts") * @Route("/{number}/parts", name="rebrickable_set_parts")
*/ */
public function partsAction(Set $set) { public function partsAction(Set $set)
{
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$em->getRepository(Color::class)->findAll(); $em->getRepository(Color::class)->findAll();
@ -41,13 +37,15 @@ class SetController extends Controller
$json = json_encode($template->getContent()); $json = json_encode($template->getContent());
$response = new Response($json, 200); $response = new Response($json, 200);
$response->headers->set('Content-Type', 'application/json'); $response->headers->set('Content-Type', 'application/json');
return $response; return $response;
} }
/** /**
* @Route("/{number}/sets", name="rebrickable_set_sets") * @Route("/{number}/sets", name="rebrickable_set_sets")
*/ */
public function setsAction(Set $set) { public function setsAction(Set $set)
{
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$inventorySets = $em->getRepository(Inventory_Set::class)->findAllBySetNumber($set->getNumber()); $inventorySets = $em->getRepository(Inventory_Set::class)->findAllBySetNumber($set->getNumber());
@ -59,6 +57,7 @@ class SetController extends Controller
$json = json_encode($template->getContent()); $json = json_encode($template->getContent());
$response = new Response($json, 200); $response = new Response($json, 200);
$response->headers->set('Content-Type', 'application/json'); $response->headers->set('Content-Type', 'application/json');
return $response; return $response;
} }
} }

View File

@ -4,15 +4,9 @@ namespace AppBundle\Controller;
use AppBundle\Api\Exception\ApiException; use AppBundle\Api\Exception\ApiException;
use AppBundle\Api\Exception\EmptyResponseException; use AppBundle\Api\Exception\EmptyResponseException;
use AppBundle\Entity\LDraw\Model;
use AppBundle\Entity\Rebrickable\Color;
use AppBundle\Entity\Rebrickable\Inventory_Part; use AppBundle\Entity\Rebrickable\Inventory_Part;
use AppBundle\Entity\Rebrickable\Inventory_Set;
use AppBundle\Entity\Rebrickable\Part;
use AppBundle\Entity\Rebrickable\Set; use AppBundle\Entity\Rebrickable\Set;
use AppBundle\Entity\Rebrickable\Theme;
use AppBundle\Form\Filter\Set\SetFilterType; use AppBundle\Form\Filter\Set\SetFilterType;
use AppBundle\Form\FilterSetType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -50,7 +44,7 @@ class SetController extends Controller
return $this->render('set/index.html.twig', [ return $this->render('set/index.html.twig', [
'sets' => $sets, 'sets' => $sets,
'form' => $form->createView() 'form' => $form->createView(),
]); ]);
} }
@ -62,9 +56,9 @@ class SetController extends Controller
$rebrickableSet = null; $rebrickableSet = null;
$bricksetSet = null; $bricksetSet = null;
try { try {
if(($rebrickableSet = $this->getDoctrine()->getManager()->getRepository(Set::class)->find($number)) == null) { if (($rebrickableSet = $this->getDoctrine()->getManager()->getRepository(Set::class)->find($number)) == null) {
$this->addFlash('warning', 'Set not found in Rebrickable database'); $this->addFlash('warning', 'Set not found in Rebrickable database');
}; }
$bricksetSet = $this->get('api.manager.brickset')->getSetByNumber($number); $bricksetSet = $this->get('api.manager.brickset')->getSetByNumber($number);
dump($bricksetSet); dump($bricksetSet);
@ -76,7 +70,7 @@ class SetController extends Controller
$this->addFlash('error', $e->getMessage()); $this->addFlash('error', $e->getMessage());
} }
if(!$rebrickableSet && !$bricksetSet) { if (!$rebrickableSet && !$bricksetSet) {
return $this->render('error/error.html.twig'); return $this->render('error/error.html.twig');
} }
@ -85,38 +79,4 @@ class SetController extends Controller
'brset' => $bricksetSet, 'brset' => $bricksetSet,
]); ]);
} }
/**
* @Route("/{number}/download", name="set_download")
*/
public function downloadZipAction(Request $request, $number) {
$em = $this->getDoctrine()->getManager();
$inventoryParts = $em->getRepository(Inventory_Part::class)->findAllRegularBySetNumber($number);
$zip = new \ZipArchive();
$zipName = 'set_'.$number.'.zip';
$zip->open($zipName, \ZipArchive::CREATE);
/** @var Inventory_Part $part */
foreach ($inventoryParts as $part) {
$filename = $part->getPart()->getNumber().'_('.$part->getColor()->getName().'_'.$part->getQuantity().'x).stl';
try {
if($part->getPart()->getModel()) {
$zip->addFromString($filename, $this->get('oneup_flysystem.media_filesystem')->read($part->getPart()->getModel()->getPath()));
}
} catch (\Exception $e) {
dump($e);
}
}
$zip->close();
$response = new Response(file_get_contents($zipName));
$response->headers->set('Content-Type', 'application/zip');
$response->headers->set('Content-Disposition', 'attachment;filename="' . $zipName . '"');
$response->headers->set('Content-length', filesize($zipName));
return $response;
}
} }

View File

@ -45,7 +45,6 @@ class Inventory
*/ */
protected $inventorySets; protected $inventorySets;
public function __construct() public function __construct()
{ {
$this->inventoryParts = new ArrayCollection(); $this->inventoryParts = new ArrayCollection();

View File

@ -2,18 +2,19 @@
namespace AppBundle\Exception; namespace AppBundle\Exception;
use Exception; use Exception;
class ConvertingFailedException extends \Exception class ConvertingFailedException extends \Exception
{ {
private $filepath; private $filepath;
public function __construct($filepath = "", $message = "", $code = 0, Exception $previous = null) public function __construct($form = '', $to = '', $message = '', $code = 0, Exception $previous = null)
{ {
$message = sprintf('Error converting "%s" file to "%s".', $form, $to);
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
$this->filepath = $filepath; $this->filepath = $form;
} }
/** /**
@ -31,6 +32,4 @@ class ConvertingFailedException extends \Exception
{ {
$this->filepath = $filepath; $this->filepath = $filepath;
} }
}
}

View File

@ -7,12 +7,12 @@ use AppBundle\Repository\BaseRepository;
class InventoryRepository extends BaseRepository class InventoryRepository extends BaseRepository
{ {
public function findNewestInventoryBySetNumber($number) { public function findNewestInventoryBySetNumber($number)
{
$queryBuilder = $this->createQueryBuilder('inventory') $queryBuilder = $this->createQueryBuilder('inventory')
->where('inventory.set = :setNumber') ->where('inventory.set = :setNumber')
->setParameter('setNumber', $number) ->setParameter('setNumber', $number)
->orderBy('inventory.version','DESC') ->orderBy('inventory.version', 'DESC')
->setMaxResults(1); ->setMaxResults(1);
return $queryBuilder->getQuery()->getOneOrNullResult(); return $queryBuilder->getQuery()->getOneOrNullResult();

View File

@ -6,7 +6,6 @@ use AppBundle\Entity\LDraw\Category;
use AppBundle\Entity\Rebrickable\Inventory; use AppBundle\Entity\Rebrickable\Inventory;
use AppBundle\Entity\Rebrickable\Inventory_Part; use AppBundle\Entity\Rebrickable\Inventory_Part;
use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Part;
use AppBundle\Entity\Rebrickable\Set;
use AppBundle\Repository\BaseRepository; use AppBundle\Repository\BaseRepository;
use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\Query\Expr\Join;
@ -18,7 +17,7 @@ class Inventory_PartRepository extends BaseRepository
$queryBuilder = $this->createQueryBuilder('inventory_part') $queryBuilder = $this->createQueryBuilder('inventory_part')
->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory') ->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory')
->join(Part::class,'part',JOIN::WITH,'inventory_part.part = part.number') ->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part.number')
->where('part.category != 17') ->where('part.category != 17')
->andWhere('inventory.id = :inventoryId') ->andWhere('inventory.id = :inventoryId')
->setParameter('inventoryId', $inventory->getId()) ->setParameter('inventoryId', $inventory->getId())
@ -34,7 +33,7 @@ class Inventory_PartRepository extends BaseRepository
$queryBuilder = $this->createQueryBuilder('inventory_part') $queryBuilder = $this->createQueryBuilder('inventory_part')
->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory') ->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory')
->join(Part::class,'part',JOIN::WITH,'inventory_part.part = part.number') ->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part.number')
->where('part.category != 17') ->where('part.category != 17')
->andWhere('inventory.id = :inventoryId') ->andWhere('inventory.id = :inventoryId')
->setParameter('inventoryId', $inventory->getId()) ->setParameter('inventoryId', $inventory->getId())

View File

@ -3,21 +3,18 @@
namespace AppBundle\Repository\Rebrickable; namespace AppBundle\Repository\Rebrickable;
use AppBundle\Entity\Rebrickable\Inventory; use AppBundle\Entity\Rebrickable\Inventory;
use AppBundle\Entity\Rebrickable\Inventory_Part;
use AppBundle\Entity\Rebrickable\Set;
use AppBundle\Repository\BaseRepository; use AppBundle\Repository\BaseRepository;
use Doctrine\ORM\Query\Expr\Join;
class Inventory_SetRepository extends BaseRepository class Inventory_SetRepository extends BaseRepository
{ {
public function findAllBySetNumber($number) { public function findAllBySetNumber($number)
{
$inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($number); $inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($number);
if($inventory) { if ($inventory) {
$queryBuilder = $this->createQueryBuilder('inventory_set') $queryBuilder = $this->createQueryBuilder('inventory_set')
->where('inventory_set.inventory = :inventory') ->where('inventory_set.inventory = :inventory')
->setParameter('inventory',$inventory->getId()); ->setParameter('inventory', $inventory->getId());
return $queryBuilder->getQuery()->getResult(); return $queryBuilder->getQuery()->getResult();
} }

View File

@ -5,7 +5,6 @@ namespace AppBundle\Repository\Rebrickable;
use AppBundle\Entity\LDraw\Model; use AppBundle\Entity\LDraw\Model;
use AppBundle\Entity\Rebrickable\Inventory; use AppBundle\Entity\Rebrickable\Inventory;
use AppBundle\Entity\Rebrickable\Inventory_Part; use AppBundle\Entity\Rebrickable\Inventory_Part;
use AppBundle\Entity\Rebrickable\Inventory_Set;
use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Part;
use AppBundle\Entity\Rebrickable\Set; use AppBundle\Entity\Rebrickable\Set;
use AppBundle\Entity\Rebrickable\Theme; use AppBundle\Entity\Rebrickable\Theme;
@ -14,12 +13,12 @@ use Doctrine\ORM\Query\Expr\Join;
class SetRepository extends BaseRepository class SetRepository extends BaseRepository
{ {
public function findAllByTheme(Theme $theme) { public function findAllByTheme(Theme $theme)
{
dump($this->getEntityManager()->getRepository(Theme::class)->findAllSubthemes($theme)); dump($this->getEntityManager()->getRepository(Theme::class)->findAllSubthemes($theme));
$queryBuilder = $this->createQueryBuilder('s') $queryBuilder = $this->createQueryBuilder('s')
->join(Theme::class, 'theme',Join::WITH, 's.theme = theme') ->join(Theme::class, 'theme', Join::WITH, 's.theme = theme')
->where('theme.id = :id') ->where('theme.id = :id')
->setParameter('id', $theme->getId()); ->setParameter('id', $theme->getId());

View File

@ -8,12 +8,12 @@ use Doctrine\ORM\Query\Expr\Join;
class ThemeRepository extends BaseRepository class ThemeRepository extends BaseRepository
{ {
public function findAllSubthemes(Theme $theme) { public function findAllSubthemes(Theme $theme)
{
$subQueryBuilder = $this->createQueryBuilder('subtheme'); $subQueryBuilder = $this->createQueryBuilder('subtheme');
$queryBuilder = $this->createQueryBuilder('subtheme') $queryBuilder = $this->createQueryBuilder('subtheme')
->leftJoin(Theme::class,'theme', Join::WITH, 'subtheme.parent = theme.id') ->leftJoin(Theme::class, 'theme', Join::WITH, 'subtheme.parent = theme.id')
->where('subtheme.parent = :id') ->where('subtheme.parent = :id')
->setParameter('id', $theme->getId()); ->setParameter('id', $theme->getId());

View File

@ -3,9 +3,6 @@
namespace AppBundle\Twig; namespace AppBundle\Twig;
use AppBundle\Api\Manager\RebrickableManager; use AppBundle\Api\Manager\RebrickableManager;
use AppBundle\Entity\Rebrickable\Color;
use AppBundle\Entity\Rebrickable\Part;
use AppBundle\Entity\Rebrickable\Set;
class AppExtension extends \Twig_Extension class AppExtension extends \Twig_Extension
{ {
@ -30,7 +27,8 @@ class AppExtension extends \Twig_Extension
]; ];
} }
public function getFunctions() { public function getFunctions()
{
return [ return [
new \Twig_SimpleFunction('remoteSize', [$this, 'remoteSize']), new \Twig_SimpleFunction('remoteSize', [$this, 'remoteSize']),
new \Twig_SimpleFunction('remoteFilename', [$this, 'remoteFilename']), new \Twig_SimpleFunction('remoteFilename', [$this, 'remoteFilename']),
@ -39,7 +37,7 @@ class AppExtension extends \Twig_Extension
public function partImage($number, $color = null) public function partImage($number, $color = null)
{ {
return '/parts/ldraw/'.($color ? $color :'-1').'/'.$number.'.png'; return '/parts/ldraw/'.($color ? $color : '-1').'/'.$number.'.png';
} }
public function setImage($number) public function setImage($number)
@ -47,21 +45,24 @@ class AppExtension extends \Twig_Extension
return '/sets/'.strtolower($number).'.jpg'; return '/sets/'.strtolower($number).'.jpg';
} }
public function remoteSize($url) { public function remoteSize($url)
{
$ch = curl_init($url); $ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, TRUE); curl_setopt($ch, CURLOPT_NOBODY, true);
$data = curl_exec($ch); $data = curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch); curl_close($ch);
return $size; return $size;
} }
public function remoteFilename($url) { public function remoteFilename($url)
return basename($url); {
return basename($url);
} }
} }