├── .gitignore ├── src ├── Console │ ├── bin │ │ ├── linux │ │ ├── macos │ │ ├── windows.exe │ │ └── readme.md │ ├── Commands.php │ ├── Commands │ │ ├── Cache.php │ │ ├── Version.php │ │ ├── RouterListCommand.php │ │ ├── ServeCommand.php │ │ ├── Controller.php │ │ └── ListCmd.php │ ├── Colorize.php │ ├── Input.php │ ├── Input │ │ └── Table.php │ └── Command.php ├── Files │ ├── readme.md │ ├── composer.json │ └── FileHandling.php ├── Archive │ ├── composer.json │ ├── Adapter │ │ ├── AdapterInterface.php │ │ ├── Bzip.php │ │ └── Gzip.php │ └── Archive.php ├── Cookies │ └── composer.json ├── Session │ └── composer.json ├── Data │ ├── composer.json │ └── Contracts │ │ ├── StrContract.php │ │ └── ConversionContract.php ├── Container │ └── composer.json ├── Common │ ├── Version.php │ ├── Logger │ │ └── LogLevel.php │ ├── AliasLoader.php │ ├── Model │ │ └── Model.php │ ├── TimeZone.php │ ├── OperatingSystem.php │ ├── Sitemap │ │ ├── AbstractSitemap.php │ │ └── SitemapWriter.php │ ├── Maintenance.php │ ├── PasswordManipulation.php │ ├── Env.php │ └── Configuration.php ├── Component │ ├── dispatcher.php │ ├── View │ │ └── View.php │ ├── Router.php │ └── Component.php ├── http │ ├── ServerRequest.php │ ├── UploadedFile.php │ ├── Clients │ │ ├── Stream.php │ │ └── Client.php │ ├── ValidProtocolVersions.php │ ├── Redirect.php │ └── StatusCode.php ├── Contracts │ ├── Benchmark │ │ └── Benchmark.php │ ├── Common │ │ ├── Root.php │ │ └── Configuration.php │ ├── Sitemap │ │ ├── SitemapIndex.php │ │ ├── Sitemap.php │ │ ├── AbstractSitemap.php │ │ └── SitemapWriter.php │ ├── View │ │ └── View.php │ ├── SystemMessage │ │ └── SystemMessage.php │ ├── Encryption │ │ ├── Adapter │ │ │ └── AbstractAdapter.php │ │ ├── Encrypt.php │ │ └── Encryption.php │ ├── Auth │ │ ├── Update.php │ │ ├── Auth.php │ │ └── User.php │ ├── Zip │ │ └── Zip.php │ ├── Site │ │ └── Key.php │ ├── Time │ │ └── Time.php │ └── Cache │ │ └── Cache.php ├── Database │ ├── MYSQL.php │ └── Db.php ├── Exception │ └── Exception.php ├── Auth │ ├── Logout.php │ ├── Success.php │ ├── EmailHandler.php │ ├── Verify.php │ ├── Handler.php │ ├── Auth.php │ ├── Error.php │ ├── Reset.php │ └── Update.php ├── Hashing │ ├── Argon2IdHashing.php │ ├── AbstractHashing.php │ ├── Hashing.php │ └── Hash.php ├── Validation │ ├── JsonRules.php │ ├── StickyRules.php │ ├── databaseRules.php │ └── Handler.php ├── Encryption │ ├── Adapter │ │ ├── AbstractAdapter.php │ │ ├── OpenSslEncryption.php │ │ └── SodiumEncryption.php │ ├── Encrypt.php │ └── Encryption.php ├── Router │ └── App.php ├── Benchmark │ └── Benchmark.php ├── Site │ └── Key.php ├── Bootstrap.php ├── Cache │ └── Adapter │ │ └── AbstractAdapter.php └── Language │ └── Language.php ├── CONTRIBUTING.md ├── Tests ├── Archive │ ├── .gitignore │ ├── alphaz.png │ ├── ZipTest.php │ ├── BzipTest.php │ └── GzipTest.php ├── Data │ └── ConversionTest.php ├── Site │ └── KeyTest.php ├── Common │ ├── RootTest.php │ ├── PasswordManipulationTest.php │ ├── EnvTest.php │ └── ConfigurationTest.php ├── Container │ └── ContainerTest.php ├── Encryption │ └── EncryptionTest.php ├── Mail │ └── MailTest.php ├── Time │ └── TimeTest.php └── Hashing │ └── HashingTest.php ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── FUNDING.yml ├── workflows │ ├── branch.yml │ ├── api_docs.yml │ ├── monorepo_split.yml │ ├── tests.yml │ └── split_releases.yml └── PULL_REQUEST_TEMPLATE.md ├── phpunit.xml ├── LICENSE ├── composer.json ├── readme.md ├── changes.md └── CODE_OF_CONDUCT.md /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /.phpintel 3 | /.phpunit.result.cache 4 | -------------------------------------------------------------------------------- /src/Console/bin/linux: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazframework/framework/HEAD/src/Console/bin/linux -------------------------------------------------------------------------------- /src/Console/bin/macos: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazframework/framework/HEAD/src/Console/bin/macos -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## DISCLAIMERS 2 | 3 | [Guidelines](https://alphazframework.github.io/contribution/) 4 | -------------------------------------------------------------------------------- /Tests/Archive/.gitignore: -------------------------------------------------------------------------------- 1 | /new 2 | alphaz.png.bz 3 | alphaz.png.gz 4 | alphaz.png.new 5 | alphaz.png.zip 6 | -------------------------------------------------------------------------------- /Tests/Archive/alphaz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazframework/framework/HEAD/Tests/Archive/alphaz.png -------------------------------------------------------------------------------- /src/Console/bin/windows.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazframework/framework/HEAD/src/Console/bin/windows.exe -------------------------------------------------------------------------------- /src/Console/bin/readme.md: -------------------------------------------------------------------------------- 1 | ## secret input binaries 2 | The source code of the binaries is available here [https://github.com/alphazframework/secret-input](https://github.com/alphazframework/secret-input) 3 | -------------------------------------------------------------------------------- /src/Files/readme.md: -------------------------------------------------------------------------------- 1 | # PHP Files Library 2 | 3 | Subtree of alphaz/Files 4 | 5 | PHP File library for the local filesystem. 6 | 7 | ## Installation 8 | 9 | Install via Composer: 10 | 11 | ``` 12 | composer require alphaz/files 13 | ``` 14 | -------------------------------------------------------------------------------- /Tests/Data/ConversionTest.php: -------------------------------------------------------------------------------- 1 | assertSame('1 K', Conversion::bitToBytes(1024)); 13 | $this->assertNotSame('2 K', Conversion::bitToBytes(1024)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Files/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alphaz/files", 3 | "description": "alphaz framework components to manipulate files", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "lablnet", 8 | "email": "mumerfarooqlablnet01@gmail.com" 9 | } 10 | ], 11 | "require": {}, 12 | "autoload": { 13 | "psr-4": { 14 | "alphaz\\Files\\": "" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Archive/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alphaz/archive", 3 | "description": "The alphaz Archive component", 4 | "type": "libraray", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "lablnet", 9 | "email": "mumerfarooqlablnet01@gmail.com" 10 | } 11 | ], 12 | "require": {}, 13 | "autoload": { 14 | "psr-4": { 15 | "alphaz\\Archive\\": "" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Cookies/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alphaz/cookies", 3 | "description": "The alphaz Component to manipulate web cookies", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "lablnet", 9 | "email": "mumerfarooqlablnet01@gmail.com" 10 | } 11 | ], 12 | "require": {}, 13 | "autoload": { 14 | "psr-4": { 15 | "alphaz\\Cookies\\": "" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Session/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alphaz/session", 3 | "description": "The alphaz component to manipulate sessions", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "lablnet", 9 | "email": "mumerfarooqlablnet01@gmail.com" 10 | } 11 | ], 12 | "require": {}, 13 | "autoload": { 14 | "psr-4": { 15 | "alphaz\\Cookies\\": "" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Data/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alphaz/data", 3 | "description": "A set of Component classes to manipulate arrays, data and string", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "lablnet", 9 | "email": "mumerfarooqlablnet01@gmail.com" 10 | } 11 | ], 12 | "require": {}, 13 | "autoload": { 14 | "psr-4": { 15 | "alphaz\\Data\\": "" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Container/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alphaz/container", 3 | "description": "The alphaz contianer component", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "lablnet", 9 | "email": "mumerfarooqlablnet01@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "alphaz/data": "dev-master" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "alphaz\\Container\\": "" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Common/Version.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common; 18 | 19 | class Version 20 | { 21 | const VERSION = '3.0.0'; 22 | } 23 | -------------------------------------------------------------------------------- /src/Component/dispatcher.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.9.7 13 | * 14 | * @license MIT 15 | */ 16 | use alphaz\http\Request; 17 | 18 | //Dispatch the request 19 | $com->dispatch(new Request()); 20 | -------------------------------------------------------------------------------- /src/http/ServerRequest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @todo 3.0.1 14 | * 15 | * @license MIT 16 | */ 17 | 18 | namespace alphaz\http; 19 | 20 | class ServerRequest extends Request 21 | { 22 | //TODO 23 | } 24 | -------------------------------------------------------------------------------- /src/http/UploadedFile.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @todo 3.0.1 14 | * 15 | * @license MIT 16 | */ 17 | 18 | namespace alphaz\http; 19 | 20 | class UploadedFile extends \Files\Files 21 | { 22 | //TODO 23 | } 24 | -------------------------------------------------------------------------------- /src/http/Clients/Stream.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @todo 3.0.1 14 | * 15 | * @license MIT 16 | */ 17 | 18 | namespace alphaz\http\Clients; 19 | 20 | class Stream extends AbstractClient 21 | { 22 | //TODO 23 | } 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Requirements** 14 | 1. alphaz Framework Version 15 | 2. PHP Version 16 | 3. Apache version 17 | 4. PlatForm version and name 18 | 5. ErrorLog 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Additional context** 24 | Add any other context about the problem here. 25 | -------------------------------------------------------------------------------- /src/Contracts/Benchmark/Benchmark.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Benchmark; 18 | 19 | interface Benchmark 20 | { 21 | public function start(); 22 | 23 | public function end(); 24 | 25 | public function elapsedTime(int $round); 26 | } 27 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | src 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Tests 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/Database/MYSQL.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | * 15 | * @note this file is deprated and only working not recommended to used only for old users of alphaz Framework 16 | */ 17 | 18 | namespace alphaz\Database; 19 | 20 | use alphaz\Database\Drives\MYSQL\MySqlDb; 21 | 22 | class MYSQL extends MySqlDb 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: lablnet 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /src/Exception/Exception.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Exception; 18 | 19 | use alphaz\Whoops\Whoops; 20 | 21 | class Exception 22 | { 23 | /** 24 | * __construct. 25 | * 26 | * @since 1.0.0 27 | */ 28 | public function __construct() 29 | { 30 | new Whoops(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Common/Logger/LogLevel.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common\Logger; 18 | 19 | class LogLevel 20 | { 21 | const EMERGENCY = 'emergency'; 22 | const ALERT = 'alert'; 23 | const CRITICAL = 'critical'; 24 | const ERROR = 'error'; 25 | const WARNING = 'warning'; 26 | const NOTICE = 'notice'; 27 | const INFO = 'info'; 28 | const DEBUG = 'debug'; 29 | } 30 | -------------------------------------------------------------------------------- /src/Contracts/Common/Root.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Common; 18 | 19 | interface Root 20 | { 21 | /** 22 | * Get the specified path value. 23 | * 24 | * @param string $key 25 | * @param mixed $default 26 | * 27 | * @since 1.0.0 28 | * 29 | * @return mixed 30 | */ 31 | public function get($key, $default = null); 32 | } 33 | -------------------------------------------------------------------------------- /src/http/ValidProtocolVersions.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\http; 18 | 19 | trait ValidProtocolVersions 20 | { 21 | /** 22 | * Valid protocol versions. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var array 27 | */ 28 | protected static $validProtocolVersions = [ 29 | '1.0' => true, 30 | '1.1' => true, 31 | '2.0' => true, 32 | '2' => true, 33 | ]; 34 | } 35 | -------------------------------------------------------------------------------- /src/Contracts/Sitemap/SitemapIndex.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Sitemap; 18 | 19 | interface SitemapIndex 20 | { 21 | /** 22 | * Add item to sitemap. 23 | * 24 | * @param (string) $url Valid url. 25 | * @param (string) $lastMod Last modify. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @return void 30 | */ 31 | public function addItem($url, $lastMod = null): void; 32 | } 33 | -------------------------------------------------------------------------------- /Tests/Site/KeyTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(16, mb_strlen($key, '8bit')); 14 | } 15 | 16 | public function testEncodeAndDecode(): void 17 | { 18 | $key = Key::generate(16); 19 | $this->assertEquals(16, mb_strlen($key, '8bit')); 20 | $encoded = Key::encode($key); 21 | $this->assertEquals(32, mb_strlen($encoded, '8bit')); 22 | $this->assertEquals($key, Key::decode($encoded)); 23 | } 24 | 25 | public function testGenerateEncode(): void 26 | { 27 | $key = Key::generateEncode(16); 28 | $this->assertEquals(32, mb_strlen($key, '8bit')); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Auth/Logout.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @since 1.0.0 18 | * 19 | * @license MIT 20 | */ 21 | 22 | namespace alphaz\Auth; 23 | 24 | class Logout 25 | { 26 | /** 27 | * Logout the user. 28 | * 29 | * @since 1.0.0 30 | * 31 | * @return void 32 | */ 33 | public function __construct() 34 | { 35 | $user = new User(); 36 | $user->logout(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/http/Clients/Client.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\http\Clients; 18 | 19 | class Client 20 | { 21 | /** 22 | * Access to curl clients. 23 | * 24 | * @param (string) $url 25 | * (string) $method 26 | * (array) $options 27 | * 28 | * @since 1.0.0 29 | */ 30 | public function curl($url, $method = 'GET', array $options = null) 31 | { 32 | return new CURL($url, $method, $options); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Tests/Archive/ZipTest.php: -------------------------------------------------------------------------------- 1 | compress($Path, __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.zip'); 15 | $Results = $Archive->extract( 16 | __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.zip', 17 | __DIR__.DIRECTORY_SEPARATOR.'new' 18 | ); 19 | $this->assertTrue($Results); 20 | } 21 | 22 | public function testCompress() 23 | { 24 | $Path = __DIR__.DIRECTORY_SEPARATOR.'alphaz.png'; 25 | $Archive = new Zip(); 26 | $Results = $Archive->compress($Path, __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.zip'); 27 | $this->assertTrue($Results); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tests/Archive/BzipTest.php: -------------------------------------------------------------------------------- 1 | compress($Path, __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.bz'); 15 | $Results = $Archive->extract( 16 | __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.bz', 17 | __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.new' 18 | ); 19 | $this->assertTrue($Results); 20 | } 21 | 22 | public function testCompress() 23 | { 24 | $Path = __DIR__.DIRECTORY_SEPARATOR.'alphaz.png'; 25 | $Archive = new Bzip(); 26 | $Results = $Archive->compress($Path, __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.bz'); 27 | $this->assertTrue($Results); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tests/Archive/GzipTest.php: -------------------------------------------------------------------------------- 1 | compress($Path, __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.gz'); 15 | $Results = $Archive->extract( 16 | __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.gz', 17 | __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.new' 18 | ); 19 | $this->assertTrue($Results); 20 | } 21 | 22 | public function testCompress() 23 | { 24 | $Path = __DIR__.DIRECTORY_SEPARATOR.'alphaz.png'; 25 | $Archive = new Gzip(); 26 | $Results = $Archive->compress($Path, __DIR__.DIRECTORY_SEPARATOR.'alphaz.png.gz'); 27 | $this->assertTrue($Results); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Contracts/Sitemap/Sitemap.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Sitemap; 18 | 19 | interface Sitemap 20 | { 21 | /** 22 | * Add item to sitemap. 23 | * 24 | * @param (string) $url Valid url. 25 | * @param (string) $lastMod Last modify. 26 | * @param (float) $priority Priority. 27 | * @param (string) $changeFreq changeFreq. 28 | * 29 | * @since 1.0.0 30 | * 31 | * @return void 32 | */ 33 | public function addItem($url, $lastMod = null, $priority = 0.5, $changeFreq = 'weekly'): void; 34 | } 35 | -------------------------------------------------------------------------------- /src/Contracts/View/View.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\View; 18 | 19 | interface View 20 | { 21 | /** 22 | * Render a view template. 23 | * 24 | * @param (string) $file Name of files. 25 | * @param (array) $args Attributes. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @return void 30 | */ 31 | public static function renderTemplate($file, $args = []); 32 | 33 | /** 34 | * Compile. 35 | * 36 | * @todo future 37 | * 38 | * @return void 39 | */ 40 | public function compile(); 41 | } 42 | -------------------------------------------------------------------------------- /Tests/Common/RootTest.php: -------------------------------------------------------------------------------- 1 | root = new Root($this->roots = [ 23 | 'path' => 'root', 24 | ]); 25 | parent::setUp(); 26 | } 27 | 28 | public function testConstruct() 29 | { 30 | $this->assertInstanceOf(Root::class, $this->root); 31 | } 32 | 33 | public function testGet() 34 | { 35 | $this->assertSame('root', $this->root->get('path')); 36 | } 37 | 38 | public function testGetWithDefault() 39 | { 40 | $this->assertSame('default', $this->root->get('not-exist', 'default')); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/Container/ContainerTest.php: -------------------------------------------------------------------------------- 1 | register([Message::class, 'Message'], $msg, false); 17 | 18 | $this->assertFalse($container->isSingleton('Message')); 19 | 20 | $instance2 = $container->register([Message::class, 'Message'], $msg, true); 21 | 22 | $this->assertTrue($container->isSingleton('Message')); 23 | } 24 | 25 | public function testException() 26 | { 27 | $container = new Container(); 28 | 29 | $this->expectException(\InvalidArgumentException::class); 30 | 31 | $instance3 = $container->register(['Invalid', 'Invalid'], null, true); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.github/workflows/branch.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | # Sequence of patterns matched against refs/tags 4 | tags: 5 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 6 | 7 | name: Create Branch 8 | 9 | jobs: 10 | build: 11 | name: Create Branch 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout code 15 | uses: actions/checkout@v2 16 | - name: Create Branch 17 | id: create_branch 18 | uses: lablnet/create-branch-from-tag@v1 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token 21 | with: 22 | tag_name: ${{ github.ref }} 23 | owner: ${{ github.repository_owner }} # https://docs.github.com/en/actions/learn-github-actions/contexts#example-contents-of-the-github-context 24 | repo: ${{ github.event.repository.name }} # https://www.reddit.com/r/github/comments/tjkj6f/get_repo_name_on_github_actions_without_owner/ 25 | -------------------------------------------------------------------------------- /src/Hashing/Argon2IdHashing.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Hashing; 18 | 19 | class Argon2IdHashing extends ArgonHashing 20 | { 21 | /** 22 | * Get the algroithm. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @return \Constant 27 | */ 28 | protected function algorithm() 29 | { 30 | return \PASSWORD_ARGON2ID; 31 | } 32 | 33 | /** 34 | * Get the algroithm keys. 35 | * 36 | * @since 1.0.0 37 | * 38 | * @return string 39 | */ 40 | protected function algorithmKeys() 41 | { 42 | return 'argon2id'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Contracts/SystemMessage/SystemMessage.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\SystemMessage; 18 | 19 | interface SystemMessage 20 | { 21 | /** 22 | * Add the system message. 23 | * 24 | * @param $params['msg'] => message to be store 25 | * $params['type'] => alert type 26 | * 27 | * @since 1.0.0 28 | * 29 | * @return bool 30 | */ 31 | public function add($params); 32 | 33 | /** 34 | * View the system message. 35 | * 36 | * @since 1.0.0 37 | * 38 | * @return string 39 | */ 40 | public function view(); 41 | } 42 | -------------------------------------------------------------------------------- /src/Validation/JsonRules.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | */ 15 | 16 | namespace alphaz\Validation; 17 | 18 | class JsonRules extends StickyRules 19 | { 20 | /** 21 | * Evaulate Json. 22 | * 23 | * @param $value Value to be checked 24 | * 25 | * @return bool 26 | */ 27 | public function validate($value) 28 | { 29 | if ($this->notBeEmpty($value)) { 30 | $value = json_decode($value); 31 | if ($value !== null) { 32 | return true; 33 | } else { 34 | return false; 35 | } 36 | } else { 37 | return false; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Contracts/Encryption/Adapter/AbstractAdapter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Encryption\Adapter; 18 | 19 | interface AbstractAdapter 20 | { 21 | /** 22 | * Encrypt the message. 23 | * 24 | * @param (mixed) $data data to be encrypted 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return mixed 29 | */ 30 | public function encrypt($data); 31 | 32 | /** 33 | * Decrypt the message. 34 | * 35 | * @param (mixed) $token encrypted token 36 | * 37 | * @since 1.0.0 38 | * 39 | * @return mixed 40 | */ 41 | public function decrypt($token); 42 | } 43 | -------------------------------------------------------------------------------- /src/Validation/StickyRules.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | */ 15 | 16 | namespace alphaz\Validation; 17 | 18 | class StickyRules 19 | { 20 | /** 21 | * Evaulate required. 22 | * 23 | * @param $value Value to be checked 24 | * 25 | * @return bool 26 | */ 27 | public function notBeEmpty($value) 28 | { 29 | return (!empty($this->removeSpaces($value))) ? true : false; 30 | } 31 | 32 | /** 33 | * Remove spaces. 34 | * 35 | * @param $value Value to be checked 36 | * 37 | * @return value 38 | */ 39 | public function removeSpaces($value) 40 | { 41 | return escape($value); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Tests/Encryption/EncryptionTest.php: -------------------------------------------------------------------------------- 1 | encrypt($str); 16 | $this->assertNotSame($str, $encryptHash); 17 | $this->assertSame($str, $openSslEncryption->decrypt($encryptHash)); 18 | } 19 | 20 | public function testSodiumEncrypt() 21 | { 22 | $sodiumEncryption = new SodiumEncryption('asdfghtrewbg458793210lopkmfjritj'); 23 | $str = 'This is a string'; 24 | $encryptHash = $sodiumEncryption->encrypt($str); 25 | $this->assertNotSame($str, $encryptHash); 26 | $this->assertSame($str, $sodiumEncryption->decrypt($encryptHash)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Contracts/Sitemap/AbstractSitemap.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Sitemap; 18 | 19 | interface AbstractSitemap 20 | { 21 | /** 22 | * Determine whether the sitemap exists. 23 | * 24 | * @param (string) $file File name with extension (.xml). 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return bool 29 | */ 30 | public function has($file): bool; 31 | 32 | /** 33 | * Delete the sitemap. 34 | * 35 | * @param (string) $file File name with extension (.xml). 36 | * 37 | * @since 1.0.0 38 | * 39 | * @return object 40 | */ 41 | public function delete($file): self; 42 | } 43 | -------------------------------------------------------------------------------- /src/Component/View/View.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | */ 15 | 16 | namespace alphaz\Component\View; 17 | 18 | class View extends \alphaz\View\View 19 | { 20 | /** 21 | * Rander the view. 22 | * 23 | * @param (string) $file Name of files 24 | * @param (array) $args Attributes. 25 | * @param (bool) $minify Is code should be minify 26 | * @param (array) $headers Custom headers. 27 | * 28 | * @since 1.0.0 29 | * 30 | * @return mixed 31 | */ 32 | public static function rander($file, array $args = [], bool $minify = false, array $headers = []) 33 | { 34 | static::$isCom = true; 35 | self::view($file, $args, $minify); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Contracts/Sitemap/SitemapWriter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Sitemap; 18 | 19 | interface SitemapWriter 20 | { 21 | /** 22 | * Write on sitemap file. 23 | * 24 | * @param (xml) $data Valid XML 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return void 29 | */ 30 | public function write($data): void; 31 | 32 | /** 33 | * Read the sitemap file. 34 | * 35 | * @since 1.0.0 36 | * 37 | * @return xml 38 | */ 39 | public function read(): string; 40 | 41 | /** 42 | * Close the sitemap file. 43 | * 44 | * @since 1.0.0 45 | * 46 | * @return void 47 | */ 48 | public function close(): void; 49 | } 50 | -------------------------------------------------------------------------------- /src/Contracts/Auth/Update.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Auth; 18 | 19 | interface Update 20 | { 21 | /** 22 | * Update the users. 23 | * 24 | * @param (array) $paramsfields like [name => thisname] 25 | * @param (int) $id id of user 26 | * 27 | * @return void 28 | */ 29 | public function update($params, $id); 30 | 31 | /** 32 | * Check is username is exists or not. 33 | * 34 | * @param (mixed) $password password of user 35 | * @param (mixed) $repeat confirm password 36 | * @param (int) $id id of user 37 | * 38 | * @since 1.0.0 39 | * 40 | * @return void 41 | */ 42 | public function updatePassword($password, $repeat, $id); 43 | } 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2020 alphaz Framework members and contributers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alphaz/framework", 3 | "description": "The AlphaZ Framework.", 4 | "keywords": ["framework", "alphaz"], 5 | "license": "MIT", 6 | "require": { 7 | "php": "^7.3|^8.0", 8 | "ext-mbstring": "*" 9 | }, 10 | "require-dev": { 11 | "phpunit/phpunit": "^9.4" 12 | }, 13 | "support": { 14 | "issues": "https://github.com/alphazframework/framework/issues", 15 | "source": "https://github.com/alphazframework/framework" 16 | }, 17 | "authors": [ 18 | { 19 | "name": "Muhamamad Umer Farooq", 20 | "email":"umer@lablnet.com", 21 | "homepage": "https://lablnet.com/" 22 | } 23 | ], 24 | "autoload": { 25 | "psr-4": { 26 | "alphaz\\": "src/" 27 | }, 28 | "files":["src/functions/helpers.php"] 29 | }, 30 | "autoload-dev": { 31 | "psr-4": { 32 | "Framework\\Tests\\": "Tests/" 33 | } 34 | }, 35 | "scripts": { 36 | "test": "vendor/bin/phpunit" 37 | }, 38 | "config":{ 39 | "optimize-autoloader":true 40 | }, 41 | "prefer-stable": true 42 | } 43 | -------------------------------------------------------------------------------- /src/Database/Db.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | */ 15 | 16 | namespace alphaz\Database; 17 | 18 | use alphaz\Database\Drives\MYSQL\MySqlDb as MYSQL; 19 | use alphaz\Database\Drives\SqLite\SqLite; 20 | 21 | class Db 22 | { 23 | private $db; 24 | 25 | public function __construct() 26 | { 27 | if (strtolower(__config()->database->db_driver) === 'mysql') { 28 | $this->db = (new MYSQL()); 29 | } elseif (strtolower(__config()->database->db_driver) === 'sqlite') { 30 | $this->db = (new SqLite()); 31 | } else { 32 | $db_driver = __config()->database->db_driver; 33 | 34 | throw new \Exception("Driver {$db_driver} is not supportd!", 500); 35 | } 36 | } 37 | 38 | public function db() 39 | { 40 | return $this->db; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /.github/workflows/api_docs.yml: -------------------------------------------------------------------------------- 1 | name: Build Api Documentation 2 | on: 3 | push: 4 | branches: [main] 5 | jobs: 6 | build-api: 7 | name: Build api 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v3 12 | - name: Checkout api repository 13 | uses: actions/checkout@v3 14 | with: 15 | repository: alphazframework/api 16 | path: api 17 | - name: Setup PHP 18 | uses: shivammathur/setup-php@v2 19 | with: 20 | php-version: 7.3 21 | extensions: mbstring, dom, json, libxml, xml, xmlwriter 22 | coverage: none 23 | - name: Download phpDocumentor 24 | run: wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.0.0/phpDocumentor.phar 25 | - name: Build api documentation 26 | run: php phpDocumentor.phar -d ./src . -t ./api 27 | - name: Deploy api documentation site 28 | uses: peaceiris/actions-gh-pages@v2 29 | env: 30 | PERSONAL_TOKEN: ${{ secrets.AUTH_TOKEN }} 31 | EXTERNAL_REPOSITORY: alphazframework/api 32 | PUBLISH_BRANCH: master 33 | PUBLISH_DIR: ./api 34 | -------------------------------------------------------------------------------- /src/Auth/Success.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Auth; 18 | 19 | class Success 20 | { 21 | /** 22 | * Store the success msgs. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var mixed 27 | */ 28 | private static $success; 29 | 30 | /** 31 | * Set the success msgs. 32 | * 33 | * @param (string) $success message 34 | * 35 | * @since 1.0.0 36 | * 37 | * @return void 38 | */ 39 | public static function set($success) 40 | { 41 | static::$success = $success; 42 | } 43 | 44 | /** 45 | * Get the success message. 46 | * 47 | * @since 1.0.0 48 | * 49 | * @return string 50 | */ 51 | public function get() 52 | { 53 | return static::$success; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Tests/Common/PasswordManipulationTest.php: -------------------------------------------------------------------------------- 1 | assertNotEmpty($pass->generatePassword()); 14 | } 15 | 16 | public function testCountTes() 17 | { 18 | $pass = new PasswordManipulation(); 19 | $this->assertSame(6, $pass->len(123456)); 20 | } 21 | 22 | public function testIsValid() 23 | { 24 | $pass = new PasswordManipulation(); 25 | $this->assertTrue($pass->isValid($pass->generatePassword())); 26 | $this->assertFalse($pass->isValid('1234dasd')); 27 | } 28 | 29 | public function testSetLength() 30 | { 31 | $pass = new PasswordManipulation(); 32 | $pass->setLength(21); 33 | $this->assertNotEmpty($pass->getLength()); 34 | } 35 | 36 | public function testGetLength() 37 | { 38 | $pass = new PasswordManipulation(); 39 | $this->assertNotEmpty($pass->getLength()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # How to report an issue on GitHub 2 | ## Requirements: 3 | To report an issue on Github following conditions must be followed: 4 | 5 | * alphaz Framework version 6 | * PHP version 7 | * Error message 8 | * Error Log 9 | * Issue screenshots 10 | * Apache version (optional) 11 | * MySQL version (if possible) 12 | ### Before submitting a bug report 13 | 14 | * Search for issue already or not 15 | ### After submitting a bug report ### 16 | 17 | * Wait until the core team replies to you. 18 | * Do what core team says. Don't argue with core team. 19 | 20 | # How to contribute on GitHub 21 | We always welcome contributions, as long as they follow our guidelines. 22 | * You never allow add third-party composer dependencies or classes. 23 | * You allow to improve existing features or add new features. 24 | * You allow update our alphaz framework code or core code. 25 | * When you want send poll request you have provide brief description about code either you update exsting code or adding new feature. 26 | * alphaz => https://github.com/alphazframework/alphaz 27 | * Core => https://github.com/alphazframework/framework 28 | 29 | **[NOTE: The conditions above apply to all members except core]** 30 | -------------------------------------------------------------------------------- /src/Validation/databaseRules.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | */ 15 | 16 | namespace alphaz\Validation; 17 | 18 | use alphaz\Database\Db as DB; 19 | 20 | class databaseRules extends StickyRules 21 | { 22 | /** 23 | * Evaulate unique. 24 | * 25 | * @param $column Table column 26 | * $value Value to be checked 27 | * $table Database table 28 | * 29 | * @return bool 30 | */ 31 | public function unique($column, $value, $table) 32 | { 33 | $db = new DB(); 34 | $result = $db->db()->count(['db_name'=>__config()->database->db_name, 'table'=>$table, 'wheres' => [$column.' ='."'{$value}'"]]); 35 | $db->db()->close(); 36 | if ($result === 0) { 37 | return true; 38 | } else { 39 | return false; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/Mail/MailTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 16 | } 17 | 18 | /* 19 | * @test 20 | */ 21 | /*public function can_send_email_with_user_selected_driver() 22 | { 23 | 24 | $file = __DIR__.'/../phpunit-book.pdf'; 25 | 26 | $mail = new Mail; 27 | //Set subject. 28 | $mail->setSubject('Example mail'); 29 | //Sender, like support@example.com 30 | $mail->setSender('noreply@alphazframework.xyz'); 31 | //Set the plain content of the mail. 32 | $mail->setContentPlain('Example plain-content!'); 33 | //Add a receiver of the mail (you can add more than one receiver too). 34 | $mail->addReceiver('lablnet01@gmail.com'); 35 | $mail->addAttachment($file); 36 | 37 | if ($mail->send()) { 38 | $this->assertSame('Queued. Thank you.'); 39 | } else { 40 | $this->assertSame('Sorry, mail not send'); 41 | } 42 | 43 | }*/ 44 | } 45 | -------------------------------------------------------------------------------- /src/Auth/EmailHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Auth; 18 | 19 | use alphaz\Mail\Mail; 20 | 21 | class EmailHandler 22 | { 23 | /** 24 | * Send the email msg. 25 | * 26 | * @param (string) $subject subject of email 27 | * @param (mixeds) $html body of email 28 | * @param (mixed) $email user email 29 | * 30 | * @since 1.0.0 31 | * 32 | * @return void 33 | */ 34 | public function __construct($subject, $html, $email) 35 | { 36 | $mail = new Mail(); 37 | $mail->setSubject($subject); 38 | $mail->setSender(__config()->email->site_email); 39 | $mail->setContentHTML($html); 40 | $mail->addReceiver($email); 41 | if (__config()->auth->is_smtp) { 42 | $mail->isSMTP(true); 43 | } 44 | $mail->send(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Hashing/AbstractHashing.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Hashing; 18 | 19 | abstract class AbstractHashing 20 | { 21 | /** 22 | * Get information about the given hash. 23 | * 24 | * @param (string) $hash 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return array 29 | */ 30 | public function info($hash) 31 | { 32 | return password_get_info($hash); 33 | } 34 | 35 | /** 36 | * Verify the hash value. 37 | * 38 | * @param (string) $original 39 | * @param (string) $hash 40 | * 41 | * @since 1.0.0 42 | * 43 | * @return bool 44 | */ 45 | public function verify($original, $hash) 46 | { 47 | if (empty($hash)) { 48 | return false; 49 | } 50 | 51 | return password_verify($original, $hash); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /.github/workflows/monorepo_split.yml: -------------------------------------------------------------------------------- 1 | # Split monorepo via splitsh-lite 2 | name: Split monorepo 3 | on: 4 | push: 5 | branches: [main] 6 | jobs: 7 | split: 8 | name: split 9 | strategy: 10 | matrix: 11 | library: ['Files', 'Data', 'Cookies', 'Session', 'Container', 'Archive'] 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v3 16 | - uses: actions/cache@v3 17 | id: cache 18 | with: 19 | path: ./splitsh 20 | key: ${{ runner.os }}-${{ hashFiles('**/composer.json') }} 21 | - name: Install splitsh 22 | if: steps.cache.outputs.cache-hit != 'true' 23 | run: | 24 | mkdir ./splitsh 25 | wget https://github.com/splitsh/lite/releases/download/v1.0.1/lite_linux_amd64.tar.gz 26 | tar -zxpf lite_linux_amd64.tar.gz --directory ./splitsh 27 | - name: Split and update ${{ matrix.library }} 28 | run: | 29 | SHA1=`./splitsh/splitsh-lite --prefix=src/${{ matrix.library }}` 30 | git remote add ${{ matrix.library }} https://${{ secrets.AUTH_TOKEN }}@github.com/alphazframework/${{ matrix.library }} 31 | git push -f ${{ matrix.library }} ${SHA1}:refs/heads/ref/heads/main 32 | -------------------------------------------------------------------------------- /src/Contracts/Encryption/Encrypt.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Encryption; 18 | 19 | interface Encrypt 20 | { 21 | /** 22 | * Set the adapter. 23 | * 24 | * @param (string) $adapter 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return object 29 | */ 30 | public static function setAdapter($adapter); 31 | 32 | /** 33 | * Encrypt the message. 34 | * 35 | * @param (mixed) $data data to be encrypted 36 | * 37 | * @since 1.0.0 38 | * 39 | * @return mixed 40 | */ 41 | public static function encrypt($data, $adapter = null); 42 | 43 | /** 44 | * Decrypt the message. 45 | * 46 | * @param (mixed) $token encrypted token 47 | * 48 | * @since 1.0.0 49 | * 50 | * @return mixed 51 | */ 52 | public static function decrypt($token, $adapter = null); 53 | } 54 | -------------------------------------------------------------------------------- /src/Encryption/Adapter/AbstractAdapter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Encryption\Adapter; 18 | 19 | use alphaz\Contracts\Encryption\Adapter\AbstractAdapter as AbstractAdapterContract; 20 | 21 | abstract class AbstractAdapter implements AbstractAdapterContract 22 | { 23 | /** 24 | * Store the secret key. 25 | * 26 | * @since 1.0.0 27 | * 28 | * @var key 29 | */ 30 | protected $key; 31 | 32 | /** 33 | * Encrypt the message. 34 | * 35 | * @param (mixed) $data data to be encrypted 36 | * 37 | * @since 1.0.0 38 | * 39 | * @return mixed 40 | */ 41 | abstract public function encrypt($data); 42 | 43 | /** 44 | * Decrypt the message. 45 | * 46 | * @param (mixed) $token encrypted token 47 | * 48 | * @since 1.0.0 49 | * 50 | * @return mixed 51 | */ 52 | abstract public function decrypt($token); 53 | } 54 | -------------------------------------------------------------------------------- /src/Contracts/Common/Configuration.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Common; 18 | 19 | interface Configuration 20 | { 21 | /** 22 | * Determine if the given configuration value exists. 23 | * 24 | * @param string $key 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return bool 29 | */ 30 | public function has($key); 31 | 32 | /** 33 | * Get the specified configuration value. 34 | * 35 | * @param string $key 36 | * @param mixed $default 37 | * 38 | * @since 1.0.0 39 | * 40 | * @return mixed 41 | */ 42 | public function get($key, $default = null); 43 | 44 | /** 45 | * Set a given configuration value. 46 | * 47 | * @param array|string $key 48 | * @param mixed $value 49 | * 50 | * @since 1.0.0 51 | * 52 | * @return void 53 | */ 54 | public function set($key, $value = null); 55 | } 56 | -------------------------------------------------------------------------------- /src/http/Redirect.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\http; 18 | 19 | class Redirect extends HTTP 20 | { 21 | /** 22 | * Send redirect. 23 | * 24 | * @param (string) $url 25 | * @param (int) $code 26 | * @param (mixed) $version 27 | * 28 | * @since 1.0.0 29 | * 30 | * @return void 31 | */ 32 | public function __construct($url, $code = '302', $version = '1.1') 33 | { 34 | if (headers_sent()) { 35 | throw new \Exception('The headers have already been sent.'); 36 | } 37 | 38 | if (!array_key_exists($code, self::$responseCodes)) { 39 | throw new \Exception('The header code '.$code.' is not allowed.'); 40 | } 41 | 42 | header("HTTP/{$version} {$code} ".self::$responseCodes[$code]); 43 | header("Location: {$url}"); 44 | 45 | //Need to stop current execution after redirect. 46 | exit; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | run: 7 | runs-on: ${{ matrix.operating-system }} 8 | strategy: 9 | matrix: 10 | operating-system: [ubuntu-latest] #[ubuntu-latest, macos-latest, windows-latest] 11 | php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] 12 | name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v3 17 | 18 | - name: Setup PHP 19 | uses: shivammathur/setup-php@v2 20 | with: 21 | php-version: ${{ matrix.php-versions }} 22 | extensions: mbstring, pdo, pdo_mysql, intl, zip, sodium, bz2, gzip 23 | 24 | - name: Check PHP Version 25 | run: php -v 26 | 27 | - name: Check Composer Version 28 | run: composer -V 29 | 30 | - name: Check PHP Extensions 31 | run: php -m 32 | 33 | - name: Validate composer.json and composer.lock 34 | run: composer validate 35 | 36 | - name: Install dependencies 37 | run: composer install --no-suggest --no-progress --no-interaction 38 | 39 | - name: Run test suite 40 | run: vendor/bin/phpunit --configuration 'phpunit.xml' --bootstrap 'vendor/autoload.php' --test-suffix 'Test.php,.phpt' --coverage-text 41 | -------------------------------------------------------------------------------- /src/Common/AliasLoader.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common; 18 | 19 | class AliasLoader 20 | { 21 | /** 22 | * Class aliases. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var array 27 | */ 28 | protected $aliases; 29 | 30 | /** 31 | * __construct. 32 | * 33 | * @param (array) $aliases Class aliases 34 | * 35 | * @since 1.0.0 36 | */ 37 | public function __construct($aliases) 38 | { 39 | $this->aliases = $aliases; 40 | } 41 | 42 | /** 43 | * Autoloads aliased classes. 44 | * 45 | * @param (string) $alias Class alias 46 | * 47 | * @since 1.0.0 48 | * 49 | * @return bool 50 | */ 51 | public function load($alias) 52 | { 53 | if (array_key_exists($alias, $this->aliases)) { 54 | return class_alias($this->aliases[$alias], $alias); 55 | } 56 | 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Contracts/Zip/Zip.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | * 15 | * @since 1.0.0 16 | */ 17 | 18 | namespace alphaz\Contracts\Zip; 19 | 20 | interface Zip 21 | { 22 | /** 23 | * Open zip extract zip. 24 | * 25 | * @param (string) $file file that you want uncompress/open 26 | * @param (string) $target where you extract file 27 | * @param (bool) $delete true delete zip file false not delete 28 | * 29 | * @since 1.0.0 30 | * 31 | * @return bool 32 | */ 33 | public function extract($file, $target, $delete = false); 34 | 35 | /** 36 | * Compress file into zip. 37 | * 38 | * @param (string) $file file that you want compress 39 | * @param (string) $destination destination 40 | * @param (bool)d $overwrite true delete zip file false not delete 41 | * 42 | * @since 1.0.0 43 | * 44 | * @return bool 45 | */ 46 | public function compress($files = [], $destination = '', $overwrite = false); 47 | } 48 | -------------------------------------------------------------------------------- /src/Console/Commands.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console; 21 | 22 | class Commands 23 | { 24 | /** 25 | * Internal commands. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @var array 30 | */ 31 | protected $commands = [ 32 | ['version', \alphaz\Console\Commands\Version::class], 33 | ['list', \alphaz\Console\Commands\ListCmd::class], 34 | ['make:controller', \alphaz\Console\Commands\Controller::class], 35 | ['clear:cache', \alphaz\Console\Commands\Cache::class], 36 | ['serve', \alphaz\Console\Commands\ServeCommand::class], 37 | 38 | ]; 39 | 40 | /** 41 | * Get commands. 42 | * 43 | * @since 1.0.0 44 | * 45 | * @var array 46 | */ 47 | public function getCommands(): array 48 | { 49 | return $this->commands; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Common/Model/Model.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common\Model; 18 | 19 | class Model 20 | { 21 | /** 22 | * Model. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var string 27 | */ 28 | private $model; 29 | 30 | /** 31 | * Set the model. 32 | * 33 | * @param (string) $model model name 34 | * 35 | * @since 1.0.0 36 | * 37 | * @return resource 38 | */ 39 | public function set($model) 40 | { 41 | $this->model = '\App\Models\\'.$model; 42 | 43 | return $this; 44 | } 45 | 46 | /** 47 | * Get the instance of model class. 48 | * 49 | * @since 1.0.0 50 | * 51 | * @return resource 52 | */ 53 | public function execute() 54 | { 55 | if (class_exists($this->model)) { 56 | return new $this->model(); 57 | } 58 | 59 | throw new \Exception("The model Class {$this->model} not found", 500); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Contracts/Encryption/Encryption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Encryption; 18 | 19 | interface Encryption 20 | { 21 | /** 22 | * __construct. 23 | * 24 | * @since 1.0.0 25 | */ 26 | public function __construct($adaoter = null); 27 | 28 | /** 29 | * Set the adapter. 30 | * 31 | * @param (string) $adapter 32 | * 33 | * @since 1.0.0 34 | * 35 | * @return object 36 | */ 37 | public function setAdapter($adapter); 38 | 39 | /** 40 | * Encrypt the message. 41 | * 42 | * @param (mixed) $data data to be encrypted 43 | * 44 | * @since 1.0.0 45 | * 46 | * @return mixed 47 | */ 48 | public function encrypt($data); 49 | 50 | /** 51 | * Decrypt the message. 52 | * 53 | * @param (mixed) $token encrypted token 54 | * 55 | * @since 1.0.0 56 | * 57 | * @return mixed 58 | */ 59 | public function decrypt($token); 60 | } 61 | -------------------------------------------------------------------------------- /src/Component/Router.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.9.7 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Component; 18 | 19 | use alphaz\Files\FileHandling; 20 | 21 | class Router extends Component 22 | { 23 | /** 24 | * Load the components. 25 | * 26 | * @since 1.9.7 27 | * 28 | * @return void 29 | */ 30 | public static function loadComponents() 31 | { 32 | $com = new Component(); 33 | $file = new FileHandling(); 34 | $diskScan = array_diff(scandir(route('com')), ['..', '.']); 35 | foreach ($diskScan as $scans) { 36 | $configFile = route('com').$scans.'/component.json'; 37 | if (file_exists($configFile)) { 38 | $c = $file->open($configFile, 'readOnly')->read(); 39 | $file->close(); 40 | $config = json_decode($c, true); 41 | if ($config['status'] === true) { 42 | require_once route('com').$scans.'/routes.php'; 43 | } 44 | } 45 | } 46 | require_once 'dispatcher.php'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Common/TimeZone.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common; 18 | 19 | class TimeZone extends \DateTimeZone 20 | { 21 | /** 22 | * Set Default timeZone. 23 | * 24 | * @param string $tz valid time zone 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return void 29 | */ 30 | public static function seteDefaultTz($tz): void 31 | { 32 | date_default_timezone_set(static::validate($tz)); 33 | } 34 | 35 | /** 36 | * Get the valid timeZone identifiers. 37 | * 38 | * @since 1.0.0 39 | * 40 | * @return void 41 | */ 42 | public static function tZIdentifiers(): array 43 | { 44 | return static::listIdentifiers(); 45 | } 46 | 47 | /** 48 | * Validate timeZone. 49 | * 50 | * @param (string) $tz valid time zone 51 | * 52 | * @since 1.0.0 53 | * 54 | * @return void 55 | */ 56 | public static function validate($tz): string 57 | { 58 | return in_array($tz, static::tZIdentifiers()) ? $tz : 'UTC'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Data/Contracts/StrContract.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Data\Contracts; 18 | 19 | interface StrContract 20 | { 21 | /** 22 | * Reverse the string. 23 | * 24 | * @param string $str String to be evaluated. 25 | * @param string $encoding Valid encoding. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @return string 30 | */ 31 | public static function reverse(string $str, $encoding = null): string; 32 | 33 | /** 34 | * Concat the strings. 35 | * 36 | * @param string $g With concat. 37 | * @param string $str String to concat. 38 | * 39 | * @since 1.0.0 40 | * 41 | * @return bool 42 | */ 43 | public static function concat($g, ...$str); 44 | 45 | /** 46 | * Count the string. 47 | * 48 | * @param string $str String to be counted. 49 | * @param string $encoding Valid encoding. 50 | * 51 | * @since 1.0.0 52 | * 53 | * @return int 54 | */ 55 | public static function count(string $str, $encoding = null); 56 | } 57 | -------------------------------------------------------------------------------- /Tests/Common/EnvTest.php: -------------------------------------------------------------------------------- 1 | config = new Env($this->configs = [ 23 | 'name' => 'alphaz', 24 | 'version' => '3.0.0', 25 | 'null' => null, 26 | 'encryption' => [ 27 | 'key' => 'xxx', 28 | 'adapter' => 'yyy', 29 | ], 30 | ]); 31 | parent::setUp(); 32 | } 33 | 34 | public function testConstruct() 35 | { 36 | $this->assertInstanceOf(Env::class, $this->config); 37 | } 38 | 39 | public function testGet() 40 | { 41 | $this->assertSame('alphaz', $this->config->get('name')); 42 | } 43 | 44 | public function testGetWithArrayOfKeys() 45 | { 46 | $this->assertSame('alphaz', $this->config->get('name')); 47 | } 48 | 49 | public function testGetWithDefault() 50 | { 51 | $this->assertSame('default', $this->config->get('not-exist', 'default')); 52 | } 53 | 54 | public function testAll() 55 | { 56 | $this->assertSame($this->configs, $this->config->all()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Archive/Adapter/AdapterInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * @link https://github.com/alphazframework/framework 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | * 12 | * @license MIT 13 | * 14 | * @since 1.0.0 15 | */ 16 | 17 | namespace alphaz\Archive\Adapter; 18 | 19 | interface AdapterInterface 20 | { 21 | /** 22 | * Open and extract the archive. 23 | * 24 | * @param (string) $file The file that you want uncompress/open. 25 | * @param (string) $target Where to extract the file. 26 | * @param (bool) $delete True to delete the file; False to not delete it. 27 | * 28 | * @return bool True when succeeded; False when failed. 29 | */ 30 | public function extract(string $file = '', string $target = '', bool $delete = false): bool; 31 | 32 | /** 33 | * Compress the file to an archive. 34 | * 35 | * @param (mixed) $files The file(/s) that you want to compress. 36 | * @param (string) $destination The file destination. 37 | * @param (bool) $overwrite True to delete the file; False to not delete it. 38 | * 39 | * @return bool True when succeeded; False when failed. 40 | */ 41 | public function compress($files, string $destination = '', bool $overwrite = false): bool; 42 | } 43 | -------------------------------------------------------------------------------- /src/Router/App.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Router; 18 | 19 | use alphaz\Cache\Cache; 20 | 21 | class App extends Router 22 | { 23 | /** 24 | * Run the alphaz Framework. 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return bool 29 | */ 30 | public function run() 31 | { 32 | $router = new Router(); 33 | $cache = new Cache('file'); 34 | if (file_exists('../Routes/Routes.php')) { 35 | $routeFile = '../Routes/Routes.php'; 36 | } elseif (file_exists('Routes/Routes.php')) { 37 | $routeFile = 'Routes/Routes.php'; 38 | } else { 39 | throw new \Exception('Error while loading Route.php file', 500); 40 | } 41 | if (__config('app.router_cache') === true) { 42 | if (!$cache->has('router')) { 43 | require_once $routeFile; 44 | $router->cacheRouters(); 45 | } else { 46 | $router->routes = $router->loadCache(); 47 | } 48 | } else { 49 | require_once $routeFile; 50 | } 51 | 52 | return $router; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Contracts/Auth/Auth.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Auth; 18 | 19 | interface Auth 20 | { 21 | /** 22 | * Instance of signup class. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @return object 27 | */ 28 | public function signup(); 29 | 30 | /** 31 | * Instance of signin class. 32 | * 33 | * @since 1.0.0 34 | * 35 | * @return object 36 | */ 37 | public function signin(); 38 | 39 | /** 40 | * Instance of logout class. 41 | * 42 | * @since 1.0.0 43 | * 44 | * @return object 45 | */ 46 | public function logout(); 47 | 48 | /** 49 | * Instance of update class. 50 | * 51 | * @since 1.0.0 52 | * 53 | * @return object 54 | */ 55 | public function update(); 56 | 57 | /** 58 | * Instance of verify class. 59 | * 60 | * @since 1.0.0 61 | * 62 | * @return object 63 | */ 64 | public function verify(); 65 | 66 | /** 67 | * Instance of reset class. 68 | * 69 | * @since 1.0.0 70 | * 71 | * @return object 72 | */ 73 | public function reset(); 74 | } 75 | -------------------------------------------------------------------------------- /src/Contracts/Site/Key.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Site; 18 | 19 | interface Key 20 | { 21 | /** 22 | * Converts a binary key into its hexadecimal representation. 23 | * 24 | * @param string $key Binary key 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return string 29 | */ 30 | public static function encode(string $key): string; 31 | 32 | /** 33 | * Converts a hexadecimal key into its binary representation. 34 | * 35 | * @param string $key Binary key 36 | * 37 | * @since 1.0.0 38 | * 39 | * @return string 40 | */ 41 | public static function decode(string $key): string; 42 | 43 | /** 44 | * Generates a key. 45 | * 46 | * @param int $length Key length 47 | * 48 | * @since 1.0.0 49 | * 50 | * @return string 51 | */ 52 | public static function generate(int $length = 32): string; 53 | 54 | /** 55 | * Generates a hex encoded key. 56 | * 57 | * @param int $length Key length 58 | * 59 | * @since 1.0.0 60 | * 61 | * @return string 62 | */ 63 | public static function generateEncode(int $length = 32): string; 64 | } 65 | -------------------------------------------------------------------------------- /.github/workflows/split_releases.yml: -------------------------------------------------------------------------------- 1 | # Push release tags on sub-repos 2 | name: Push releases 3 | on: 4 | release: 5 | types: [published] 6 | jobs: 7 | split-release: 8 | name: Split release 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | library: ['Files', 'Data', 'Cookies', 'Session', 'Container', 'Archive'] 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v3 17 | - name: Get the tag name 18 | uses: olegtarasov/get-tag@v2.1 19 | id: tagName 20 | - uses: actions/cache@v3 21 | id: cache 22 | with: 23 | path: ./splitsh 24 | key: ${{ runner.os }}-${{ hashFiles('**/composer.json') }} 25 | - name: Install splitsh 26 | if: steps.cache.outputs.cache-hit != 'true' 27 | run: | 28 | mkdir ./splitsh 29 | wget https://github.com/splitsh/lite/releases/download/v1.0.1/lite_linux_amd64.tar.gz 30 | tar -zxpf lite_linux_amd64.tar.gz --directory ./splitsh 31 | - name: Update ${{ matrix.library }} repository 32 | run: | 33 | SHA1=`./splitsh/splitsh-lite --prefix=src/${{ matrix.library }} --origin=refs/tags/${{ steps.tagName.outputs.tag }}` 34 | git remote add ${{ matrix.library }} https://${{ secrets.AUTH_TOKEN }}@github.com/alphazframework/${{ matrix.library }} 35 | git push -f ${{ matrix.library }} ${SHA1}:master 36 | git tag -d ${{ steps.tagName.outputs.tag }} 37 | git tag ${{ steps.tagName.outputs.tag }} ${SHA1} 38 | git push ${{ matrix.library }} ${{ steps.tagName.outputs.tag }} 39 | -------------------------------------------------------------------------------- /src/Benchmark/Benchmark.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Benchmark; 18 | 19 | use alphaz\Contracts\Benchmark as BenchmarkContract; 20 | 21 | class Benchmark implements BenchmarkContract 22 | { 23 | /** 24 | * Store start time. 25 | * 26 | * @since 1.0.0 27 | * 28 | * @var int 29 | */ 30 | private $start; 31 | 32 | /** 33 | * Store end time. 34 | * 35 | * @since 1.0.0 36 | * 37 | * @var int 38 | */ 39 | private $end; 40 | 41 | /** 42 | * Start time. 43 | * 44 | * @since 1.0.0 45 | * 46 | * @return void 47 | */ 48 | public function start() 49 | { 50 | $this->start = microtime(true); 51 | } 52 | 53 | /** 54 | * end time. 55 | * 56 | * @since 1.0.0 57 | * 58 | * @return void 59 | */ 60 | public function end() 61 | { 62 | $this->end = microtime(true); 63 | } 64 | 65 | /** 66 | * Get the elapsed time. 67 | * 68 | * @param (int) $round round. 69 | * 70 | * @since 1.0.0 71 | * 72 | * @return float 73 | */ 74 | public function elapsedTime(int $round = null) 75 | { 76 | $time = $this->end - $this->start; 77 | if (!is_null($round)) { 78 | $time = round($time, $round); 79 | } 80 | 81 | return (float) $time; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Tests/Time/TimeTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(Time::isLeapYear(2020)); 13 | $this->assertFalse(Time::isLeapYear(2019)); 14 | } 15 | 16 | public function testNow() 17 | { 18 | $this->assertIsInt(Time::now()); 19 | $this->assertIsInt(Time::now('Asia/Taipei')); 20 | } 21 | 22 | public function daysInMonthDataProvider() 23 | { 24 | return [ 25 | [2, 2019, 28], 26 | [3, 2019, 31], 27 | [4, 2019, 30], 28 | [2, 2012, 29], 29 | [2, 2016, 29], 30 | ]; 31 | } 32 | 33 | /** 34 | * @dataProvider daysInMonthDataProvider 35 | */ 36 | public function testDaysInMonth($month, $year, $expected) 37 | { 38 | $this->assertSame($expected, Time::daysInMonth($month, $year)); 39 | } 40 | 41 | public function formatsSecondsDataProvider() 42 | { 43 | return [ 44 | [1554339600, '09:00:00'], 45 | [1554343200, '10:00:00'], 46 | ]; 47 | } 48 | 49 | /** 50 | * @dataProvider formatsSecondsDataProvider 51 | */ 52 | public function testFormatsSecondsDataProvider($seconds, $expected) 53 | { 54 | $this->assertSame($expected, Time::formatsSeconds($seconds, 'Asia/Taipei')); 55 | } 56 | 57 | public function testAgo() 58 | { 59 | $this->assertSame(Time::ago(1558539991), Time::ago(1558539991)); 60 | } 61 | 62 | public function testTimestampToGmt() 63 | { 64 | $this->assertSame(Time::timestampToGmt(1558539991), Time::timestampToGmt(1558539991)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Common/OperatingSystem.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common; 18 | 19 | class OperatingSystem 20 | { 21 | /** 22 | * Get the operating system name. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @return string 27 | */ 28 | public function get() 29 | { 30 | return $this->phpOs(); 31 | } 32 | 33 | /** 34 | * Get the operating system name. 35 | * 36 | * @since 1.0.0 37 | * 38 | * @return string 39 | */ 40 | public function phpOs() 41 | { 42 | $os = PHP_OS; 43 | switch ($os) { 44 | case 'WINNT': 45 | case 'WINNT32': 46 | case 'WINNT64': 47 | case 'Windows': 48 | $c_os = 'Windows'; 49 | break; 50 | case 'DragonFly': 51 | case 'FreeBSD': 52 | case 'NetBSD': 53 | case 'OpenBSD': 54 | $c_os = 'BSD'; 55 | break; 56 | case 'Linux': 57 | $c_os = 'Linux'; 58 | break; 59 | case 'SunOS': 60 | $c_os = 'Solaris'; 61 | break; 62 | case 'darwin': 63 | $c_os = 'macos'; 64 | break; 65 | default: 66 | $c_os = 'Unknown'; 67 | break; 68 | } 69 | 70 | return $c_os; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Auth/Verify.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Auth; 18 | 19 | class Verify extends Handler 20 | { 21 | /** 22 | * Verify the user base on token. 23 | * 24 | * @param (mixed) $token token of user 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return void 29 | */ 30 | public function verify($token) 31 | { 32 | $user = new User(); 33 | if ($token === 'NULL' || $user->isToken($token) !== true) { 34 | Error::set(__printl('auth:error:token'), 'token'); 35 | } 36 | if ($this->fail() !== true) { 37 | if (!(new User())->isLogin()) { 38 | $id = $user->getByWhere('token', $token)[0]['id']; 39 | $email = $user->getByWhere('token', $token)[0]['email']; 40 | $update = new Update(); 41 | $update->update(['token' => 'NULL'], $id); 42 | $subject = __printl('auth:subject:verified'); 43 | $link = __config()->auth->verification_link.'/'.$token; 44 | $html = __printl('auth:body:verified'); 45 | $html = str_replace(':email', $email, $html); 46 | $email = new EmailHandler($subject, $html, $email); 47 | Success::set(__config()->auth->success->verified); 48 | } else { 49 | Error::set(__printl('auth:error:already:login'), 'login'); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://github.com/alphazframework/framework/workflows/tests/badge.svg)](https://github.com/alphazframework/framework/actions) 2 | [![StyleCI](https://github.styleci.io/repos/135673638/shield?branch=master)](https://github.styleci.io/repos/135673638) 3 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/alphazframework/framework/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/alphazframework/framework/?branch=master) 4 | [![Code Intelligence Status](https://scrutinizer-ci.com/g/alphazframework/framework/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence) 5 | [![Latest Stable Version](https://poser.pugx.org/alphaz/framework/v/stable)](https://packagist.org/packages/alphaz/framework) 6 | [![Latest Unstable Version](https://poser.pugx.org/alphaz/framework/v/unstable)](https://packagist.org/packages/alphaz/framework) 7 | [![License](https://poser.pugx.org/alphaz/framework/license)](https://packagist.org/packages/alphaz/framework) 8 | 9 | 10 | 11 | # AlphaZ PHP Framework 12 | 13 | **Note:** This repository contains the core files of the alphaz framework. If you want to build an application using alphaz, 14 | visit the main [alphaz repository](https://github.com/alphazframework/alphaz). 15 | 16 | Who is AlphaZ For? 17 | AlphaZ is for PHP developers who want to build apps instead of coding common things like validation, routing, database manipulation, etc, from scratch. AlphaZ offers a set of well-defined toolkits that take care of those things allowing you to focus on building your app. 18 | 19 | The purpose of AlphaZ Framework 20 | As for PHP, there are many PHP frameworks available nowadays, so the question is raised as to why we/people should use AlphaZ. The main purpose of AlphaZ framework is to provide a very lightweight framework without any external dependencies except core and autoloader. 21 | -------------------------------------------------------------------------------- /src/Console/Commands/Cache.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console\Commands; 21 | 22 | use alphaz\Cache\Cache as CacheManager; 23 | use alphaz\Console\Command; 24 | use alphaz\Console\Input; 25 | use alphaz\Console\Output; 26 | 27 | class Cache extends Command 28 | { 29 | /** 30 | * Sign of the command. 31 | * 32 | * @since 1.0.0 33 | * 34 | * @var string 35 | */ 36 | protected $sign = 'clear:cache'; 37 | 38 | /** 39 | * Description of the command. 40 | * 41 | * @since 1.0.0 42 | * 43 | * @var string 44 | */ 45 | protected $description = 'Clear the application cache'; 46 | 47 | /** 48 | * Create a new command instance. 49 | * 50 | * @return void 51 | */ 52 | public function __construct() 53 | { 54 | parent::__construct(); 55 | } 56 | 57 | /** 58 | * Function to handle the class. 59 | * 60 | * @param \alphaz\Console\Output $output 61 | * @param \alphaz\Console\Input $input 62 | * @param array $param 63 | * 64 | * @return void 65 | */ 66 | public function handle(Output $output, Input $input, $param = []): void 67 | { 68 | $c = new CacheManager(); 69 | $c->clear(); 70 | $output->write('Cache cleared'); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Console/Commands/Version.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console\Commands; 21 | 22 | use alphaz\Common\Version as V; 23 | use alphaz\Console\Command; 24 | use alphaz\Console\Input; 25 | use alphaz\Console\Output; 26 | 27 | class Version extends Command 28 | { 29 | /** 30 | * Sign of the command. 31 | * 32 | * @since 1.0.0 33 | * 34 | * @var string 35 | */ 36 | protected $sign = 'version'; 37 | 38 | /** 39 | * Description of the command. 40 | * 41 | * @since 1.0.0 42 | * 43 | * @var string 44 | */ 45 | protected $description = 'Get the version of alphaz framework installed'; 46 | 47 | /** 48 | * Create a new command instance. 49 | * 50 | * @return void 51 | */ 52 | public function __construct() 53 | { 54 | parent::__construct(); 55 | } 56 | 57 | /** 58 | * Function to handle the class. 59 | * 60 | * @param \alphaz\Console\Output $output 61 | * @param \alphaz\Console\Input $input 62 | * @param array $param 63 | * 64 | * @return void 65 | */ 66 | public function handle(Output $output, Input $input, $param = []): void 67 | { 68 | $output->write('alphaz Framewor: ', false); 69 | $output->write(''.V::VERSION.'', true); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Auth/Handler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | */ 15 | 16 | namespace alphaz\Auth; 17 | 18 | class Handler 19 | { 20 | /** 21 | * check if the error has. 22 | * 23 | * @return bool 24 | */ 25 | public function fail() 26 | { 27 | return Error::has(); 28 | } 29 | 30 | /** 31 | * Store the error msgs. 32 | * 33 | * @return array 34 | */ 35 | public function error() 36 | { 37 | $this->errors = Error::all(); 38 | 39 | return $this; 40 | } 41 | 42 | /** 43 | * Get the error msg. 44 | * 45 | * @param $key , like username (optional) 46 | * 47 | * @return array 48 | */ 49 | public function get($key = null) 50 | { 51 | return (isset($key)) ? $this->errors[$key] : $this->errors; 52 | } 53 | 54 | /** 55 | * Get last error msg. 56 | * 57 | * @param $key , like username (optional) 58 | * 59 | * @return string 60 | */ 61 | public function last($key = null) 62 | { 63 | return end($this->get($key)); 64 | } 65 | 66 | /** 67 | * Get first errror msg . 68 | * 69 | * @param $key , like username (optional) 70 | * 71 | * @return string 72 | */ 73 | public function first($key = null) 74 | { 75 | return current($this->get($key)); 76 | } 77 | 78 | /** 79 | * Get the success msg. 80 | * 81 | * @return string 82 | */ 83 | public function success() 84 | { 85 | return Success::get(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Common/Sitemap/AbstractSitemap.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common\Sitemap; 18 | 19 | use alphaz\Contracts\Sitemap\AbstractSitemap as AbstractSitemapContracts; 20 | 21 | class AbstractSitemap extends SitemapWriter implements AbstractSitemapContracts 22 | { 23 | /** 24 | * Last modify. 25 | * 26 | * @since 1.0.0 27 | * 28 | * @var Datetime 29 | */ 30 | protected $lastMod; 31 | 32 | /** 33 | * Sitemap file. 34 | * 35 | * @since 1.0.0 36 | * 37 | * @var string 38 | */ 39 | protected $file; 40 | 41 | /** 42 | * Extension. 43 | * 44 | * @since 1.0.0 45 | * 46 | * @var string 47 | */ 48 | protected $ext = '.xml'; 49 | 50 | /** 51 | * Determine whether the sitemap exists. 52 | * 53 | * @param (string) $file File name with extension (.xml). 54 | * 55 | * @since 1.0.0 56 | * 57 | * @return bool 58 | */ 59 | public function has($file): bool 60 | { 61 | return file_exists($file); 62 | } 63 | 64 | /** 65 | * Delete the sitemap. 66 | * 67 | * @param (string) $file File name with extension (.xml). 68 | * 69 | * @since 1.0.0 70 | * 71 | * @return object 72 | */ 73 | public function delete($file): AbstractSitemapContracts 74 | { 75 | if ($this->has(__public_path().$file.$this->ext)) { 76 | unlink(__public_path().$file.$this->ext); 77 | } 78 | 79 | return $this; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Auth/Auth.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Auth; 18 | 19 | use alphaz\Contracts\Auth\Auth as AuthContract; 20 | 21 | class Auth extends Handler implements AuthContract 22 | { 23 | /** 24 | * Instance of signup class. 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return object 29 | */ 30 | public function signup() 31 | { 32 | return new Signup(); 33 | } 34 | 35 | /** 36 | * Instance of signin class. 37 | * 38 | * @since 1.0.0 39 | * 40 | * @return object 41 | */ 42 | public function signin() 43 | { 44 | return new Signin(); 45 | } 46 | 47 | /** 48 | * Instance of logout class. 49 | * 50 | * @since 1.0.0 51 | * 52 | * @return object 53 | */ 54 | public function logout() 55 | { 56 | return new Logout(); 57 | } 58 | 59 | /** 60 | * Instance of update class. 61 | * 62 | * @since 1.0.0 63 | * 64 | * @return object 65 | */ 66 | public function update() 67 | { 68 | return new Update(); 69 | } 70 | 71 | /** 72 | * Instance of verify class. 73 | * 74 | * @since 1.0.0 75 | * 76 | * @return object 77 | */ 78 | public function verify() 79 | { 80 | return new Verify(); 81 | } 82 | 83 | /** 84 | * Instance of reset class. 85 | * 86 | * @since 1.0.0 87 | * 88 | * @return object 89 | */ 90 | public function reset() 91 | { 92 | return new Reset(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Site/Key.php: -------------------------------------------------------------------------------- 1 | 7 | * @author Muhammad Umer Farooq (Malik) 8 | * 9 | * @link https://github.com/alphazframework/framework 10 | * 11 | * For the full copyright and license information, please view the LICENSE 12 | * file that was distributed with this source code. 13 | * @since 1.0.0 14 | * 15 | * @license MIT 16 | */ 17 | 18 | namespace alphaz\Site; 19 | 20 | use alphaz\Contracts\Site\Key as KeyContract; 21 | 22 | class Key implements keyContract 23 | { 24 | /** 25 | * Converts a binary key into its hexadecimal representation. 26 | * 27 | * @param string $key Binary key 28 | * 29 | * @since 1.0.0 30 | * 31 | * @return string 32 | */ 33 | public static function encode(string $key): string 34 | { 35 | return bin2hex($key); 36 | } 37 | 38 | /** 39 | * Converts a hexadecimal key into its binary representation. 40 | * 41 | * @param string $key Binary key 42 | * 43 | * @since 1.0.0 44 | * 45 | * @return string 46 | */ 47 | public static function decode(string $key): string 48 | { 49 | return hex2bin($key); 50 | } 51 | 52 | /** 53 | * Generates a key. 54 | * 55 | * @param int $length Key length 56 | * 57 | * @since 1.0.0 58 | * 59 | * @return string 60 | */ 61 | public static function generate(int $length = 32): string 62 | { 63 | return random_bytes($length); 64 | } 65 | 66 | /** 67 | * Generates a hex encoded key. 68 | * 69 | * @param int $length Key length 70 | * 71 | * @since 1.0.0 72 | * 73 | * @return string 74 | */ 75 | public static function generateEncode(int $length = 32): string 76 | { 77 | return static::encode(self::generate($length)); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Console/Commands/RouterListCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console\Commands; 21 | 22 | use alphaz\Console\Command; 23 | use alphaz\Console\Output; 24 | use alphaz\Router\App; 25 | 26 | class RouterListCommand extends Command 27 | { 28 | /** 29 | * Sign of the command. 30 | * 31 | * @since 1.0.0 32 | * 33 | * @var string 34 | */ 35 | protected $sign = 'route:list'; 36 | 37 | /** 38 | * Description of the command. 39 | * 40 | * @since 1.0.0 41 | * 42 | * @var string 43 | */ 44 | protected $description = 'List all registered routes'; 45 | 46 | /** 47 | * App instance. 48 | * 49 | * @since 1.0.0 50 | * 51 | * @var \alphaz\Router\App 52 | */ 53 | private $app; 54 | 55 | /** 56 | * Create a new command instance. 57 | * 58 | * @return void 59 | */ 60 | public function __construct() 61 | { 62 | parent::__construct(); 63 | $this->app = new App(); 64 | } 65 | 66 | /** 67 | * Function to handle the class. 68 | * 69 | * @param \alphaz\Console\Output $output 70 | * @param \alphaz\Console\Input $input 71 | * @param array $param 72 | * 73 | * @return void 74 | */ 75 | public function handle(Output $output, Input $input, $param = []): void 76 | { 77 | $routers = $this->app->getRoutes(); 78 | var_dump($routers); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Auth/Error.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Auth; 18 | 19 | class Error 20 | { 21 | /** 22 | * Store the error msgs. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var array 27 | */ 28 | private static $errors = []; 29 | 30 | /** 31 | * Set the error msg. 32 | * 33 | * @param (string) $error error msg 34 | * @param (string) optional $key key of error msg like username 35 | * 36 | * @since 1.0.0 37 | * 38 | * @return bool 39 | */ 40 | public static function set($error, $key = null) 41 | { 42 | if (isset($key)) { 43 | static::$errors[$key] = $error; 44 | } else { 45 | static::$errors = $error; 46 | } 47 | } 48 | 49 | /** 50 | * Check if the error has or not. 51 | * 52 | * @since 1.0.0 53 | * 54 | * @return bool 55 | */ 56 | public static function has() 57 | { 58 | return (count(static::$errors) > 0) ? true : false; 59 | } 60 | 61 | /** 62 | * Get all the error msgs. 63 | * 64 | * @since 1.0.0 65 | * 66 | * @return array 67 | */ 68 | public static function all() 69 | { 70 | return static::$errors; 71 | } 72 | 73 | /** 74 | * Get the error msgs. 75 | * 76 | * @param (string) optional $key like username 77 | * 78 | * @since 1.0.0 79 | * 80 | * @return array 81 | */ 82 | public function get($key = null) 83 | { 84 | return (isset($key)) ? static::$errors[$key] : static::$errors; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Common/Maintenance.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common; 18 | 19 | class Maintenance 20 | { 21 | /** 22 | * Check is the site maintaince mode is enable. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @return bool 27 | */ 28 | public function isMaintain() 29 | { 30 | if (file_exists(route('root').'maintained')) { 31 | return true; 32 | } elseif (__config('app.maintenance', false)) { 33 | return true; 34 | } else { 35 | return false; 36 | } 37 | } 38 | 39 | /** 40 | * Upgrade the maintaince mode dynamically. 41 | * 42 | * @param (bool) $status 43 | * 44 | * @since 1.0.0 45 | * 46 | * @return void 47 | */ 48 | public function updataMaintenance(bool $status) 49 | { 50 | if ($status) { 51 | if (!file_exists(route('root').'maintained')) { 52 | $fh = fopen(route('root').'maintained', 'w'); 53 | fwrite($fh, 'maintained'); 54 | fclose($fh); 55 | } 56 | } elseif (!$status) { 57 | if (file_exists(route('root').'maintained')) { 58 | unlink(route('root').'maintained'); 59 | } 60 | } else { 61 | return false; 62 | } 63 | } 64 | 65 | /** 66 | * Run the site maintaince mode if enable. 67 | * 68 | * @since 1.0.0 69 | * 70 | * @return void 71 | */ 72 | public function run() 73 | { 74 | if ($this->isMaintain()) { 75 | throw new \Exception('Sorry, Site is in maintenance mode', 503); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Console/Colorize.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console; 21 | 22 | use alphaz\Data\Arrays; 23 | 24 | class Colorize 25 | { 26 | /** 27 | * Foregroud colors. 28 | * 29 | * @since 1.0.0 30 | * 31 | * @var array 32 | */ 33 | public $styles = [ 34 | 'bold' => '1m', 35 | 'faded' => '2m', 36 | 'underlined' => '4m', 37 | 'blinking' => '5m', 38 | 'reversed' => '7m', 39 | 'hidden' => '8m', 40 | 'red' => '31m', 41 | 'green' => '32m', 42 | 'yellow' => '33m', 43 | 'blue' => '34m', 44 | 'magenta' => '35m', 45 | 'cyan' => '36m', 46 | 'light_gray' => '37m', 47 | 'dark_gray' => '90m', 48 | 'white' => '0m', 49 | 'bg:red' => '41m', 50 | 'bg:green' => '42m', 51 | 'bg:yellow' => '53m', 52 | 'bg:blue' => '44m', 53 | 'bg:magenta' => '45m', 54 | 'bg:cyan' => '46m', 55 | 'bg:light_gray' => '47m', 56 | 'bg:dark_gray' => '100m', 57 | 'bg:white' => '0m', 58 | ]; 59 | 60 | /** 61 | * Get the color by key. 62 | * 63 | * @param string $color Color key 64 | * @param bool $background 65 | * 66 | * @since 1.0.0 67 | * 68 | * @var string 69 | */ 70 | public function get(string $style) 71 | { 72 | if (Arrays::has($this->styles, $style, '.')) { 73 | return Arrays::get($this->styles, $style, '.'); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Common/Sitemap/SitemapWriter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common\Sitemap; 18 | 19 | use alphaz\Contracts\Sitemap\SitemapWriter as SitemapWriterContracts; 20 | use alphaz\Files\FileHandling; 21 | 22 | class SitemapWriter implements SitemapWriterContracts 23 | { 24 | /** 25 | * resource. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @var object 30 | */ 31 | private $file; 32 | 33 | /** 34 | * __construct. 35 | * Open the sitemap file. 36 | * 37 | * @param (string) $file File name with extension (.xml). 38 | * @param (string) $mode Valid file opening mode. 39 | * 40 | * @since 1.0.0 41 | * 42 | * @return void 43 | */ 44 | public function __construct($file, $mode = 'readWriteAppend') 45 | { 46 | $this->file = (new FileHandling())->open($file, $mode); 47 | } 48 | 49 | /** 50 | * Write on sitemap file. 51 | * 52 | * @param (xml) $data Valid XML 53 | * 54 | * @since 1.0.0 55 | * 56 | * @return void 57 | */ 58 | public function write($data): void 59 | { 60 | if (null !== $this->file) { 61 | $this->file->write($data); 62 | } 63 | } 64 | 65 | /** 66 | * Read the sitemap file. 67 | * 68 | * @since 1.0.0 69 | * 70 | * @return xml 71 | */ 72 | public function read(): string 73 | { 74 | if (null !== $this->file) { 75 | return $this->file->read(); 76 | } 77 | } 78 | 79 | /** 80 | * Close the sitemap file. 81 | * 82 | * @since 1.0.0 83 | * 84 | * @return void 85 | */ 86 | public function close(): void 87 | { 88 | $this->file->close(); 89 | unset($this->file); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Data/Contracts/ConversionContract.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Data\Contracts; 18 | 19 | interface ConversionContract 20 | { 21 | /** 22 | * Convert arrays to Object. 23 | * 24 | * @param array $array Arrays 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return object|false 29 | */ 30 | public static function arrayToObject($array); 31 | 32 | /** 33 | * Convert Objects to arrays. 34 | * 35 | * @param object $object 36 | * 37 | * @since 1.0.0 38 | * 39 | * @return array|false 40 | */ 41 | public static function objectToArray($object); 42 | 43 | /** 44 | * Convert the bit into bytes. 45 | * 46 | * @param int $size The value that you want provided 47 | * @param int $pre Round the value default 2 48 | * 49 | * @since 1.0.0 50 | * 51 | * @return mixed 52 | */ 53 | public static function bitToBytes($size, $pre = 2); 54 | 55 | /** 56 | * Convert the views to relative unit. 57 | * 58 | * @param int $n Views. 59 | * @param string $sep Seperator. 60 | * 61 | * @since 1.0.0 62 | * 63 | * @return mixed 64 | */ 65 | public static function viewToHumanize($n, $sep = ','); 66 | 67 | /** 68 | * Convert XML to arrays. 69 | * 70 | * @param mixed $xml xml 71 | * 72 | * @since 1.0.0 73 | * 74 | * @return array 75 | */ 76 | public static function xmlToArray($xml); 77 | 78 | /** 79 | * Unit conversion. 80 | * 81 | * @param int $value Value to be work on. 82 | * @param string $base The unit which is given that to be converted. 83 | * @param string $to The unit in which it should be converted. 84 | * 85 | * @since 1.0.0 86 | * 87 | * @return mixed 88 | */ 89 | public static function unit($value, $base, $to); 90 | } 91 | -------------------------------------------------------------------------------- /src/Contracts/Time/Time.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Time; 18 | 19 | interface Time 20 | { 21 | /** 22 | * Get "now" time. 23 | * 24 | * @param string|null $timezone Valid php supported timezone. 25 | * 26 | * @since 1.0.0 27 | * 28 | * @return int 29 | */ 30 | public static function now($timezone = null); 31 | 32 | /** 33 | * Number of days in a month. 34 | * 35 | * @param int $month A numeric month. 36 | * @param int $year A numeric year. 37 | * 38 | * @since 1.0.0 39 | * 40 | * @return int 41 | */ 42 | public static function daysInMonth($month = 1, $year = 1970); 43 | 44 | /** 45 | * Determine whether the year is leap or not. 46 | * 47 | * @param int|null $year A numeric year. 48 | * 49 | * @since 1.0.0 50 | * 51 | * @return bool 52 | */ 53 | public static function isLeapYear($year = null); 54 | 55 | /** 56 | * Converts a timestamp to GMT. 57 | * 58 | * @param int|null $time Unix timestamp 59 | * 60 | * @since 1.0.0 61 | * 62 | * @return int 63 | */ 64 | public static function timestampToGmt($time = null); 65 | 66 | /** 67 | * Converts the timestamp in to ago form. 68 | * 69 | * @param int|string $time Datetime, Timestamp or English textual datetime (http://php.net/manual/en/function.strtotime.php) 70 | * 71 | * @since 1.0.0 72 | * 73 | * @return mixed 74 | */ 75 | public static function ago($time); 76 | 77 | /** 78 | * Converts the timestamp in to h:m:s form. 79 | * 80 | * @param int $time Timestamp 81 | * @param string $timezone Valid php supported timezone. 82 | * 83 | * @since 1.0.0 84 | * 85 | * @return mixed 86 | */ 87 | public static function formatsSeconds($seconds, $timezone = ''); 88 | } 89 | -------------------------------------------------------------------------------- /src/Console/Commands/ServeCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console\Commands; 21 | 22 | use alphaz\Common\Version as V; 23 | use alphaz\Console\Command; 24 | use alphaz\Console\Input; 25 | use alphaz\Console\Output; 26 | 27 | class ServeCommand extends Command 28 | { 29 | /** 30 | * Sign of the command. 31 | * 32 | * @since 1.0.0 33 | * 34 | * @var string 35 | */ 36 | protected $sign = 'serve'; 37 | 38 | /** 39 | * Description of the command. 40 | * 41 | * @since 1.0.0 42 | * 43 | * @var string 44 | */ 45 | protected $description = 'Serve the application on the PHP development server'; 46 | 47 | /** 48 | * Create a new command instance. 49 | * 50 | * @return void 51 | */ 52 | public function __construct() 53 | { 54 | parent::__construct(); 55 | } 56 | 57 | /** 58 | * Function to handle the class. 59 | * 60 | * @param \alphaz\Console\Output $output 61 | * @param \alphaz\Console\Input $input 62 | * @param array $param 63 | * 64 | * @return void 65 | */ 66 | public function handle(Output $output, Input $input, $param = []): void 67 | { 68 | // generate random 4 digit number 69 | $port = rand(1000, 9999); 70 | $output->write('alphaz Framewor: ', false); 71 | $output->write(''.V::VERSION.'', true); 72 | // check if the server is running on $port. 73 | $host = 'localhost:'.$port; 74 | $command = 'php -S '.$host; 75 | $output->write("\n PHP local development server has been started locat at localhost:8080. If the public directory is the root, then localhost:8080/public \n"); 76 | shell_exec($command); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Tests/Common/ConfigurationTest.php: -------------------------------------------------------------------------------- 1 | config = new Configuration($this->configs = [ 23 | 'name' => 'alphaz', 24 | 'version' => '3.0.0', 25 | 'null' => null, 26 | 'encryption' => [ 27 | 'key' => 'xxx', 28 | 'adapter' => 'yyy', 29 | ], 30 | ]); 31 | parent::setUp(); 32 | } 33 | 34 | public function testConstruct() 35 | { 36 | $this->assertInstanceOf(Configuration::class, $this->config); 37 | } 38 | 39 | public function testHasIsTrue() 40 | { 41 | $this->assertTrue($this->config->has('name')); 42 | } 43 | 44 | public function testHasIsFalse() 45 | { 46 | $this->assertFalse($this->config->has('database')); 47 | } 48 | 49 | public function testGet() 50 | { 51 | $this->assertSame('alphaz', $this->config->get('name')); 52 | } 53 | 54 | public function testGetWithArrayOfKeys() 55 | { 56 | $this->assertSame('alphaz', $this->config->get('name')); 57 | $this->assertSame('xxx', $this->config->get('encryption.key')); 58 | } 59 | 60 | public function testGetWithDefault() 61 | { 62 | $this->assertSame('default', $this->config->get('not-exist', 'default')); 63 | } 64 | 65 | public function testSet() 66 | { 67 | $this->config->set('key', 'value'); 68 | $this->assertSame('value', $this->config->get('key')); 69 | } 70 | 71 | public function testSetArray() 72 | { 73 | $this->config->set([ 74 | 'key1' => 'value1', 75 | 'key2' => 'value2', 76 | ]); 77 | $this->assertSame('value1', $this->config->get('key1')); 78 | $this->assertSame('value2', $this->config->get('key2')); 79 | } 80 | 81 | public function testAll() 82 | { 83 | $this->assertSame($this->configs, $this->config->all()); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Console/Input.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console; 21 | 22 | class Input extends Colorize 23 | { 24 | /** 25 | * Prompt for input secret input like password. 26 | * 27 | * @param string $prompt Message to display. 28 | * @param bool $show_asterisk Show asterisk or not. 29 | * 30 | * @since 1.0.0 31 | * 32 | * @return bool 33 | */ 34 | public function secret(string $prompt) 35 | { 36 | $os = (new \alphaz\Common\OperatingSystem())->get(); 37 | $current_dir = __DIR__; 38 | $current_dir = str_replace('\\', '/', $current_dir); 39 | $command = $current_dir.'/bin/'; 40 | if ($os === 'Windows') { 41 | $command .= 'windows.exe'; 42 | } elseif ($os === 'macos') { 43 | $command .= 'macos'; 44 | } else { 45 | $command .= 'linux'; 46 | } 47 | $value = shell_exec($command); 48 | 49 | return $value; 50 | } 51 | 52 | /** 53 | * Prompt for input confirm. 54 | * 55 | * @since 1.0.0 56 | * 57 | * @return bool 58 | */ 59 | public function confirm(): bool 60 | { 61 | $confirm = $this->ask(); 62 | $confirmed = ['y', 'yes']; 63 | 64 | return in_array(strtolower($confirm), $confirmed); 65 | } 66 | 67 | /** 68 | * Prompt for input input. 69 | * 70 | * @since 1.0.0 71 | * 72 | * @return string 73 | */ 74 | public function ask(): string 75 | { 76 | $os = (new \alphaz\Common\OperatingSystem())->get(); 77 | if ($os === 'WINNT' or $os === 'Windows') { 78 | $x = stream_get_line(STDIN, 9024, PHP_EOL); 79 | if (!empty($x)) { 80 | return $x; 81 | } 82 | } else { 83 | $x = readline(''); 84 | if (!empty($x)) { 85 | return $x; 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz; 18 | 19 | use alphaz\Common\AliasLoader; 20 | use alphaz\Common\TimeZone; 21 | use alphaz\http\Request; 22 | use alphaz\Router\App; 23 | 24 | class Bootstrap 25 | { 26 | /** 27 | * Set Default configuration. 28 | * 29 | * @since 1.0.0 30 | * 31 | * @return void 32 | */ 33 | public function configure() 34 | { 35 | TimeZone::seteDefaultTz(__config('app.time_zone')); 36 | } 37 | 38 | /** 39 | * Register the class aliases. 40 | * 41 | * @since 1.0.0 42 | * 43 | * @return void 44 | */ 45 | protected function registerClassAliases() 46 | { 47 | $aliases = __config('class_aliases'); 48 | if (!empty($aliases)) { 49 | $aliasLoader = new AliasLoader($aliases); 50 | spl_autoload_register([$aliasLoader, 'load']); 51 | } 52 | } 53 | 54 | /** 55 | * Register the App. 56 | * 57 | * @since 1.0.0 58 | * 59 | * @return void 60 | */ 61 | public function registerApp() 62 | { 63 | (new App())->run()->dispatch(new Request()); 64 | } 65 | 66 | /** 67 | * Load the boostrap file. 68 | * 69 | * @since 1.0.0 70 | * 71 | * @return void 72 | */ 73 | public function bootstrap() 74 | { 75 | $file = route('root').'/bootstrap.php'; 76 | if (file_exists($file)) { 77 | include_once $file; 78 | } 79 | } 80 | 81 | /** 82 | * Boot the application. 83 | * 84 | * @since 1.0.0 85 | * 86 | * @return void 87 | */ 88 | public function boot() 89 | { 90 | //Set default configuration 91 | $this->configure(); 92 | //Loaded class aliases 93 | $this->registerClassAliases(); 94 | //Load the application bootstrap file 95 | $this->bootstrap(); 96 | //register the app 97 | $this->registerApp(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Encryption/Encrypt.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Encryption; 18 | 19 | use alphaz\Contracts\Encryption\Encrypt as EncryptContract; 20 | 21 | class Encrypt implements EncryptContract 22 | { 23 | /** 24 | * Store the adapter object. 25 | * 26 | * @since 1.0.0 27 | * 28 | * @var object 29 | */ 30 | private static $adapter = null; 31 | 32 | /** 33 | * Set the adapter. 34 | * 35 | * @param (string) $adapter 36 | * 37 | * @since 1.0.0 38 | * 39 | * @return object 40 | */ 41 | public static function setAdapter($adapter) 42 | { 43 | switch (strtolower($adapter)) { 44 | case 'sodium': 45 | $adapterSet = '\alphaz\Encryption\Adapter\SodiumEncryption'; 46 | break; 47 | case 'openssl': 48 | $adapterSet = '\alphaz\Encryption\Adapter\OpenSslEncryption'; 49 | break; 50 | default: 51 | $adapterSet = '\alphaz\Encryption\Adapter\OpenSslEncryption'; 52 | break; 53 | } 54 | $key = __config('encryption.key'); 55 | self::$adapter = new $adapterSet($key); 56 | 57 | return __CLASS__; 58 | } 59 | 60 | /** 61 | * Encrypt the message. 62 | * 63 | * @param (mixed) $data data to be encrypted 64 | * 65 | * @since 1.0.0 66 | * 67 | * @return mixed 68 | */ 69 | public static function encrypt($data, $adapter = null) 70 | { 71 | ($adapter !== null) ? self::setAdapter($adapter) : self::setAdapter(__config('encryption.driver')); 72 | 73 | return self::$adapter->encrypt($data); 74 | } 75 | 76 | /** 77 | * Decrypt the message. 78 | * 79 | * @param (mixed) $token encrypted token 80 | * 81 | * @since 1.0.0 82 | * 83 | * @return mixed 84 | */ 85 | public static function decrypt($token, $adapter = null) 86 | { 87 | ($adapter !== null) ? self::setAdapter($adapter) : self::setAdapter(__config('encryption.driver')); 88 | 89 | return self::$adapter->decrypt($token); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Encryption/Encryption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Encryption; 18 | 19 | use alphaz\Contracts\Encryption\Encryption as EncryptionContract; 20 | 21 | class Encryption implements EncryptionContract 22 | { 23 | /** 24 | * Store the adapter object. 25 | * 26 | * @since 1.0.0 27 | * 28 | * @var object 29 | */ 30 | private $adapter = null; 31 | 32 | /** 33 | * __construct. 34 | * 35 | * @since 1.0.0 36 | */ 37 | public function __construct($adapter = null) 38 | { 39 | ($adapter !== null) ? $this->setAdapter($adapter) : $this->setAdapter(__config('encryption.driver')); 40 | } 41 | 42 | /** 43 | * Set the adapter. 44 | * 45 | * @param (string) $adapter 46 | * 47 | * @since 1.0.0 48 | * 49 | * @return object 50 | */ 51 | public function setAdapter($adapter) 52 | { 53 | switch (strtolower($adapter)) { 54 | case 'sodium': 55 | $adapterSet = '\alphaz\Encryption\Adapter\SodiumEncryption'; 56 | break; 57 | case 'openssl': 58 | $adapterSet = '\alphaz\Encryption\Adapter\OpenSslEncryption'; 59 | break; 60 | default: 61 | $adapterSet = '\alphaz\Encryption\Adapter\OpenSslEncryption'; 62 | break; 63 | } 64 | $key = __config('encryption.key'); 65 | $this->adapter = new $adapterSet($key); 66 | 67 | return $this; 68 | } 69 | 70 | /** 71 | * Encrypt the message. 72 | * 73 | * @param (mixed) $data data to be encrypted 74 | * 75 | * @since 1.0.0 76 | * 77 | * @return mixed 78 | */ 79 | public function encrypt($data) 80 | { 81 | return $this->adapter->encrypt($data); 82 | } 83 | 84 | /** 85 | * Decrypt the message. 86 | * 87 | * @param (mixed) $token encrypted token 88 | * 89 | * @since 1.0.0 90 | * 91 | * @return mixed 92 | */ 93 | public function decrypt($token) 94 | { 95 | return $this->adapter->decrypt($token); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Encryption/Adapter/OpenSslEncryption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Encryption\Adapter; 18 | 19 | class OpenSslEncryption 20 | { 21 | /** 22 | * Store the cipher iv. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var string 27 | */ 28 | private $iv; 29 | 30 | /** 31 | * Cipher. 32 | * 33 | * @since 1.0.0 34 | * 35 | * @var string 36 | */ 37 | private $cipher = 'AES-256-CBC'; 38 | 39 | /** 40 | * __Construct. 41 | * 42 | * @since 1.0.0 43 | * 44 | * @return void 45 | */ 46 | public function __construct($key = null) 47 | { 48 | if (null !== $key) { 49 | $this->iv = openssl_random_pseudo_bytes($this->iv_bytes($this->cipher)); 50 | $this->key = hash('sha512', $key); 51 | } else { 52 | throw new \Exception('Crypto key not found', 500); 53 | } 54 | } 55 | 56 | /** 57 | * Encrypt the message. 58 | * 59 | * @param $data => data to be encrypted 60 | * 61 | * @since 1.0.0 62 | * 63 | * @return token 64 | */ 65 | public function encrypt($data) 66 | { 67 | return base64_encode(openssl_encrypt($data, $this->cipher, $this->key, 0, $this->iv).'&&'.bin2hex($this->iv)); 68 | } 69 | 70 | /** 71 | * Decrypt the message. 72 | * 73 | * @param $token => encrypted token 74 | * 75 | * @since 1.0.0 76 | * 77 | * @return mix-data 78 | */ 79 | public function decrypt($token) 80 | { 81 | $token = base64_decode($token); 82 | list($token, $this->iv) = explode('&&', $token); 83 | 84 | return openssl_decrypt($token, $this->cipher, $this->key, 0, hex2bin($this->iv)); 85 | } 86 | 87 | /** 88 | * Get the length of cipher. 89 | * 90 | * @param $method 91 | * 92 | * @since 1.0.0 93 | * 94 | * @return int 95 | */ 96 | protected function iv_bytes($method) 97 | { 98 | return openssl_cipher_iv_length($method); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /changes.md: -------------------------------------------------------------------------------- 1 | ## alphaz Framework - V3.0.0 {Dev} 2 | 3 | ### New Features. 4 | 1. Added Identicon Library. 5 | 2. Added FTP Class. 6 | 3. Added FileHandling Classs. 7 | 4. Added Avatar Package. 8 | 5. Added Container Package. 9 | 6. Added Model Class (to access models {Now you can access any model like method() //or model('folder\model')->method()?> }). 10 | 7. Added Pagination Class and their respective functions. 11 | 8. Added HTTP Client Library/Package. 12 | 9. Added New Cache Library/Package. 13 | - Supported Adapters 14 | A. APC 15 | B. APCU 16 | C. FileSystem 17 | D. Memcache 18 | E. Memcached 19 | F. Redis 20 | G. Session 21 | 10. Added Encryption Library/Package {Sodium,openSSL}. 22 | 11. Added Hashing Library/Package. 23 | 12. Added Whoops Library/Pacakge (to show more friendly error log on display if turn on). 24 | 13. Added Component Manipulator Class. 25 | 14. Added Sitemap Library/Package. 26 | 15. Added Arrays Library/Package. 27 | 16. Added String Library/Package. 28 | 17. Added TimeZone Class. 29 | 18. Added LanguageCodes Trait. 30 | 19. Added ClassAlias Class. 31 | 20. Added FileInfo Class. 32 | 21. Added Key Class. 33 | 34 | ### Fixes 35 | 1. Update site class (fix issue in redirect method , prev parameter were not working). 36 | 2. Update userInfo class (fix issue FireFox browser return NULL). 37 | 3. Fix Router Cache issue (Cache seems to be on even it were off). 38 | 4. Update Signup,Signin class fix issue send verification email. 39 | 5. Fix typo in language string class Local to Locale. 40 | 6. Fix typos in Root Class. 41 | 7. Avoid session hijacking attack. 42 | 43 | ### Added Function or Method. 44 | 1. Added view function in `function.php` 45 | 2. Added getInput method in `Router` class 46 | 3. Allow to get input using $this->input properity in `controller` 47 | 4. Added ipv6,alpha and subnet `validation` rule method. 48 | 5. Added delete method in `user` class. 49 | 6. Added touch & chown method in `Files` class. 50 | 7. Added recursiveCreateDir method in `Files` class (Special thanks [Nivaldo MS 51 | ](https://github.com/NivaldoMS)). 52 | 8. Added setCustumFile method in `Logger` class. 53 | 9. Added close method in `FileHandling` class. 54 | 10. Added OPTIONS, TRACE, CONNECT, ALL rests methods in `Router` class. 55 | 11. Added setMultiple, deleteMultiple, getMultiple methods in `Session` class. 56 | 12. Added setMultiple, deleteMultiple, getMultiple methods in `Cookie` class. 57 | 13. Update `\Site::Salts` method add `$special` argument support to add, special chars in salts. 58 | 59 | ### Optimizations 60 | 1. Allow translations of default validations messages. 61 | 2. Optimizations of Components package. 62 | 3. Optimizations of PasswordManipulation Class. 63 | 64 | ### Unit Testing. 65 | 1. Added PHPUnit testing. 66 | -------------------------------------------------------------------------------- /src/Console/Commands/Controller.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console\Commands; 21 | 22 | use alphaz\Console\Command; 23 | use alphaz\Console\Input; 24 | use alphaz\Console\Output; 25 | 26 | class Controller extends Command 27 | { 28 | /** 29 | * Sign of the command. 30 | * 31 | * @since 1.0.0 32 | * 33 | * @var string 34 | */ 35 | protected $sign = 'make:controller'; 36 | 37 | /** 38 | * Description of the command. 39 | * 40 | * @since 1.0.0 41 | * 42 | * @var string 43 | */ 44 | protected $description = 'Create a new Controller class'; 45 | 46 | /** 47 | * Accpet flag parameter in command. 48 | * 49 | * @since 1.0.0 50 | * 51 | * @var array 52 | */ 53 | protected $flags = [ 54 | 'name', 55 | ]; 56 | 57 | /** 58 | * Create a new command instance. 59 | * 60 | * @return void 61 | */ 62 | public function __construct() 63 | { 64 | parent::__construct(); 65 | } 66 | 67 | /** 68 | * Function to handle the class. 69 | * 70 | * @param \alphaz\Console\Output $output 71 | * @param \alphaz\Console\Input $input 72 | * @param array $param 73 | * 74 | * @return void 75 | */ 76 | public function handle(Output $output, Input $input, $param = []): void 77 | { 78 | $name = $param['name'] ?? 'test'; 79 | $file = 'App/Controllers/'.$name.'.php'; 80 | if (!file_exists($file)) { 81 | $fh = fopen($file, 'w'); 82 | fwrite($fh, $this->controller($name)); 83 | fclose($fh); 84 | } 85 | $output->write('Controller created successfully.'); 86 | } 87 | 88 | // should replace with like {stubs} 89 | public function controller($name) 90 | { 91 | return << 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Cache\Adapter; 18 | 19 | abstract class AbstractAdapter 20 | { 21 | /** 22 | * Time to live. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var int 27 | */ 28 | private $ttl = 0; 29 | 30 | /** 31 | * __construct. 32 | * 33 | * @param int $ttl time to live 34 | * 35 | * @since 1.0.0 36 | */ 37 | public function __construct($ttl = 0) 38 | { 39 | $this->setTtl($ttl); 40 | } 41 | 42 | /** 43 | * Set the ttl. 44 | * 45 | * @param int $ttl time to live 46 | * 47 | * @since 1.0.0 48 | * 49 | * @return self 50 | */ 51 | public function setTtl($ttl) 52 | { 53 | $this->ttl = $ttl; 54 | 55 | return $this; 56 | } 57 | 58 | /** 59 | * Get the time-to-live for cache. 60 | * 61 | * @since 1.0.0 62 | * 63 | * @return int 64 | */ 65 | public function getTtl() 66 | { 67 | return $this->ttl; 68 | } 69 | 70 | /** 71 | * Get the time-to-live for an item in cache. 72 | * 73 | * @param string $key 74 | * 75 | * @since 1.0.0 76 | * 77 | * @return int|false 78 | */ 79 | abstract public function getItemTtl($key); 80 | 81 | /** 82 | * Save an item to cache. 83 | * 84 | * @param string $key 85 | * @param mixed $value 86 | * @param int $ttl 87 | * 88 | * @since 1.0.0 89 | * 90 | * @return self 91 | */ 92 | abstract public function saveItem($key, $value, $ttl = null); 93 | 94 | /** 95 | * Get an item from cache. 96 | * 97 | * @param string $key 98 | * 99 | * @since 1.0.0 100 | * 101 | * @return mixed 102 | */ 103 | abstract public function getItem($key); 104 | 105 | /** 106 | * Determine if the item exist in cache. 107 | * 108 | * @param string $key 109 | * 110 | * @since 1.0.0 111 | * 112 | * @return bool 113 | */ 114 | abstract public function hasItem($key); 115 | 116 | /** 117 | * Delete a value in cache. 118 | * 119 | * @param string $key 120 | * 121 | * @since 1.0.0 122 | * 123 | * @return self 124 | */ 125 | abstract public function deleteItem($key); 126 | 127 | /** 128 | * Destroy cache resource. 129 | * 130 | * @since 1.0.0 131 | * 132 | * @return self 133 | */ 134 | abstract public function destroy(); 135 | } 136 | -------------------------------------------------------------------------------- /src/Console/Commands/ListCmd.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console\Commands; 21 | 22 | use alphaz\Common\Version as V; 23 | use alphaz\Console\Command; 24 | use alphaz\Console\Console; 25 | use alphaz\Console\Input; 26 | use alphaz\Console\Output; 27 | use alphaz\Container\Container; 28 | 29 | class ListCmd extends Command 30 | { 31 | /** 32 | * Sign of the command. 33 | * 34 | * @since 1.0.0 35 | * 36 | * @var string 37 | */ 38 | protected $sign = 'list'; 39 | 40 | /** 41 | * Description of the command. 42 | * 43 | * @since 1.0.0 44 | * 45 | * @var string 46 | */ 47 | protected $description = 'List the available commands'; 48 | 49 | /** 50 | * Commands. 51 | * 52 | * @since 1.0.0 53 | * 54 | * @var array 55 | */ 56 | private $cmds; 57 | 58 | /** 59 | * Create a new command instance. 60 | * 61 | * @return void 62 | */ 63 | public function __construct() 64 | { 65 | parent::__construct(); 66 | $this->container = new Container(); 67 | } 68 | 69 | /** 70 | * Get the list of commandss. 71 | * 72 | * @return void 73 | */ 74 | public function getList(): void 75 | { 76 | $console = new Console(); 77 | $this->cmds = $console->getCommands(); 78 | } 79 | 80 | /** 81 | * Function to handle the class. 82 | * 83 | * @param \alphaz\Console\Output $output 84 | * @param \alphaz\Console\Input $input 85 | * @param array $param 86 | * 87 | * @return void 88 | */ 89 | public function handle(Output $output, Input $input, $param = []): void 90 | { 91 | $output->write('alphaz Framewor: ', false); 92 | $output->write(''.V::VERSION.'', true); 93 | $this->getList(); 94 | $list = []; 95 | foreach ($this->cmds as $command) { 96 | $this->container->register([$command[1], $command[0]], new $command[1]()); 97 | $class = $this->container->get($command[0]); 98 | if (!$class->getHidden()) { 99 | $sign = $class->getSign(); 100 | $desc = $class->getDescription(); 101 | $output->write("${sign} :", true); 102 | $output->write("\t${desc}", true); 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/Console/Input/Table.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console\Input; 21 | 22 | class Table 23 | { 24 | /** 25 | * Table header. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @var array 30 | */ 31 | private $header = []; 32 | 33 | /** 34 | * Table item. 35 | * 36 | * @since 1.0.0 37 | * 38 | * @var array 39 | */ 40 | private $items = []; 41 | 42 | /** 43 | * Create a new Table instance. 44 | * 45 | * @param array $header 46 | * @param array $items 47 | * 48 | * @return void 49 | */ 50 | public function __construct(array $header, array $items) 51 | { 52 | $this->header = $header; 53 | $this->items = $items; 54 | } 55 | 56 | /** 57 | * Print table border. 58 | * 59 | * @since 1.0.0 60 | * 61 | * @return array 62 | */ 63 | public function printBorder($row): self 64 | { 65 | foreach ($row as $key => $value) { 66 | $size = mb_strlen($value); 67 | for ($i = 0; $i < $size + 2; $i++) { 68 | echo '-'; 69 | } 70 | echo '+'; 71 | } 72 | 73 | return $this; 74 | } 75 | 76 | /** 77 | * Print the row. 78 | * 79 | * @since 1.0.0 80 | * 81 | * @return self 82 | */ 83 | public function printRow($row, $head = false): self 84 | { 85 | if ($head) { 86 | echo ' +'; 87 | $this->printBorder($row); 88 | echo "\n"; 89 | } 90 | echo ' | '; 91 | foreach ($row as $key => $val) { 92 | echo $val.' | '; 93 | } 94 | if ($head) { 95 | echo "\n"; 96 | echo ' +'; 97 | $this->printBorder($row); 98 | } 99 | echo "\n"; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * Draw the table. 106 | * 107 | * @since 1.0.0 108 | * 109 | * @return void 110 | */ 111 | public function draw(): void 112 | { 113 | // print the header at top 114 | $this->printRow($this->header, true); 115 | // for other rows 116 | foreach ($this->items as $key => $val) { 117 | $this->printRow($val, false); 118 | } 119 | // for footer 120 | echo ' +'; 121 | $this->printBorder($this->header); 122 | echo "\n"; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/Validation/Handler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * 13 | * @license MIT 14 | */ 15 | 16 | namespace alphaz\Validation; 17 | 18 | class Handler 19 | { 20 | /* 21 | * Errors 22 | */ 23 | private static $error = []; 24 | /* 25 | * Msgs 26 | */ 27 | private static $msgs = []; 28 | 29 | /** 30 | * Push the messages. 31 | * 32 | * @return void 33 | */ 34 | public static function pushMsgs() 35 | { 36 | static::$msgs = [ 37 | 'string' => __printl('string:validation'), 38 | 'required' => __printl('required:validation'), 39 | 'int' => __printl('int:validation'), 40 | 'float' => __printl('float:validation'), 41 | 'email' => __printl('email:validation'), 42 | 'ip' => __printl('ip:validation'), 43 | 'ipv6' => __printl('ipv6:validation'), 44 | 'alpha' => __printl('alpha:validation'), 45 | 'subnet' => __printl('subnet:validation'), 46 | 'validate' => __printl('validate:validation'), 47 | 'unique' => __printl('unique:validation'), 48 | ]; 49 | } 50 | 51 | /** 52 | * Set the error msg. 53 | * 54 | * @param $error the error msg 55 | * $key key of error msg 56 | * 57 | * @return void 58 | */ 59 | public static function set($error, $key = null) 60 | { 61 | if (isset($key)) { 62 | static::$error[$key][] = $error; 63 | } else { 64 | static::$error[] = $error; 65 | } 66 | } 67 | 68 | /** 69 | * check Whether the any error msg exists. 70 | * 71 | * @return resource 72 | */ 73 | public static function has() 74 | { 75 | return (count(static::$error) > 0) ? true : false; 76 | } 77 | 78 | /** 79 | * Get all error msgs. 80 | * 81 | * @return resource 82 | */ 83 | public static function all() 84 | { 85 | return static::$error; 86 | } 87 | 88 | /** 89 | * Get the error msg. 90 | * 91 | * @param $key key of error msg 92 | * 93 | * @return resource 94 | */ 95 | public function get($key = null) 96 | { 97 | return (isset($key)) ? static::$error[$key] : static::$error; 98 | } 99 | 100 | /** 101 | * Get the msgs. 102 | * 103 | * @return resource 104 | */ 105 | public static function getMsgs() 106 | { 107 | self::pushMsgs(); 108 | 109 | return static::$msgs; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/Auth/Reset.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Auth; 18 | 19 | use alphaz\Site\Site; 20 | use alphaz\Validation\Validation; 21 | 22 | class Reset extends Handler 23 | { 24 | /** 25 | * Store the error msgs. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @var array 30 | */ 31 | protected $errors = []; 32 | 33 | /** 34 | * Add the reset password request. 35 | * 36 | * @param (string) $email email of user 37 | * 38 | * @since 1.0.0 39 | * 40 | * @return void 41 | */ 42 | public function reset($email) 43 | { 44 | $rules = [ 45 | 'email' => ['required' => true, 'email' => true], 46 | ]; 47 | $input = [ 48 | 'email' => $email, 49 | ]; 50 | $requireValidate = new Validation($input, $rules); 51 | if ($requireValidate->fail()) { 52 | Error::set($requireValidate->error()->get()); 53 | } 54 | $user = new User(); 55 | if (!$user->isEmail($email)) { 56 | Error::set(__config()->auth->errors->email_not_exist, 'username'); 57 | } 58 | if (!$user->isLogin()) { 59 | if ($this->fail() !== true) { 60 | $id = $user->getByWhere('email', $email)[0]['id']; 61 | $resetToken = (new Site())::salts(8); 62 | $update = new Update(); 63 | $update->update(['resetToken' => $resetToken], $id); 64 | $link = site_base_url().__config()->auth->reset_password_link.$resetToken; 65 | $subject = __printl('auth:subject:reset'); 66 | $link = site_base_url().__config()->auth->reset_password_link.'/'.$token; 67 | $html = __printl('auth:body:reset'); 68 | $html = str_replace(':email', $email, $html); 69 | $html = str_replace(':link', $link, $html); 70 | new EmailHandler($subject, $html, $email); 71 | Success::set(__printl('auth:success:reset')); 72 | } 73 | } else { 74 | Error::set(__printl('auth:error:already:login'), 'login'); 75 | } 76 | } 77 | 78 | /** 79 | * check token is exists or not. 80 | * 81 | * @param (mixed) $token token of user 82 | * 83 | * @since 1.0.0 84 | * 85 | * @return void 86 | */ 87 | public function resetUpdate($token) 88 | { 89 | $user = new User(); 90 | if ($token === 'NULL' || $user->isResetToken($token) !== true) { 91 | Error::set(__printl('auth:error:token'), 'token'); 92 | } 93 | if ($this->fail() !== true) { 94 | Success::set(true); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Contracts/Auth/User.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Auth; 18 | 19 | interface User 20 | { 21 | /** 22 | * Get all the users. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @return array 27 | */ 28 | public function getAll(); 29 | 30 | /** 31 | * Get users using specific field. 32 | * 33 | * @param (string) $where field of user e.g username 34 | * @param (string) $value value fo field like , usr01 35 | * 36 | * @since 1.0.0 37 | * 38 | * @return bool 39 | */ 40 | public function getByWhere($where, $value); 41 | 42 | /** 43 | * Delete user by id. 44 | * 45 | * @param $id id or guide of user 46 | * 47 | * @since 1.0.0 48 | * 49 | * @return bool 50 | */ 51 | public function delete($id); 52 | 53 | /** 54 | * Check is username is exists or not. 55 | * 56 | * @param (string) $username username of user 57 | * 58 | * @since 1.0.0 59 | * 60 | * @return bool 61 | */ 62 | public function isUsername($username); 63 | 64 | /** 65 | * Check is email is exists or not. 66 | * 67 | * @param (mixed) $email email of user 68 | * 69 | * @since 1.0.0 70 | * 71 | * @return bool 72 | */ 73 | public function isEmail($email); 74 | 75 | /** 76 | * Check is is verification token is exists or not. 77 | * 78 | * @param (mixed) $token token of user 79 | * 80 | * @since 1.0.0 81 | * 82 | * @return bool 83 | */ 84 | public function isToken($token); 85 | 86 | /** 87 | * Check is reset token is exists or not. 88 | * 89 | * @param (mixed) $token token of user 90 | * 91 | * @since 1.0.0 92 | * 93 | * @return bool 94 | */ 95 | public function isResetToken($token); 96 | 97 | /** 98 | * Get the details of login user. 99 | * 100 | * @since 1.0.0 101 | * 102 | * @return mixed 103 | */ 104 | public function loginUser(); 105 | 106 | /** 107 | * Get the current session user. 108 | * 109 | * @since 1.0.0 110 | * 111 | * @return mixed 112 | */ 113 | public function sessionUser(); 114 | 115 | /** 116 | * Check user is login or not. 117 | * 118 | * @since 1.0.0 119 | * 120 | * @return bool 121 | */ 122 | public function isLogin(); 123 | 124 | /** 125 | * Logout the user. 126 | * 127 | * @since 1.0.0 128 | * 129 | * @return bool 130 | */ 131 | public function logout(); 132 | } 133 | -------------------------------------------------------------------------------- /src/Hashing/Hashing.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Hashing; 18 | 19 | class Hashing 20 | { 21 | /** 22 | * Store the instance of Hash driver. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var object 27 | */ 28 | private $driver; 29 | 30 | /** 31 | * __construct. 32 | * 33 | * @since 1.0.0 34 | */ 35 | public function __construct($verify = false) 36 | { 37 | $driver = __config('hashing.driver'); 38 | if ($driver === 'bcrypt') { 39 | $this->driver = new BcryptHashing(['cost' => __config('hashing.bcrypt.cost')]); 40 | } elseif ($driver === 'argon2i') { 41 | $this->driver = new ArgonHashing([ 42 | 'memory' => __config('hashing.argon.memory'), 43 | 'time' => __config('hashing.argon.time'), 44 | 'threads' => __config('hashing.argon.threads'), 45 | 'verify' => $verify, 46 | ]); 47 | } elseif ($driver === 'argon2id') { 48 | $this->driver = new Argon2IdHashing([ 49 | 'memory' => __config('hashing.argon.memory'), 50 | 'time' => __config('hashing.argon.time'), 51 | 'threads' => __config('hashing.argon.threads'), 52 | 'verify' => $verify, 53 | ]); 54 | } else { 55 | throw new \Exception('We\'re sorry, The hashing driver '.$driver.' not supported.', 500); 56 | } 57 | } 58 | 59 | /** 60 | * Generate the hash. 61 | * 62 | * @param (string) $original 63 | * @param (array) optional $options 64 | * 65 | * @since 1.0.0 66 | * 67 | * @return string 68 | */ 69 | public function make($original, $options = null) 70 | { 71 | return $this->driver->make($original, $options); 72 | } 73 | 74 | /** 75 | * Verify the hash. 76 | * 77 | * @param (string) $original 78 | * @param (string) $hash 79 | * 80 | * @since 1.0.0 81 | * 82 | * @return string 83 | */ 84 | public function verify($original, $hash) 85 | { 86 | return $this->driver->verify($original, $hash); 87 | } 88 | 89 | /** 90 | * Check if the given hash has been hashed using the given options. 91 | * 92 | * @param (string) $hash 93 | * @param (array) optional $options 94 | * 95 | * @since 1.0.0 96 | * 97 | * @return bool 98 | */ 99 | public function needsRehash($hash, $options = null) 100 | { 101 | return $this->driver->needsRehash($hash, $options); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Encryption/Adapter/SodiumEncryption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Encryption\Adapter; 18 | 19 | class SodiumEncryption extends AbstractAdapter 20 | { 21 | /** 22 | * __Construct. 23 | * 24 | * @since 1.0.0 25 | */ 26 | public function __construct($key = null) 27 | { 28 | if (!function_exists('sodium_crypto_secretbox_keygen')) { 29 | throw new \Exception('The sodium php extension does not installed or enabled', 500); 30 | } 31 | 32 | if (null !== $key) { 33 | //Need to validate key to o mention the developers the key size is invalid. [@peter279k(https://github.com/peter279k)] 34 | if (strlen($key) !== 32) { 35 | throw new \InvalidArgumentException('The key size is invalid, and key size should be 32', 500); 36 | } 37 | //Should use user define key. 38 | $this->key = substr(hash('sha512', $key), 0, 32); 39 | } else { 40 | throw new \Exception('Crypto key not found', 500); 41 | } 42 | } 43 | 44 | /** 45 | * Encrypt the message. 46 | * 47 | * @param (mixed) $data data to be encrypted 48 | * 49 | * @since 1.0.0 50 | * 51 | * @return mixed 52 | */ 53 | public function encrypt($data) 54 | { 55 | $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); 56 | $token = base64_encode($nonce.sodium_crypto_secretbox($data, $nonce, $this->key).'&&'.$this->key); 57 | 58 | return $token; 59 | } 60 | 61 | /** 62 | * Decrypt the message. 63 | * 64 | * @param (mixed) $token encrypted token 65 | * 66 | * @since 1.0.0 67 | * 68 | * @return mixed 69 | */ 70 | public function decrypt($token) 71 | { 72 | $decoded = base64_decode($token); 73 | list($decoded, $this->key) = explode('&&', $decoded); 74 | if ($decoded === false) { 75 | throw new Exception('The decoding failed'); 76 | } 77 | if (mb_strlen($decoded, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) { 78 | throw new \Exception('The token was truncated'); 79 | } 80 | $nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); 81 | $ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); 82 | 83 | $plain = sodium_crypto_secretbox_open( 84 | $ciphertext, 85 | $nonce, 86 | $this->key 87 | ); 88 | 89 | if ($plain === false) { 90 | throw new \Exception('The message was tampered with in transit'); 91 | } 92 | 93 | return $plain; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Archive/Archive.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * @link https://github.com/alphazframework/framework 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | * 12 | * @license MIT 13 | * 14 | * @since 1.0.0 15 | */ 16 | 17 | namespace alphaz\Archive; 18 | 19 | class Archive 20 | { 21 | /** 22 | * Store the adapter object. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var object 27 | */ 28 | private $adapter = null; 29 | 30 | /** 31 | * The constructor. 32 | * 33 | * @since 1.0.0 34 | */ 35 | public function __construct($adapter = null) 36 | { 37 | if (\defined('__alphaz__ROOT__')) { 38 | $this->setAdapter(__config('archive.driver')); 39 | } 40 | 41 | if (adapter !== null) { 42 | $this->setAdapter($adapter); 43 | } 44 | } 45 | 46 | /** 47 | * Set the adapter. 48 | * 49 | * @param (string) $adapter 50 | * 51 | * @since 1.0.0 52 | * 53 | * @return object 54 | */ 55 | public function setAdapter($adapter): self 56 | { 57 | switch (strtolower($adapter)) { 58 | case 'bzip': 59 | $adapterSet = '\alphaz\Archive\Adapter\Bzip'; 60 | break; 61 | case 'gzip': 62 | $adapterSet = '\alphaz\Archive\Adapter\Gzip'; 63 | break; 64 | default: 65 | $adapterSet = '\alphaz\Archive\Adapter\Zip'; 66 | break; 67 | } 68 | $this->adapter = new $adapterSet(); 69 | 70 | return $this; 71 | } 72 | 73 | /** 74 | * Open and extract the archive. 75 | * 76 | * @param (string) $file The file that you want uncompress/open. 77 | * @param (string) $target Where to extract the file. 78 | * @param (bool) $delete True to delete the file; False to not delete it. 79 | * 80 | * @since 1.0.0 81 | * 82 | * @return bool True when succeeded; False when failed. 83 | */ 84 | public function extract(string $file, string $target, bool $delete = false): bool 85 | { 86 | return $this->adapter->extract($file, $target, $delete); 87 | } 88 | 89 | /** 90 | * Compress the file to an archive. 91 | * 92 | * @param (mixed) $files The file(/s) that you want compress. 93 | * @param (string) $destination The file destination. 94 | * @param (bool) $overwrite True to delete the file; False to not delete it. 95 | * 96 | * @since 1.0.0 97 | * 98 | * @return bool True when succeeded; False when failed. 99 | */ 100 | public function compress($files, string $destination = '', bool $overwrite = false): bool 101 | { 102 | return $this->adapter->compress($files, $destination, $overwrite); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/Language/Language.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Language; 18 | 19 | use alphaz\http\Request; 20 | 21 | class Language 22 | { 23 | /* Use of language codes trait. */ 24 | use LanguageCodesTrait; 25 | 26 | /** 27 | * Set the language. 28 | * 29 | * @param $value=> language symbol 30 | * 31 | * @since 1.0.0 32 | * 33 | * @return string 34 | */ 35 | public function setLanguage($value) 36 | { 37 | cookie_set('lang', $value, time() + 100000, '/', (new Request())->getServerName(), false, false); 38 | } 39 | 40 | /** 41 | * Get the current language. 42 | * 43 | * @since 1.0.0 44 | * 45 | * @return string 46 | */ 47 | public function getLang() 48 | { 49 | if (is_cookie('lang')) { 50 | $language = (array_key_exists(get_cookie('lang'), $this->_languages)) ? get_cookie('lang') : __config('app.language'); 51 | } else { 52 | $language = __config('app.language', 'en'); 53 | } 54 | 55 | return $language; 56 | } 57 | 58 | /** 59 | * Get the language name by key. 60 | * 61 | * @param (string) $key valid key 62 | * 63 | * @since 1.0.0 64 | * 65 | * @return string 66 | */ 67 | public function getNameByKey($key) 68 | { 69 | return (array_key_exists($key, $this->_languages)) ? $this->_languages[$key] : null; 70 | } 71 | 72 | /** 73 | * Include lang string file. 74 | * 75 | * @since 1.0.0 76 | * 77 | * @return string 78 | */ 79 | public function languageString() 80 | { 81 | $data = $data1 = $data2 = []; 82 | $language = $this->getLang(); 83 | if (file_exists(route('locale')."{$language}.php")) { 84 | $data1 += require route('locale')."{$language}.php"; 85 | } 86 | $path = route('com'); 87 | $disk_scan = array_diff(scandir($path), ['..', '.']); 88 | foreach ($disk_scan as $scans) { 89 | if (file_exists($path.$scans."/Locale/{$language}.php")) { 90 | $data2 += require $path.$scans."/Locale/{$language}.php"; 91 | } 92 | } 93 | $data = array_merge($data1, $data2); 94 | 95 | return $data; 96 | } 97 | 98 | /** 99 | * for getting language key and return its value. 100 | * 101 | * @param $key language key 102 | * 103 | * @since 1.0.0 104 | * 105 | * @return string 106 | */ 107 | public function print($key, $default = null) 108 | { 109 | if (!empty($key)) { 110 | return $this->languageString()[strtolower($key)] ?? $default; 111 | } else { 112 | return false; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Common/PasswordManipulation.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 2.9.7 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common; 18 | 19 | use alphaz\Data\Str; 20 | use alphaz\Site\Site; 21 | 22 | class PasswordManipulation 23 | { 24 | /** 25 | * Store password default length. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @var int 30 | */ 31 | private $password_len = 30; 32 | 33 | /** 34 | * Set the password default length. 35 | * 36 | * @param (int) $length Length of password. 37 | * 38 | * @since 1.0.0 39 | * 40 | * @return self 41 | */ 42 | public function setLength(int $length) 43 | { 44 | $this->password_len = $length; 45 | 46 | return $this; 47 | } 48 | 49 | /** 50 | * Get the password default length. 51 | * 52 | * @since 1.0.0 53 | * 54 | * @return int 55 | */ 56 | public function getLength() 57 | { 58 | return $this->password_len; 59 | } 60 | 61 | /** 62 | * Generate the password. 63 | * 64 | * @param (int) $length Password length. 65 | * 66 | * @since 2.9.7 67 | * 68 | * @return string 69 | */ 70 | public function generatePassword($length = 30) 71 | { 72 | $this->setLength($length); 73 | 74 | return Site::Salts($this->getLength(), true); 75 | } 76 | 77 | /** 78 | * Validate the password. 79 | * 80 | * @param $password userPassword 81 | * 82 | * @since 2.9.7 83 | * 84 | * @return bool 85 | */ 86 | public function isValid($password) 87 | { 88 | return (Str::hasUpperCase($password) && Str::hasLowerCase($password) && $this->isN($password) && $this->isS($password) && $this->len($password) >= $this->getLength()) ? true : false; 89 | } 90 | 91 | /** 92 | * Check is the integer included in password. 93 | * 94 | * @param $password userPassword 95 | * 96 | * @since 2.9.7 97 | * 98 | * @return bool 99 | */ 100 | private function isN($password) 101 | { 102 | return preg_match('/[0-9]/', $password); 103 | } 104 | 105 | /** 106 | * Check is special character is in password. 107 | * 108 | * @param $password userPassword 109 | * 110 | * @since 2.9.7 111 | * 112 | * @return bool 113 | */ 114 | private function isS($password) 115 | { 116 | return preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $password); 117 | } 118 | 119 | /** 120 | * Get password length. 121 | * 122 | * @param $password userPassword 123 | * 124 | * @since 2.9.7 125 | * 126 | * @return int 127 | */ 128 | public function len($password) 129 | { 130 | return Str::count($password); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/Common/Env.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common; 18 | 19 | class Env 20 | { 21 | /** 22 | * All of the configuration items. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var array 27 | */ 28 | protected $items = []; 29 | 30 | /** 31 | * Create a new env configuration repository. 32 | * 33 | * @param array $items 34 | * 35 | * @since 1.0.0 36 | * 37 | * @return void 38 | */ 39 | public function __construct($items = []) 40 | { 41 | $this->items = array_merge($this->load(), $items); 42 | } 43 | 44 | /** 45 | * Load the configuration file. 46 | * 47 | * @since 1.0.0 48 | * 49 | * @return array 50 | */ 51 | public function load() 52 | { 53 | $items = []; 54 | if (\defined('__alphaz__ROOT__')) { 55 | $file = __alphaz__ROOT__.'/.env'; 56 | 57 | if (file_exists($file)) { 58 | $handle = fopen($file, 'r'); 59 | if ($handle) { 60 | while (($line = fgets($handle)) !== false) { 61 | // if line start with # then skip it 62 | if (substr($line, 0, 1) === '#') { 63 | continue; 64 | } 65 | // if it is whitespace or empty then skip it 66 | if (trim($line) === '') { 67 | continue; 68 | } 69 | $config = explode('=', $line); 70 | // if config is not 2 then skip it 71 | if (count($config) !== 2) { 72 | continue; 73 | } 74 | 75 | $items = array_merge($items, [ 76 | $config[0] => $config[1], 77 | ]); 78 | } 79 | fclose($handle); 80 | } 81 | } 82 | } 83 | 84 | return $items; 85 | } 86 | 87 | /** 88 | * Get the specified configuration value. 89 | * 90 | * @param string $key 91 | * @param mixed $default 92 | * 93 | * @since 1.0.0 94 | * 95 | * @return mixed 96 | */ 97 | public function get($key, $default = null) 98 | { 99 | if (is_array($key)) { 100 | return $this->items; 101 | } 102 | 103 | return $this->items[$key] ?? $default; 104 | } 105 | 106 | /** 107 | * Get all of the configuration items for the application. 108 | * 109 | * @since 1.0.0 110 | * 111 | * @return array 112 | */ 113 | public function all() 114 | { 115 | return $this->items; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Hashing/Hash.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Hashing; 18 | 19 | class Hash 20 | { 21 | /** 22 | * Store the instance of Hash driver. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var object 27 | */ 28 | private static $driver; 29 | 30 | /** 31 | * __construct. 32 | * 33 | * @since 1.0.0 34 | */ 35 | public static function self($verify = false) 36 | { 37 | $driver = __config('hashing.driver'); 38 | if ($driver === 'bcrypt') { 39 | self::$driver = new BcryptHashing(['cost' => __config('hashing.bcrypt.cost')]); 40 | } elseif ($driver === 'argon2i') { 41 | self::$driver = new ArgonHashing([ 42 | 'memory' => __config('hashing.argon.memory'), 43 | 'time' => __config('hashing.argon.time'), 44 | 'threads' => __config('hashing.argon.threads'), 45 | 'verify' => $verify, 46 | ]); 47 | } elseif ($driver === 'argon2id') { 48 | self::$driver = new Argon2IdHashing([ 49 | 'memory' => __config('hashing.argon.memory'), 50 | 'time' => __config('hashing.argon.time'), 51 | 'threads' => __config('hashing.argon.threads'), 52 | 'verify' => $verify, 53 | ]); 54 | } else { 55 | throw new \Exception('We\'re sorry, The hashing driver '.$driver.' not supported.', 500); 56 | } 57 | } 58 | 59 | /** 60 | * Generate the hash. 61 | * 62 | * @param (string) $original 63 | * @param (array) optional $options 64 | * 65 | * @since 1.0.0 66 | * 67 | * @return string 68 | */ 69 | public static function make($original, $options = null, $verify = false) 70 | { 71 | self::self($verify); 72 | 73 | return self::$driver->make($original, $options); 74 | } 75 | 76 | /** 77 | * Verify the hash. 78 | * 79 | * @param (string) $original 80 | * @param (string) $hash 81 | * 82 | * @since 1.0.0 83 | * 84 | * @return string 85 | */ 86 | public static function verify($original, $hash, $verify = false) 87 | { 88 | self::self($verify); 89 | 90 | return self::$driver->verify($original, $hash); 91 | } 92 | 93 | /** 94 | * Check if the given hash has been hashed using the given options. 95 | * 96 | * @param (string) $hash 97 | * @param (array) optional $options 98 | * 99 | * @since 1.0.0 100 | * 101 | * @return bool 102 | */ 103 | public static function needsRehash($hash, $options = null, $verify = false) 104 | { 105 | self::self($verify); 106 | 107 | return self::$driver->needsRehash($hash, $options); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/http/StatusCode.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\http; 18 | 19 | trait StatusCode 20 | { 21 | /** 22 | * Response codes & messages. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var array 27 | */ 28 | protected static $responseCodes = [ 29 | // Informational 1xx 30 | 100 => 'Continue', 31 | 101 => 'Switching Protocols', 32 | 102 => 'Processing', 33 | 34 | // Success 2xx 35 | 200 => 'OK', 36 | 201 => 'Created', 37 | 202 => 'Accepted', 38 | 203 => 'Non-Authoritative Information', 39 | 204 => 'No Content', 40 | 205 => 'Reset Content', 41 | 206 => 'Partial Content', 42 | 207 => 'Multi-Status', 43 | 208 => 'Already Reported', 44 | 226 => 'IM Used', 45 | 46 | // Redirection 3xx 47 | 300 => 'Multiple Choices', 48 | 301 => 'Moved Permanently', 49 | 302 => 'Found', 50 | 303 => 'See Other', 51 | 304 => 'Not Modified', 52 | 305 => 'Use Proxy', 53 | 306 => 'Switch Proxy', 54 | 307 => 'Temporary Redirect', 55 | 308 => 'Permanent Redirect', 56 | 57 | // Client Error 4xx 58 | 400 => 'Bad Request', 59 | 401 => 'Unauthorized', 60 | 402 => 'Payment Required', 61 | 403 => 'Forbidden', 62 | 404 => 'Not Found', 63 | 405 => 'Method Not Allowed', 64 | 406 => 'Not Acceptable', 65 | 407 => 'Proxy Authentication Required', 66 | 408 => 'Request Timeout', 67 | 409 => 'Conflict', 68 | 410 => 'Gone', 69 | 411 => 'Length Required', 70 | 412 => 'Precondition Failed', 71 | 413 => 'Payload Too Large', 72 | 414 => 'URI Too Long', 73 | 415 => 'Unsupported Media Type', 74 | 416 => 'Range Not Satisfiable', 75 | 417 => 'Expectation Failed', 76 | 421 => 'Misdirected Request', 77 | 422 => 'Unprocessable Entity', 78 | 423 => 'Locked', 79 | 424 => 'Failed Dependency', 80 | 426 => 'Upgrade Required', 81 | 428 => 'Precondition Required', 82 | 429 => 'Too Many Requests', 83 | 431 => 'Request Header Fields Too Large', 84 | 451 => 'Unavailable For Legal Reasons', 85 | 86 | // Server Error 5xx 87 | 500 => 'Internal Server Error', 88 | 501 => 'Not Implemented', 89 | 502 => 'Bad Gateway', 90 | 503 => 'Service Unavailable', 91 | 504 => 'Gateway Timeout', 92 | 505 => 'HTTP Version Not Supported', 93 | 506 => 'Variant Also Negotiates', 94 | 507 => 'Insufficient Storage', 95 | 508 => 'Loop Detected', 96 | 509 => 'Bandwidth Limit Exceeded', 97 | 510 => 'Not Extended', 98 | 511 => 'Network Authentication Required', 99 | ]; 100 | } 101 | -------------------------------------------------------------------------------- /src/Auth/Update.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Auth; 18 | 19 | use alphaz\Common\PasswordManipulation; 20 | use alphaz\Contracts\Auth\Update as UpdateContract; 21 | use alphaz\Database\Db as DB; 22 | use alphaz\Hashing\Hash; 23 | use alphaz\Validation\Validation; 24 | 25 | class Update extends Handler implements UpdateContract 26 | { 27 | /** 28 | * Update the users. 29 | * 30 | * @param (array) $params fields like [name => thisname] 31 | * @param (int) $id id of user 32 | * 33 | * @since 1.0.0 34 | * 35 | * @return void 36 | */ 37 | public function update($params, $id) 38 | { 39 | if (is_array($params)) { 40 | foreach (array_keys($params) as $key => $value) { 41 | $paramsRules = [$value => ['required' => true]]; 42 | } 43 | $paramsValidate = new Validation($params, $paramsRules); 44 | if ($paramsValidate->fail()) { 45 | Error::set($paramsValidate->error()->get()); 46 | } 47 | } 48 | if ($this->fail() !== true) { 49 | $fields = [ 50 | 'db_name' => __config()->auth->db_name, 51 | 'table' => __config()->auth->db_table, 52 | 'columns' => $params, 53 | 'wheres' => ['id = '.$id], 54 | ]; 55 | $db = new DB(); 56 | $db->db()->update($fields); 57 | $db->db()->close(); 58 | Success::set(__printl('auth:success:update')); 59 | } 60 | } 61 | 62 | /** 63 | * Check is username is exists or not. 64 | * 65 | * @param (mixed) $password password of user 66 | * @param (mixed) $repeat confirm password 67 | * @param (int) $id id of user 68 | * 69 | * @since 1.0.0 70 | * 71 | * @return void 72 | */ 73 | public function updatePassword($password, $repeat, $id) 74 | { 75 | if ($password !== $repeat) { 76 | Error::set(__printl('auth:error:password:confirm'), 'password'); 77 | } elseif (__config()->auth->sticky_password === true) { 78 | if (!(new PasswordManipulation())->isValid($password)) { 79 | Error::set(__printl('auth:error:password:sticky'), 'password'); 80 | } 81 | } 82 | if ($this->fail() !== true) { 83 | $password_hash = Hash::make($password); 84 | $params = ['password' => $password_hash]; 85 | $fields = [ 86 | 'db_name' => __config()->auth->db_name, 87 | 'table' => __config()->auth->db_table, 88 | 'columns' => $params, 89 | 'wheres' => ['id = '.$id], 90 | ]; 91 | $db = new DB(); 92 | $db->db()->update($fields); 93 | $db->db()->close(); 94 | Success::set(__printl('auth:success:update_password')); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team umer@lablnet.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /src/Component/Component.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Component; 18 | 19 | use alphaz\http\Request; 20 | use alphaz\http\Response; 21 | use alphaz\Input\Input; 22 | use alphaz\View\View; 23 | 24 | class Component extends \alphaz\Router\Router 25 | { 26 | /** 27 | * Dispatch the route, creating the controller object and running the 28 | * action method. 29 | * 30 | * @param string $url The route URL 31 | * 32 | * @since 1.0.0 33 | * 34 | * @return void 35 | */ 36 | public function dispatch(Request $request) 37 | { 38 | $url = $request->getQueryString(); 39 | $url = $this->RemoveQueryString($url, new Request()); 40 | if ($this->match($url)) { 41 | if (isset($this->params['redirect'])) { 42 | \alphaz\Site\Site::redirect($this->params['to'], $this->params['code']); 43 | 44 | return; 45 | } 46 | (isset($this->params['middleware'])) ? $this->params['middleware'] = new $this->params['middleware']() : null; 47 | if (!isset($this->params['callable'])) { 48 | $controller = $this->params['controller']; 49 | $controller = $this->convertToStudlyCaps($controller); 50 | $controller = $this->getNamespace().$controller; 51 | if (class_exists($controller)) { 52 | (isset($this->params['middleware']) && is_object($this->params['middleware'])) ? ( new $this->params['middleware']())->before(new Request(), new Response(), $this->params) : null; 53 | $controller_object = new $controller($this->params, $this->getInput(new Input())); 54 | $action = $this->params['action']; 55 | $action = $this->convertToCamelCase($action); 56 | if (preg_match('/action$/i', $action) == 0) { 57 | $controller_object->$action(); 58 | (isset($this->params['middleware']) && is_object($this->params['middleware'])) ? (new $this->params['middleware']())->after(new Request(), new Response(), $this->params) : null; 59 | } else { 60 | throw new \Exception("Method $action in controller $controller cannot be called directly - remove the Action suffix to call this method"); 61 | } 62 | } else { 63 | throw new \Exception("Controller class $controller not found"); 64 | } 65 | } else { 66 | (is_object(isset($this->params['middleware']))) ? $this->params['middleware']->before(new Request(), new Response(), $this->params) : null; 67 | call_user_func($this->params['callable'], $this->params); 68 | (is_object(isset($this->params['middleware']))) ? $this->params['middleware']->after(new Request(), new Response(), $this->params) : null; 69 | } 70 | } else { 71 | View::view('errors/404', [], true, [], 404); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Archive/Adapter/Bzip.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * @link https://github.com/alphazframework/framework 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | * 12 | * @license MIT 13 | * 14 | * @since 1.0.0 15 | */ 16 | 17 | namespace alphaz\Archive\Adapter; 18 | 19 | class Bzip implements AdapterInterface 20 | { 21 | /** 22 | * @var int The size of the buffer to use for reading and writing files (default = 4KB). 23 | */ 24 | private $BufferSize = 4096; 25 | 26 | /** 27 | * Open and extract the archive. 28 | * 29 | * @param (string) $file The file that you want uncompress/open. 30 | * @param (string) $target Where to extract the file. 31 | * @param (bool) $delete True to delete the file; False to not delete it. 32 | * 33 | * @since 1.0.0 34 | * 35 | * @return bool True when succeeded; False when failed. 36 | */ 37 | public function extract(string $file = '', string $target = '', bool $delete = false): bool 38 | { 39 | // Return false immediately if the file doesn't exist. 40 | if ($file === '' || !file_exists($file)) { 41 | return false; 42 | } 43 | 44 | if ($handle = bzopen($file, 'r')) { 45 | if ($outfile = fopen($target, 'wb')) { 46 | // Keep repeating until the end of the input file. 47 | while (!feof($handle)) { 48 | fwrite($outfile, bzread($handle, $this->BufferSize)); 49 | } 50 | fclose($outfile); 51 | } 52 | bzclose($handle); 53 | } 54 | if ($delete === true) { 55 | unlink($file); 56 | } 57 | 58 | // Success. :-) 59 | return true; 60 | } 61 | 62 | /** 63 | * Compress file into bzip. 64 | * 65 | * @param (string) $files The file that you want to compress. 66 | * @param (string) $destination The file destination. 67 | * @param (bool) $overwrite True to delete the file; False to not delete it. 68 | * 69 | * @since 1.0.0 70 | * 71 | * @return bool True when succeeded; False when failed. 72 | */ 73 | public function compress($files, string $destination = '', bool $overwrite = false): bool 74 | { 75 | // If the destination already exists and overwrite is false, return false. 76 | if (file_exists($destination) && !$overwrite) { 77 | return true; 78 | } 79 | 80 | // Return false immediately if files isn't a string or is empty. 81 | if (!is_string($files) || $files === '') { 82 | return false; 83 | } 84 | 85 | $filename = $destination; 86 | 87 | if ($outfile = bzopen($filename, 'w')) { 88 | if ($infile = fopen($files, 'rb')) { 89 | while (!feof($infile)) { 90 | bzwrite($outfile, fread($infile, $this->BufferSize)); 91 | } 92 | fclose($infile); 93 | } 94 | bzclose($outfile); 95 | } 96 | //check to make sure the file exists 97 | return file_exists($filename); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Common/Configuration.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Common; 18 | 19 | use alphaz\Contracts\Common\Configuration as ConfigurationContract; 20 | use alphaz\Data\Arrays; 21 | 22 | class Configuration implements ConfigurationContract 23 | { 24 | /** 25 | * All of the configuration items. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @var array 30 | */ 31 | protected $items = []; 32 | 33 | /** 34 | * Create a new configuration repository. 35 | * 36 | * @param array $items 37 | * 38 | * @since 1.0.0 39 | * 40 | * @return void 41 | */ 42 | public function __construct($items = []) 43 | { 44 | if (\defined('__alphaz__ROOT__')) { 45 | $this->file = __alphaz__ROOT__.'/Config/App.php'; 46 | } else { 47 | $this->file = null; 48 | } 49 | 50 | // We need to load array configurations. 51 | $this->items = Arrays::arrayChangeCaseKey(Arrays::dot($this->load()), CASE_LOWER); 52 | $this->items = array_merge($this->items, $items); 53 | } 54 | 55 | /** 56 | * Load the configuration file. 57 | * 58 | * @since 1.0.0 59 | * 60 | * @return array 61 | */ 62 | private function load() 63 | { 64 | $configs = []; 65 | 66 | if (file_exists($this->file)) { 67 | $configs += require $this->file; 68 | } 69 | 70 | return $configs; 71 | } 72 | 73 | /** 74 | * Determine if the given configuration value exists. 75 | * 76 | * @param string $key 77 | * 78 | * @since 1.0.0 79 | * 80 | * @return bool 81 | */ 82 | public function has($key) 83 | { 84 | return Arrays::has($this->items, $key, '.'); 85 | } 86 | 87 | /** 88 | * Get the specified configuration value. 89 | * 90 | * @param string $key 91 | * @param mixed $default 92 | * 93 | * @since 1.0.0 94 | * 95 | * @return mixed 96 | */ 97 | public function get($key, $default = null) 98 | { 99 | if (is_array($key)) { 100 | return $this->items; 101 | } 102 | 103 | return Arrays::get($this->items, $key, $default, '.'); 104 | } 105 | 106 | /** 107 | * Set a given configuration value. 108 | * 109 | * @param array|string $key 110 | * @param mixed $value 111 | * 112 | * @since 1.0.0 113 | * 114 | * @return void 115 | */ 116 | public function set($key, $value = null) 117 | { 118 | $keys = is_array($key) ? $key : [$key => $value]; 119 | 120 | foreach ($keys as $key => $value) { 121 | Arrays::set($this->items, $key, $value, '.'); 122 | } 123 | } 124 | 125 | /** 126 | * Get all of the configuration items for the application. 127 | * 128 | * @since 1.0.0 129 | * 130 | * @return array 131 | */ 132 | public function all() 133 | { 134 | return $this->items; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/Archive/Adapter/Gzip.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * @link https://github.com/alphazframework/framework 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | * 12 | * @license MIT 13 | * 14 | * @since 1.0.0 15 | */ 16 | 17 | namespace alphaz\Archive\Adapter; 18 | 19 | class Gzip implements AdapterInterface 20 | { 21 | /** 22 | * @var int The size of the buffer to use for reading and writing files (default = 4KB). 23 | */ 24 | private $BufferSize = 4096; 25 | 26 | /** 27 | * Open and extract the archive. 28 | * 29 | * @param (string) $file The file that you want uncompress/open. 30 | * @param (string) $target Where to extract the file. 31 | * @param (bool) $delete True to delete the file; False to not delete it. 32 | * 33 | * @since 1.0.0 34 | * 35 | * @return bool True when succeeded; False when failed. 36 | */ 37 | public function extract(string $file = '', string $target = '', bool $delete = false): bool 38 | { 39 | // Return false immediately if the file doesn't exist. 40 | if ($file === '' || !file_exists($file)) { 41 | return false; 42 | } 43 | 44 | if ($handle = gzopen($file, 'rb')) { 45 | if ($outfile = fopen($target, 'wb')) { 46 | // Keep repeating until the end of the input file 47 | while (!gzeof($handle)) { 48 | fwrite($outfile, gzread($handle, $this->BufferSize)); 49 | } 50 | fclose($outfile); 51 | } 52 | gzclose($handle); 53 | } 54 | if ($delete === true) { 55 | unlink($file); 56 | } 57 | 58 | // Success. :-) 59 | return true; 60 | } 61 | 62 | /** 63 | * Compress file into bzip. 64 | * 65 | * @param (string) $files The file that you want to compress. 66 | * @param (string) $destination The file destination. 67 | * @param (bool) $overwrite True to delete the file; False to not delete it. 68 | * @param (int) $mode Level of gzip compression. 69 | * 70 | * @since 1.0.0 71 | * 72 | * @return bool True when succeeded; False when failed. 73 | */ 74 | public function compress($files, string $destination = '', bool $overwrite = false, $mode = 9): bool 75 | { 76 | // If the destination already exists and overwrite is false, return false. 77 | if (file_exists($destination) && !$overwrite) { 78 | return true; 79 | } 80 | 81 | // Return false immediately if files isn't a string or is empty. 82 | if (!is_string($files) || $files === '') { 83 | return false; 84 | } 85 | 86 | $filename = $destination; 87 | if ($outfile = gzopen($filename, 'wb'.$mode)) { 88 | if ($infile = fopen($files, 'rb')) { 89 | while (!feof($infile)) { 90 | gzwrite($outfile, fread($infile, $this->BufferSize)); 91 | } 92 | fclose($infile); 93 | } 94 | gzclose($outfile); 95 | } 96 | //check to make sure the file exists 97 | return file_exists($filename); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Files/FileHandling.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Files; 18 | 19 | class FileHandling 20 | { 21 | /** 22 | * Resource. 23 | * 24 | * @since 1.0.0 25 | * 26 | * @var object 27 | */ 28 | private $resource; 29 | 30 | /** 31 | * File. 32 | * 33 | * @since 1.0.0 34 | * 35 | * @var string 36 | */ 37 | private $file; 38 | 39 | /** 40 | * Modes of file. 41 | * 42 | * @since 1.0.0 43 | * 44 | * @var array 45 | */ 46 | private $modes = [ 47 | 'readOnly' => 'r', 48 | 'readWrite' => 'r+', 49 | 'writeOnly' => 'w', 50 | 'writeMaster' => 'w+', 51 | 'writeAppend' => 'a', 52 | 'readWriteAppend' => 'a+', 53 | 'writeOverride' => 'wa+', 54 | ]; 55 | 56 | /** 57 | * Open the file. 58 | * 59 | * @param (string) $file Name of file with oath. 60 | * @param (string) $mode Mode of file. 61 | * 62 | * @since 1.0.0 63 | * 64 | * @return resource 65 | */ 66 | public function open($file, $mode) 67 | { 68 | if (!empty(trim($file)) && !empty(trim($mode))) { 69 | $this->resource = fopen($file, $this->modes[$mode]); 70 | $this->file = $file; 71 | 72 | return $this; 73 | } 74 | 75 | return false; 76 | } 77 | 78 | /** 79 | * Read the file. 80 | * 81 | * @since 1.0.0 82 | * 83 | * @return mixed 84 | */ 85 | public function read() 86 | { 87 | return fread($this->resource, filesize($this->file)); 88 | } 89 | 90 | /** 91 | * Write on file. 92 | * 93 | * @param (mixed) $data Data that you want write on file 94 | * 95 | * @since 1.0.0 96 | * 97 | * @return bool 98 | */ 99 | public function write($data) 100 | { 101 | return (!empty($data)) ? fwrite($this->resource, $data) : false; 102 | } 103 | 104 | /** 105 | * Delete the file. 106 | * 107 | * @param (string) $file File to be deleted. 108 | * 109 | * @since 1.0.0 110 | * 111 | * @return bool 112 | */ 113 | public function delete($file) 114 | { 115 | if (file_exists($file)) { 116 | unlink($file); 117 | } 118 | 119 | return true; 120 | } 121 | 122 | /** 123 | * Close the file resource. 124 | * 125 | * @since 1.0.0 126 | * 127 | * @return void 128 | */ 129 | public function close() 130 | { 131 | fclose($this->resource); 132 | unset($this->file); 133 | } 134 | 135 | /** 136 | * Add custom mode. 137 | * 138 | * @param (string) $name Valid name. 139 | *.@param (string) $value Valid mode. 140 | * 141 | * @since 1.0.0 142 | * 143 | * @return void 144 | */ 145 | public function addCustomMode($name, $value) 146 | { 147 | array_push($this->modes[$name], $value); 148 | 149 | return $this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/Console/Command.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * @author Muhammad Umer Farooq 11 | * 12 | * @author-profile https://www.facebook.com/Muhammadumerfarooq01/ 13 | * 14 | * For the full copyright and license information, please view the LICENSE 15 | * file that was distributed with this source code. 16 | * 17 | * @license MIT 18 | */ 19 | 20 | namespace alphaz\Console; 21 | 22 | abstract class Command 23 | { 24 | /** 25 | * Sign of the command. 26 | * 27 | * @since 1.0.0 28 | * 29 | * @var string 30 | */ 31 | protected $sign; 32 | 33 | /** 34 | * Description of the command. 35 | * 36 | * @since 1.0.0 37 | * 38 | * @var string 39 | */ 40 | protected $description; 41 | 42 | /** 43 | * Should the command hidden form list. 44 | * 45 | * @since 1.0.0 46 | * 47 | * @var bool 48 | */ 49 | protected $hidden = false; 50 | 51 | /** 52 | * Accpet flag parameter in command. 53 | * 54 | * @since 1.0.0 55 | * 56 | * @var array 57 | */ 58 | protected $flags = []; 59 | 60 | /** 61 | * Create a new command instance. 62 | * 63 | * @return void 64 | */ 65 | public function __construct() 66 | { 67 | //todo 68 | } 69 | 70 | /** 71 | * Get hidden. 72 | * 73 | * @return string 74 | */ 75 | public function getHidden(): bool 76 | { 77 | return $this->hidden; 78 | } 79 | 80 | /** 81 | * Get sign. 82 | * 83 | * @return string 84 | */ 85 | public function getSign(): string 86 | { 87 | return $this->sign ?? ''; 88 | } 89 | 90 | /** 91 | * Get description. 92 | * 93 | * @return string 94 | */ 95 | public function getDescription(): string 96 | { 97 | return $this->description ?? ''; 98 | } 99 | 100 | /** 101 | * Get flags. 102 | * 103 | * @return array 104 | */ 105 | public function getFlags(): array 106 | { 107 | return $this->flags ?? []; 108 | } 109 | 110 | /** 111 | * Function to handle the class. 112 | * 113 | * @param string $str 114 | * @param bool $newLine 115 | * 116 | * @return void 117 | */ 118 | public function write(string $str, bool $newLine = true) 119 | { 120 | (new Output())->write($str, $newLine); 121 | } 122 | 123 | /** 124 | * Prompt user for input. 125 | * 126 | * @param string $str 127 | * 128 | * @return void 129 | */ 130 | public function ask(string $str) 131 | { 132 | $this->write("$str", false); 133 | 134 | return (new Input())->ask(); 135 | } 136 | 137 | /** 138 | * Terminate the console. 139 | * 140 | * @return void 141 | */ 142 | public function terminate(): void 143 | { 144 | exit; 145 | } 146 | 147 | /** 148 | * Function to handle the class. 149 | * 150 | * @param \alphaz\Console\Output $output 151 | * @param \alphaz\Console\Input $input 152 | * @param array $param 153 | * 154 | * @return void 155 | */ 156 | abstract public function handle(Output $output, Input $input, $prams = []): void; 157 | } 158 | -------------------------------------------------------------------------------- /Tests/Hashing/HashingTest.php: -------------------------------------------------------------------------------- 1 | 10]); 17 | $value = $hashing->make('password'); 18 | $this->assertNotSame('password', $value); 19 | $this->assertTrue($hashing->verify('password', $value)); 20 | $this->assertFalse($hashing->needsRehash($value)); 21 | $this->assertTrue($hashing->needsRehash($value, ['cost' => 1])); 22 | $this->assertSame('bcrypt', password_get_info($value)['algoName']); 23 | } 24 | 25 | public function testBasicArgon2iHashing() 26 | { 27 | if (!defined('PASSWORD_ARGON2I')) { 28 | $this->markTestSkipped('PHP not compiled with Argon2i hashing support.'); 29 | } 30 | $hashing = new ArgonHashing(['memory' => 512, 'time' => 5, 'threads' => 3]); 31 | $value = $hashing->make('password'); 32 | $this->assertNotSame('password', $value); 33 | $this->assertTrue($hashing->verify('password', $value)); 34 | $this->assertFalse($hashing->needsRehash($value)); 35 | $this->assertFalse($hashing->needsRehash($value, ['memory' => 512, 'time' => 5, 'threads' => 3])); 36 | $this->assertSame('argon2i', password_get_info($value)['algoName']); 37 | } 38 | 39 | public function testBasicArgon2IdHashing() 40 | { 41 | if (!defined('PASSWORD_ARGON2ID')) { 42 | $this->markTestSkipped('PHP not compiled with Argon2id hashing support.'); 43 | } 44 | $hashing = new Argon2IdHashing(['memory' => 512, 'time' => 5, 'threads' => 3]); 45 | $value = $hashing->make('password'); 46 | $this->assertNotSame('password', $value); 47 | $this->assertTrue($hashing->verify('password', $value)); 48 | $this->assertFalse($hashing->needsRehash($value)); 49 | $this->assertFalse($hashing->needsRehash($value, ['memory' => 512, 'time' => 5, 'threads' => 3])); 50 | $this->assertSame('argon2id', password_get_info($value)['algoName']); 51 | } 52 | 53 | public function testBasicBcryptVerification() 54 | { 55 | $original = 'password'; 56 | $hashing = new BcryptHashing(['cost' => 10, 'verify' => true]); 57 | $hashValue = $hashing->make($original); 58 | $this->assertTrue($hashing->verify($original, $hashValue)); 59 | } 60 | 61 | public function testBasicArgon2iVerification() 62 | { 63 | if (!defined('PASSWORD_ARGON2I')) { 64 | $this->markTestSkipped('PHP not compiled with Argon2i hashing support.'); 65 | } 66 | $original = 'password'; 67 | $hashing = new ArgonHashing(['memory' => 512, 'time' => 5, 'threads' => 3, 'verify' => true]); 68 | $hashValue = $hashing->make($original); 69 | $this->assertTrue($hashing->verify($original, $hashValue)); 70 | } 71 | 72 | public function testBasicArgon2IdVerification() 73 | { 74 | if (!defined('PASSWORD_ARGON2ID')) { 75 | $this->markTestSkipped('PHP not compiled with Argon2id hashing support.'); 76 | } 77 | $original = 'password'; 78 | $hashing = new Argon2IdHashing(['memory' => 512, 'time' => 5, 'threads' => 3, 'verify' => true]); 79 | $hashValue = $hashing->make($original); 80 | $this->assertTrue($hashing->verify($original, $hashValue)); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Contracts/Cache/Cache.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * @link https://github.com/alphazframework/framework 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | * @since 1.0.0 13 | * 14 | * @license MIT 15 | */ 16 | 17 | namespace alphaz\Contracts\Cache; 18 | 19 | interface Cache 20 | { 21 | /** 22 | * __construct. 23 | * 24 | * @since 1.0.0 25 | */ 26 | public function __construct(); 27 | 28 | /** 29 | * Get the adapter of cache. 30 | * 31 | * @since 1.0.0 32 | * 33 | * @return string 34 | */ 35 | public function getAdapter(); 36 | 37 | /** 38 | * Set the valid adapter. 39 | * 40 | * @param (string) $adapter 41 | * 42 | * @since 1.0.0 43 | * 44 | * @return self 45 | */ 46 | public function setProperAdapter($adapter); 47 | 48 | /** 49 | * Get default ttl. 50 | * 51 | * @since 1.0.0 52 | * 53 | * @return int 54 | */ 55 | public function getDefaultTtl(); 56 | 57 | /** 58 | * Get item ttl. 59 | * 60 | * @param (string) $key 61 | * 62 | * @since 1.0.0 63 | * 64 | * @return int|false 65 | */ 66 | public function getItemTtl($key); 67 | 68 | /** 69 | * Get the value from cache. 70 | * 71 | * @param (mixed) $key 72 | * @param (mixed) $default 73 | * 74 | * @since 1.0.0 75 | * 76 | * @return mixed 77 | */ 78 | public function get($key, $default = null); 79 | 80 | /** 81 | * Get the multiple values from cache. 82 | * 83 | * @param (array) $keys 84 | * @param (mixed) $default 85 | * 86 | * @since 1.0.0 87 | * 88 | * @return mixed 89 | */ 90 | public function getMultiple($keys, $default = null); 91 | 92 | /** 93 | * Save item to cache. 94 | * 95 | * @param (mixed) $key key for cache 96 | * @param (mixed) $value value to be cached 97 | * @param (int) $ttl time to live for cache 98 | * 99 | * @since 1.0.0 100 | * 101 | * @return self 102 | */ 103 | public function set($key, $value, $ttl = null); 104 | 105 | /** 106 | * Save multiple items to cache. 107 | * 108 | * @param (array) $cache [key,value,ttl] 109 | * 110 | * @since 1.0.0 111 | * 112 | * @return self 113 | */ 114 | public function setMultiple($cache); 115 | 116 | /** 117 | * Determine if cache exixts. 118 | * 119 | * @param (mixed) $key key for cache 120 | * 121 | * @since 1.0.0 122 | * 123 | * @return bool 124 | */ 125 | public function has($key); 126 | 127 | /** 128 | * Delete item form cache. 129 | * 130 | * @param (mixed) $key key for cache 131 | * 132 | * @since 1.0.0 133 | * 134 | * @return self 135 | */ 136 | public function delete($key); 137 | 138 | /** 139 | * Delete multiples items form cache. 140 | * 141 | * @param (array) $keys 142 | * 143 | * @since 1.0.0 144 | * 145 | * @return self 146 | */ 147 | public function deleteMultiple($keys); 148 | 149 | /** 150 | * Clear all caches. 151 | * 152 | * @since 1.0.0 153 | * 154 | * @return self 155 | */ 156 | public function clear(); 157 | } 158 | --------------------------------------------------------------------------------