PHP code example of openapi-tools / utils
1. Go to this page and download the library: Download openapi-tools/utils library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
openapi-tools / utils example snippets
use OpenAPITools\Utils\Utils;
Utils::className('namespace/sub/my-class'); // Namespace\Sub\MyClass
Utils::cleanUpString('bad{chars'); // bad_chars
Utils::fixKeyword('class'); // class_
Utils::dirname('\\Vendor\\Schema\\Foo'); // \Vendor\Schema
Utils::basename('\\Vendor\\Schema\\Foo'); // \Foo
use OpenAPITools\Utils\ClassString;
use OpenAPITools\Utils\Namespace_;
$classString = ClassString::factory(
new Namespace_('OpenAPITools\\Schema', 'OpenAPITools\\Tests\\Schema'),
'Models\\User',
);
$classString->fullyQualified->source; // \OpenAPITools\Schema\Models\User
$classString->fullyQualified->test; // \OpenAPITools\Tests\Schema\Models\User
$classString->className; // User
use OpenAPITools\Utils\State;
$state = State::initialize();
$state->specHash = 'abc123';
$state->generatedFiles->upsert('User.php', 'bef729dcdda9be9df5af3a1f3f50873e');
$json = State::serialize($state);
$state = State::deserialize($json);
use OpenAPITools\Utils\File;
$file = new File(
pathPrefix: '/tmp/generated',
fqcn: '\\Vendor\\Schema\\User',
contents: ' /* generated */',
loadOnWrite: File::DO_LOAD_ON_WRITE,
);