/iaLib/ia_examples/AesCipher_example.php
<?php
$ia_example = [
'title' => 'AesCipher', // fully qualified className
'summary' => '', // class summary
'full_example' => '', // full usage example, relative path from ia_examples, blank '' not shown.
'example_file' => 'code/AesCipher_example_code.php', // method by method example, blank '' not shown.
];
include( __DIR__ . '/template/ia_example_class.php');
/iaLib/ia_examples/code/AesCipher_example_code.php
/**
* Usage examples for AesCipher
* @version 1.0
* @date 2026-01
*/
use ia\DocumentIt\DocumentIt;
use ia\DocumentIt\DocumentIt;
echo '<h3>Disclaimer: Auto generated file.
Please help us setting parameters to useful values and extending the examples.
</h3>';
try {
echo <<< CONSTRUCTOR_PROTOTYPE
<pre>
/**
* AesCipher constructor.
*
* @param string \$initVector Initialization vector value
* @param string|null \$data Encoded/Decoded Data
* @param string|null \$errorMessage Error message if operation failed
*/
/*
\$aesCipher = new AesCipher(<span class="type">string</span> \$initVector, <span class="type">string|null \$data Encoded/Decoded</span> \$data <span class="default">= null</span>, <span class="type">string|null</span> \$errorMessage <span class="default">= null</span>);
*/
\$aesCipher = new AesCipher('palabra');
</pre>
CONSTRUCTOR_PROTOTYPE;
$aesCipher = new AesCipher('palabra');
echo '<ul class="usage">';
///////// AesCipher::encrypt('palabra', 'palabra'); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_encrypt'><b>AesCipher::encrypt(<span class="type">string</span> \$secretKey, <span class="type">string</span> \$plainText) <span>: self</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("AesCipher", "encrypt")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>AesCipher::encrypt('palabra', 'palabra');
-> </b><br><pre>
DOCUMENT_EXAMPLE;
/// run ///
print_r(
AesCipher::encrypt('palabra', 'palabra')
);
echo "</pre>";
echo '</ol>';
///////// AesCipher::decrypt('palabra', 'palabra'); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_decrypt'><b>AesCipher::decrypt(<span class="type">string</span> \$secretKey, <span class="type">string</span> \$cipherText) <span>: self</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("AesCipher", "decrypt")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>AesCipher::decrypt('palabra', 'palabra');
-> </b><br><pre>
DOCUMENT_EXAMPLE;
/// run ///
print_r(
AesCipher::decrypt('palabra', 'palabra')
);
echo "</pre>";
echo '</ol>';
///////// AesCipher::isKeyLengthValid('palabra'); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_isKeyLengthValid'><b>AesCipher::isKeyLengthValid(<span class="type">string</span> \$secretKey) <span>: bool</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("AesCipher", "isKeyLengthValid")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>AesCipher::isKeyLengthValid('palabra'); ->
DOCUMENT_EXAMPLE;
///run ///
echo (AesCipher::isKeyLengthValid('palabra') ? 'true' : 'false');
echo '</ol>';
///////// \$aesCipher->getData(); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_getData'><b>\$aesCipher->getData() <span>: string|null</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("AesCipher", "getData")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>\$aesCipher->getData();
-> </b><br><pre>
DOCUMENT_EXAMPLE;
/// run ///
print_r(
$aesCipher->getData()
);
echo "</pre>";
echo '</ol>';
///////// \$aesCipher->getInitVector(); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_getInitVector'><b>\$aesCipher->getInitVector() <span>: string|null</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("AesCipher", "getInitVector")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>\$aesCipher->getInitVector();
-> </b><br><pre>
DOCUMENT_EXAMPLE;
/// run ///
print_r(
$aesCipher->getInitVector()
);
echo "</pre>";
echo '</ol>';
///////// \$aesCipher->getErrorMessage(); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_getErrorMessage'><b>\$aesCipher->getErrorMessage() <span>: string|null</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("AesCipher", "getErrorMessage")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>\$aesCipher->getErrorMessage();
-> </b><br><pre>
DOCUMENT_EXAMPLE;
/// run ///
print_r(
$aesCipher->getErrorMessage()
);
echo "</pre>";
echo '</ol>';
///////// \$aesCipher->hasError(); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_hasError'><b>\$aesCipher->hasError() <span>: bool</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("AesCipher", "hasError")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>\$aesCipher->hasError(); ->
DOCUMENT_EXAMPLE;
///run ///
echo ($aesCipher->hasError() ? 'true' : 'false');
echo '</ol>';
///////// \$aesCipher->__toString(); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u___toString'><b>\$aesCipher->__toString() <span>: string</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("AesCipher", "__toString")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>\$aesCipher->__toString(); ->
DOCUMENT_EXAMPLE;
/// run ///
echo $aesCipher->__toString();
echo '</ol>';
/* PerfilExample adds new methods here */
echo '</ul>';
} catch(Exception $exception) { echo "<pre class='errorBlock'>$exception</pre>"; }
phpunit test file template
<?php
use AesCipher;
use PHPUnit\Framework\TestCase;
class AesCipherTest extends TestCase {
/**
* @dataProvider encrypt_Provider
*
*/
public function test_encrypt($secretKey, $plainText , $expected) {
$this->assertEquals($expected, AesCipher::encrypt($secretKey, $plainText) );
}
function encrypt_Provider() {
return [
'test 1' => [ '', '', '' ],
];
}
/**
* @dataProvider decrypt_Provider
*
*/
public function test_decrypt($secretKey, $cipherText , $expected) {
$this->assertEquals($expected, AesCipher::decrypt($secretKey, $cipherText) );
}
function decrypt_Provider() {
return [
'test 1' => [ '', '', '' ],
];
}
/**
* @dataProvider isKeyLengthValid_Provider
*
*/
public function test_isKeyLengthValid($secretKey , $expected) {
$this->assertEquals($expected, AesCipher::isKeyLengthValid($secretKey) );
}
function isKeyLengthValid_Provider() {
return [
'test 1' => [ '', '' ],
];
}
/**
* @dataProvider getData_Provider
*
*/
public function test_getData( $expected) {
$aesCipher = new AesCipher($initVector, $data, $errorMessage);
$this->assertEquals($expected, $aesCipher->getData() );
}
function getData_Provider() {
return [
'test 1' => [ '' ],
];
}
/**
* @dataProvider getInitVector_Provider
*
*/
public function test_getInitVector( $expected) {
$aesCipher = new AesCipher($initVector, $data, $errorMessage);
$this->assertEquals($expected, $aesCipher->getInitVector() );
}
function getInitVector_Provider() {
return [
'test 1' => [ '' ],
];
}
/**
* @dataProvider getErrorMessage_Provider
*
*/
public function test_getErrorMessage( $expected) {
$aesCipher = new AesCipher($initVector, $data, $errorMessage);
$this->assertEquals($expected, $aesCipher->getErrorMessage() );
}
function getErrorMessage_Provider() {
return [
'test 1' => [ '' ],
];
}
/**
* @dataProvider hasError_Provider
*
*/
public function test_hasError( $expected) {
$aesCipher = new AesCipher($initVector, $data, $errorMessage);
$this->assertEquals($expected, $aesCipher->hasError() );
}
function hasError_Provider() {
return [
'test 1' => [ '' ],
];
}
/**
* @dataProvider __toString_Provider
*
*/
public function test___toString( $expected) {
$aesCipher = new AesCipher($initVector, $data, $errorMessage);
$this->assertEquals($expected, $aesCipher->__toString() );
}
function __toString_Provider() {
return [
'test 1' => [ '' ],
];
}
}
ia Doc