diff --git a/DXFighter.php b/DXFighter.php index b3282b6..b866a3a 100644 --- a/DXFighter.php +++ b/DXFighter.php @@ -29,6 +29,8 @@ use DXFighter\lib\Polyline; use DXFighter\lib\Spline; use DXFighter\lib\Text; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; /** * Returns the class name, used for auto loading libraries @@ -53,9 +55,11 @@ function dxf_autoloader($className) { * Class DXFighter * @package DXFighter */ -class DXFighter { +class DXFighter implements LoggerAwareInterface{ protected $sections; + use LoggerAwareTrait; + /** * @var Section */ @@ -225,7 +229,7 @@ public function move($move) { if (method_exists($entity, 'move')) { $entity->move($move); } else { - echo 'The ' . get_class($entity) . ' class does not have a move function.' . PHP_EOL; + $this->logger?->warning('The ' . get_class($entity) . ' class does not have a move function.' . PHP_EOL); } } } @@ -241,7 +245,7 @@ public function rotate($rotate, $rotationCenter = array(0, 0, 0)) { if (method_exists($entity, 'rotate')) { $entity->rotate($rotate, $rotationCenter); } else { - echo 'The ' . get_class($entity) . ' class does not have a rotate function.' . PHP_EOL; + $this->logger?->warning('The ' . get_class($entity) . ' class does not have a rotate function.' . PHP_EOL); } } } @@ -432,7 +436,8 @@ private function readBlocksSection($values) { $block = []; break; case 'ENDBLK': - $blockEntity = new Block($block[2]); + $name = $block[2] ?? ''; + $blockEntity = new Block($name); $entities = $this->readEntitiesSection($entitiesSection); foreach ($entities as $entity) { $blockEntity->addEntity($entity); @@ -631,7 +636,7 @@ private function addReadEntity($type, $data, $move = [0,0,0], $rotate = 0) { $polyline = new Polyline(3); break; default: - echo 'The polyline type ' . $data[100] . ' has not been found' . PHP_EOL; + $this->logger?->notice( 'The polyline type ' . $data[100] . ' has not been found' . PHP_EOL ); return false; } } else { diff --git a/composer.json b/composer.json index a3d0f7e..92e871c 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ } ], "require": { + "psr/log": "^3.0" }, "require-dev": { "phpunit/phpunit": "^7", diff --git a/composer.lock b/composer.lock index be6bc7d..773760f 100644 --- a/composer.lock +++ b/composer.lock @@ -1,12 +1,62 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "hash": "29e31dd3857245fbce28e9722c371a91", - "content-hash": "318c4c61460690ea91f8c317d50e9ec3", - "packages": [], + "content-hash": "60eb8e218bf7a90f2f742714187a5425", + "packages": [ + { + "name": "psr/log", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/3.0.0" + }, + "time": "2021-07-14T16:46:02+00:00" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", @@ -60,7 +110,7 @@ "constructor", "instantiate" ], - "time": "2017-07-22 11:58:36" + "time": "2017-07-22T11:58:36+00:00" }, { "name": "myclabs/deep-copy", @@ -105,7 +155,7 @@ "object", "object graph" ], - "time": "2017-10-19 19:58:43" + "time": "2017-10-19T19:58:43+00:00" }, { "name": "phar-io/manifest", @@ -160,7 +210,7 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2017-03-05 18:14:27" + "time": "2017-03-05T18:14:27+00:00" }, { "name": "phar-io/version", @@ -207,7 +257,7 @@ } ], "description": "Library for handling version information and constraints", - "time": "2017-03-05 17:38:23" + "time": "2017-03-05T17:38:23+00:00" }, { "name": "phpcheckstyle/phpcheckstyle", @@ -252,7 +302,7 @@ "convention", "standard" ], - "time": "2017-11-10 15:01:41" + "time": "2017-11-10T15:01:41+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -306,7 +356,7 @@ "reflection", "static analysis" ], - "time": "2017-09-11 18:02:19" + "time": "2017-09-11T18:02:19+00:00" }, { "name": "phpdocumentor/reflection-docblock", @@ -357,7 +407,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-30 07:14:17" + "time": "2017-11-30T07:14:17+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -404,7 +454,7 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14 14:27:02" + "time": "2017-07-14T14:27:02+00:00" }, { "name": "phpspec/prophecy", @@ -467,7 +517,7 @@ "spy", "stub" ], - "time": "2018-04-18 13:57:24" + "time": "2018-04-18T13:57:24+00:00" }, { "name": "phpunit/php-code-coverage", @@ -530,7 +580,7 @@ "testing", "xunit" ], - "time": "2018-04-06 15:39:20" + "time": "2018-04-06T15:39:20+00:00" }, { "name": "phpunit/php-file-iterator", @@ -577,7 +627,7 @@ "filesystem", "iterator" ], - "time": "2017-11-27 13:52:08" + "time": "2017-11-27T13:52:08+00:00" }, { "name": "phpunit/php-text-template", @@ -618,7 +668,7 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", @@ -667,7 +717,7 @@ "keywords": [ "timer" ], - "time": "2018-02-01 13:07:23" + "time": "2018-02-01T13:07:23+00:00" }, { "name": "phpunit/php-token-stream", @@ -716,7 +766,7 @@ "keywords": [ "tokenizer" ], - "time": "2018-02-01 13:16:43" + "time": "2018-02-01T13:16:43+00:00" }, { "name": "phpunit/phpunit", @@ -796,7 +846,7 @@ "testing", "xunit" ], - "time": "2018-04-18 13:41:53" + "time": "2018-04-18T13:41:53+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -852,7 +902,7 @@ "mock", "xunit" ], - "time": "2018-04-11 04:50:36" + "time": "2018-04-11T04:50:36+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -897,7 +947,7 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04 06:30:41" + "time": "2017-03-04T06:30:41+00:00" }, { "name": "sebastian/comparator", @@ -961,7 +1011,7 @@ "compare", "equality" ], - "time": "2018-04-18 13:33:00" + "time": "2018-04-18T13:33:00+00:00" }, { "name": "sebastian/diff", @@ -1017,7 +1067,7 @@ "unidiff", "unified diff" ], - "time": "2018-02-01 13:45:15" + "time": "2018-02-01T13:45:15+00:00" }, { "name": "sebastian/environment", @@ -1067,7 +1117,7 @@ "environment", "hhvm" ], - "time": "2017-07-01 08:51:00" + "time": "2017-07-01T08:51:00+00:00" }, { "name": "sebastian/exporter", @@ -1134,7 +1184,7 @@ "export", "exporter" ], - "time": "2017-04-03 13:19:02" + "time": "2017-04-03T13:19:02+00:00" }, { "name": "sebastian/global-state", @@ -1185,7 +1235,7 @@ "keywords": [ "global state" ], - "time": "2017-04-27 15:39:26" + "time": "2017-04-27T15:39:26+00:00" }, { "name": "sebastian/object-enumerator", @@ -1232,7 +1282,7 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-08-03 12:35:26" + "time": "2017-08-03T12:35:26+00:00" }, { "name": "sebastian/object-reflector", @@ -1277,7 +1327,7 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2017-03-29 09:07:27" + "time": "2017-03-29T09:07:27+00:00" }, { "name": "sebastian/recursion-context", @@ -1330,7 +1380,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2017-03-03 06:23:57" + "time": "2017-03-03T06:23:57+00:00" }, { "name": "sebastian/resource-operations", @@ -1372,7 +1422,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28 20:34:47" + "time": "2015-07-28T20:34:47+00:00" }, { "name": "sebastian/version", @@ -1415,7 +1465,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03 07:35:21" + "time": "2016-10-03T07:35:21+00:00" }, { "name": "theseer/tokenizer", @@ -1455,7 +1505,7 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2017-04-07 12:08:54" + "time": "2017-04-07T12:08:54+00:00" }, { "name": "webmozart/assert", @@ -1505,7 +1555,7 @@ "check", "validate" ], - "time": "2018-01-29 19:49:41" + "time": "2018-01-29T19:49:41+00:00" } ], "aliases": [], @@ -1514,5 +1564,6 @@ "prefer-stable": false, "prefer-lowest": false, "platform": [], - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "2.1.0" } diff --git a/lib/Entity.php b/lib/Entity.php index 6e7b97c..5d4e647 100644 --- a/lib/Entity.php +++ b/lib/Entity.php @@ -84,7 +84,7 @@ public function setFlag($id, $value) { * Retrieves a flag value for an entity. */ public function getFlag($id) { - return $this->flags[$id]; + return $this->flags[$id] ?? null; } /**