1. Go to this page and download the library: Download beberlei/assert 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/ */
beberlei / assert example snippets
use Assert\Assertion;
function duplicateFile($file, $times)
{
Assertion::file($file);
Assertion::digit($times);
for ($i = 0; $i < $times; $i++) {
copy($file, $file . $i);
}
}
public function putBlob($containerName = '', $blobName = '', $localFileName = '', $metadata = array(), $leaseId = null, $additionalHeaders = array())
{
Assertion::notEmpty($containerName, 'Container name is not specified');
self::assertValidContainerName($containerName);
Assertion::notEmpty($blobName, 'Blob name is not specified.');
Assertion::notEmpty($localFileName, 'Local file name is not specified.');
Assertion::file($localFileName, 'Local file name is not specified.');
self::assertValidRootContainerBlobName($containerName, $blobName);
// Check file size
if (filesize($localFileName) >= self::MAX_BLOB_SIZE) {
return $this->putLargeBlob($containerName, $blobName, $localFileName, $metadata, $leaseId, $additionalHeaders);
}
// Put the data to Windows Azure Storage
return $this->putBlobData($containerName, $blobName, file_get_contents($localFileName), $metadata, $leaseId, $additionalHeaders);
}
use Assert\Assertion;
use Assert\AssertionFailedException;
try {
Assertion::integer($value, "The pressure of gas is measured in integers.");
} catch(AssertionFailedException $e) {
// error handling
$e->getValue(); // the value that caused the failure
$e->getConstraints(); // the additional constraints of the assertion.
}
namespace MyProject;
use Assert\Assertion as BaseAssertion;
class Assertion extends BaseAssertion
{
protected static $exceptionClass = 'MyProject\AssertionFailedException';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.