Skip to content

Commit

Permalink
Merge pull request #4 from MekDrop/improvement/added-supports-method-…
Browse files Browse the repository at this point in the history
…for-factories

Added supports* functions for factory constructors
  • Loading branch information
MekDrop authored Feb 14, 2021
2 parents 22bb5ed + 25dcf6c commit bd915b3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Exceptions/UnsupportedExtensionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Imponeer\Contracts\ExtensionInfo\Exceptions;

use Exception;
use Throwable;

/**
* Exception that is thrown when factory doesn't supports such exception but asked to create one
*
* @package Imponeer\Contracts\ExtensionInfo\Exceptions
*/
class UnsupportedExtensionException extends Exception
{

/**
* UnsupportedExtensionException constructor.
*
* @param string $name Extension name
* @param int $code Error code
* @param Throwable|null $previous Previous exception
*/
public function __construct($name, $code = 0, ?Throwable $previous = null)
{
parent::__construct($name . ' extension for this factory is not supported', $code, $previous);
}

}
11 changes: 11 additions & 0 deletions src/Factory/FromComposerPackageFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Imponeer\Contracts\ExtensionInfo\Factory;

use Composer\Package\Package;
use Imponeer\Contracts\ExtensionInfo\Exceptions\UnsupportedExtensionException;
use Imponeer\Contracts\ExtensionInfo\ExtensionInfoInterface;

/**
Expand All @@ -20,7 +21,17 @@ interface FromComposerPackageFactoryInterface
* @param Package $package Composer package instance
*
* @return ExtensionInfoInterface
*
* @throws UnsupportedExtensionException
*/
public function createFromComposerPackage(Package $package): ExtensionInfoInterface;

/**
* Checks if info factory supports such package
*
* @param Package $package Composer package to be checked if is supported
*
* @return bool
*/
public function supportsPackage(Package $package): bool;
}
11 changes: 11 additions & 0 deletions src/Factory/FromPathFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Imponeer\Contracts\ExtensionInfo\Factory;

use Imponeer\Contracts\ExtensionInfo\Exceptions\UnsupportedExtensionException;
use Imponeer\Contracts\ExtensionInfo\ExtensionInfoInterface;

/**
Expand All @@ -18,7 +19,17 @@ interface FromPathFactoryInterface
* @param string $path
*
* @return ExtensionInfoInterface
*
* @throws UnsupportedExtensionException
*/
public function createFromPath(string $path): ExtensionInfoInterface;

/**
* Checks if info factory supports such path
*
* @param string $path Path to check if this info reader supports such path
*
* @return bool
*/
public function supportsPath(string $path): bool;
}

0 comments on commit bd915b3

Please sign in to comment.