├── LICENSE ├── README.md ├── composer.json └── src └── Cygnite ├── .htaccess ├── Alias └── Manager.php ├── AssetManager ├── Asset.php ├── AssetCollection.php ├── AssetExistsException.php └── Html.php ├── Auth ├── AuthInterface.php ├── AuthManager.php ├── AuthServiceProvider.php └── Exception │ ├── InvalidCredentialException.php │ ├── InvalidPasswordException.php │ ├── InvalidUserException.php │ └── UserNotActivatedException.php ├── Bootstrappers ├── Bootstrapper.php ├── BootstrapperDispatcher.php ├── BootstrapperDispatcherInterface.php ├── BootstrapperInterface.php └── Paths.php ├── Cache ├── Exceptions │ ├── ApcExtensionNotFoundException.php │ ├── InvalidCacheDirectoryException.php │ ├── MemcacheClassNotFoundException.php │ └── RedisExtensionNotFoundException.php ├── Factory │ └── Cache.php ├── Storage │ ├── Apc.php │ ├── ApcWrapper.php │ ├── File.php │ ├── MemCache.php │ ├── Memcached.php │ ├── MemcachedConnector.php │ ├── Redis.php │ └── RedisConnector.php └── StorageInterface.php ├── Common ├── ArrayManipulator │ ├── ArrayAccessor.php │ └── ArrayAccessorInterface.php ├── Encrypt.php ├── File │ ├── File.php │ ├── FileExtensionFilter.php │ ├── Thumbnail │ │ └── Image.php │ ├── Upload │ │ ├── FileUploadInterface.php │ │ └── Upload.php │ └── composer.json ├── Input │ ├── Cookie.php │ ├── CookieManager │ │ ├── Cookie.php │ │ ├── CookieInterface.php │ │ └── InvalidCookieException.php │ └── Input.php ├── Mail │ ├── MailServiceProvider.php │ ├── Mailer.php │ └── MailerInterface.php ├── Pagination.php ├── Security.php ├── SessionManager │ ├── AbstractPacket.php │ ├── Database │ │ └── Session.php │ ├── Exceptions │ │ └── SessionNotStartedException.php │ ├── Flash │ │ └── FlashMessage.php │ ├── Manager.php │ ├── Memory │ │ └── Redis.php │ ├── Native │ │ └── Session.php │ ├── PacketInterface.php │ ├── Session.php │ ├── SessionInterface.php │ └── index.php ├── Singleton.php ├── UrlManager │ ├── Manager.php │ └── Url.php └── Zip.php ├── Console ├── Command │ ├── Command.php │ ├── ControllerGeneratorCommand.php │ ├── FormGeneratorCommand.php │ ├── GeneratorCommand.php │ ├── InitCommand.php │ ├── MigrationCommand.php │ ├── ModelGeneratorCommand.php │ └── SeederCommand.php ├── CraftApplication.php ├── Foundation │ ├── Application.php │ └── ConsoleApplicationInterface.php ├── Generator │ ├── Controller.php │ ├── Form.php │ ├── Migrator.php │ ├── Model.php │ └── View.php └── src │ └── Apps │ ├── Controllers │ ├── Controller.php │ ├── Php │ │ └── Controller.php │ └── Resources │ │ └── Stubs │ │ ├── controller.tpl.stub │ │ ├── create.tpl.stub │ │ ├── delete.tpl.stub │ │ ├── edit.tpl.stub │ │ ├── index.tpl.stub │ │ ├── new.tpl.stub │ │ ├── show.tpl.stub │ │ └── update.tpl.stub │ ├── Database │ └── Migration.php │ ├── Form │ └── Form.php │ ├── Models │ └── Model.php │ └── Views │ ├── controller │ ├── Php │ │ ├── create.html.stub │ │ ├── index.html.stub │ │ ├── show.html.stub │ │ └── update.html.stub │ ├── create.html.stub │ ├── index.html.stub │ ├── show.html.stub │ └── update.html.stub │ └── layouts │ ├── base.view.stub │ └── main │ └── base.html.stub ├── Container ├── Container.php ├── ContainerAwareInterface.php ├── Dependency │ └── Builder.php ├── Exceptions │ ├── ContainerException.php │ └── DependencyException.php ├── Injector.php ├── Reflection.php ├── Service │ └── ServiceProvider.php └── index.php ├── Database ├── Configure.php ├── ConnectionManagerTrait.php ├── Connections │ ├── ConnectionFactory.php │ ├── Connector.php │ ├── MySql.php │ └── Oracle.php ├── Cyrus │ ├── ActiveRecord.php │ ├── ActiveRecordInterface.php │ └── Relations │ │ ├── BelongsTo.php │ │ ├── HasMany.php │ │ ├── HasManyThough.php │ │ ├── HasOne.php │ │ └── Relation.php ├── DB.php ├── Exceptions │ ├── ActiveRecordMethodMissingException.php │ ├── ConfigException.php │ └── DatabaseException.php ├── Migration.php ├── Query │ ├── Builder.php │ ├── Joins.php │ └── QueryBuilderInterface.php ├── ResultSet.php ├── Service │ ├── Eloquent.php │ └── Providers │ │ └── EloquentServiceProvider.php └── Table │ ├── Schema.php │ ├── Seeder.php │ └── Table.php ├── EventHandler ├── Event.php ├── EventInterface.php └── EventRegistrarTrait.php ├── Exception ├── ExceptionHandler.php ├── ExceptionInterface.php ├── Http │ ├── HttpException.php │ ├── HttpExceptionInterface.php │ ├── HttpNotFoundException.php │ └── ResponseException.php └── assets │ ├── pretty.css │ └── version_template.stub ├── FormBuilder ├── Form.php ├── FormInterface.php └── Html │ └── Elements.php ├── Foundation ├── Application.php ├── ApplicationInterface.php ├── AutoLoader.php ├── Bootstrappers │ ├── AliasLoaderBootstraper.php │ ├── ApplicationBootstraper.php │ ├── LogBootstraper.php │ └── ViewBootstraper.php ├── Collection.php └── Http │ ├── Kernel.php │ └── KernelInterface.php ├── Hash ├── BCrypt.php ├── Hash.php ├── HashInterface.php └── composer.json ├── Helpers ├── Config.php ├── Inflector.php ├── Profiler.php ├── Str.php └── Support.php ├── Http ├── CsrfValidator.php ├── Header.php ├── Requests │ ├── Files.php │ ├── Request.php │ ├── RequestHeaderConstants.php │ └── RequestMethods.php └── Responses │ ├── JsonResponse.php │ ├── RedirectResponse.php │ ├── Response.php │ ├── ResponseHeader.php │ ├── ResponseInterface.php │ └── StreamedResponse.php ├── Logger └── Log.php ├── Mvc ├── Controller │ ├── AbstractBaseController.php │ ├── ServiceController.php │ └── ServiceControllerInterface.php ├── ControllerViewBridgeTrait.php └── View │ ├── Composer.php │ ├── Exceptions │ ├── ViewEventNotFoundException.php │ └── ViewNotFoundException.php │ ├── Output.php │ ├── Template.php │ ├── Twig │ └── Template.php │ ├── View.php │ ├── ViewFactory.php │ ├── ViewInterface.php │ └── Widget.php ├── Pipeline ├── Pipeline.php ├── PipelineException.php ├── PipelineInterface.php └── PipelineServiceProvider.php ├── Proxy ├── Asset.php └── StaticResolver.php ├── Router ├── Controller │ ├── Controller.php │ ├── ResourceController.php │ ├── RouteController.php │ └── RouteControllerInterface.php ├── InvalidRouterCollectionException.php ├── Middleware │ └── RouteMiddlewareInterface.php ├── Router.php └── RouterInterface.php ├── Services ├── Omnipay │ ├── GatewayManager.php │ ├── Providers │ │ └── OmnipayServiceProvider.php │ └── composer.json ├── SocialOAuth │ └── Providers │ │ └── SocialAuthServiceProvider.php └── Stripe │ ├── Providers │ └── StripeServiceProvider.php │ └── composer.json ├── Translation ├── Translator.php └── TranslatorInterface.php └── Validation ├── Exception └── ValidatorException.php ├── ValidationTrait.php ├── Validator.php └── ValidatorInterface.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2014 Cygnite Framework 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##Cygnite PHP Framework 2 | ----------------------------------- 3 | [![Build Status](https://travis-ci.org/cygnite/framework.svg)](https://travis-ci.org/cygnite/framework) 4 | [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cygnite/framework?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | [![HHVM Status](http://hhvm.h4cc.de/badge/cygnite/framework.svg)](http://hhvm.h4cc.de/package/cygnite/framework) 6 | [![Latest Stable Version](https://poser.pugx.org/cygnite/framework/v/stable.svg)](https://packagist.org/packages/cygnite/framework) [![Total Downloads](https://poser.pugx.org/cygnite/framework/downloads.svg)](https://packagist.org/packages/cygnite/framework) [![Latest Unstable Version](https://poser.pugx.org/cygnite/framework/v/unstable.svg)](https://packagist.org/packages/cygnite/framework) [![License](https://poser.pugx.org/cygnite/framework/license.svg)](https://packagist.org/packages/cygnite/framework) 7 | 8 | 9 | Cygnite Framework it's just a small footprint to give you the creative experience of developing a web application. 10 | Cygnite is beautifully crafted to make your job simple and better without being worried about performance. 11 | 12 | You will find several eye catching features into Cygnite Framework. 13 | 14 | ##Requirements 15 | ----------------------- 16 | 17 | The following versions of PHP are supported by this version. 18 | 19 | - PHP 7.0 and above 20 | - HHVM 21 | 22 | ### Key Features - 23 | ----------------------- 24 | 25 | 1. Powered By Composer. 26 | 2. Zero Configuration. 27 | 3. Powerful Craft Console On Top Of Symfony Console. Creating CRUD, Forms, Commands, Migrations and lot more Is Just Easy. 28 | 4. Cyrus Lightweight ORM. 29 | 5. As Simple For Begginer As Well As For Advance Developers. 30 | 6. RESTFul Routing, Events, Controllers Helps You To Build Powerful API. 31 | 7. Powerful IoC Container, HTTP Requests/Responses, Middlewares, Events, Bootstrappers, Services, Tracy Exception Handler etc. 32 | 8. Integrated Third Party Payment Gateway, Social Authentication Libraries (Omnipay, Stripe, SocialOAuth etc.) 33 | 9. Use Plain PHP Layout or Twig Template Engine. 34 | 10. Use Classic Controllers, Service Controllers or HMVC Modules For Building Modular Application. 35 | 36 | ###Contributing To Cygnite Framework 37 | --------------------------------------------------- 38 | 39 | Contribute on the development or its documentation, learn, get help and help others, find, report bugs, send us your feedback, send your wishlist for new features, write and send us patches for Cygnite Framework. 40 | 41 | You can contribute into cygnite development different ways. Read more in official website- 42 | 43 | http://www.cygniteframework.com/ 44 | 45 | 46 | ###License 47 | -------------- 48 | 49 | The Cygnite Framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). 50 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cygnite/framework", 3 | "description": "Cygnite PHP Framework", 4 | "type": "library", 5 | "keywords": ["Cygnite", "PHP", "Framework"], 6 | "homepage": "http://www.cygniteframework.com", 7 | "license": "MIT", 8 | "support": { 9 | "issues": "https://github.com/cygnite/framework/issues", 10 | "source": "https://github.com/cygnite/framework" 11 | }, 12 | "authors": [{ 13 | "name": "Sanjoy Dey", 14 | "email": "dey.sanjoy0@gmail.com" 15 | }, { 16 | "name": "Cygnite Contributors", 17 | "homepage": "https://github.com/cygnite/framework/graphs/contributors" 18 | }], 19 | "require": { 20 | "php": ">=5.6.4", 21 | "twig/twig": "2.1.*", 22 | "symfony/console": "3.2.*", 23 | "tracy/tracy": "2.4.*", 24 | "ircmaxell/password-compat": "1.0.*", 25 | "swiftmailer/swiftmailer": "5.4.*", 26 | "monolog/monolog": "~1.22", 27 | "nesbot/carbon": "~1.20", 28 | "league/flysystem": "~1.0", 29 | "symfony/finder": "~3.2" 30 | }, 31 | "require-dev": { 32 | "mockery/mockery": "~0.9.7", 33 | "phpunit/phpunit": "~6.0", 34 | "predis/predis": "1.1.*", 35 | "squizlabs/php_codesniffer": "^2.8" 36 | }, 37 | "autoload": { 38 | "files": ["src/Cygnite/Helpers/Support.php"], 39 | "psr-4": { 40 | "Cygnite\\": "src/Cygnite" 41 | } 42 | }, 43 | "autoload-dev": { 44 | "psr-4": { 45 | "Cygnite\\Tests\\": "tests/Cygnite" 46 | } 47 | }, 48 | "extra": { 49 | "branch-alias": { 50 | "dev-master": "3.0-dev" 51 | } 52 | }, 53 | "config": { 54 | "sort-packages": true 55 | }, 56 | "minimum-stability": "dev", 57 | "prefer-stable": true 58 | } 59 | -------------------------------------------------------------------------------- /src/Cygnite/.htaccess: -------------------------------------------------------------------------------- 1 | Deny from all 2 | -------------------------------------------------------------------------------- /src/Cygnite/AssetManager/AssetCollection.php: -------------------------------------------------------------------------------- 1 | asset(); 53 | } 54 | 55 | return $callback($collection); 56 | } 57 | 58 | /** 59 | * Register Asset into Asset object and returns 60 | * Asset object. 61 | * 62 | * @param $class 63 | * @param Closure $callback 64 | * @return mixed 65 | */ 66 | public static function create($class, ContainerAwareInterface $container) : Asset 67 | { 68 | (new $class($a = new Asset($container)))->register(); 69 | 70 | return static::$asset = $a; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Cygnite/AssetManager/AssetExistsException.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\AssetManager; 11 | 12 | use Cygnite\Helpers\Config; 13 | 14 | if (!defined('CF_SYSTEM')) { 15 | exit('External script access not allowed'); 16 | } 17 | 18 | class Html 19 | { 20 | /** 21 | * Convert Html characters to entities. 22 | * 23 | * Encoding will be used based on configuration given in Config file. 24 | * 25 | * @false string $value 26 | * 27 | * @param $value 28 | * 29 | * @return string 30 | */ 31 | public static function entities($value) 32 | { 33 | return htmlentities($value, ENT_QUOTES, Config::get('global.config', 'encoding'), false); 34 | } 35 | 36 | /** 37 | * Convert entities to Html characters. 38 | * 39 | * @false string $value 40 | * 41 | * @param $value 42 | * 43 | * @return string 44 | */ 45 | public static function decode($value) 46 | { 47 | return html_entity_decode($value, ENT_QUOTES, Config::get('global.config', 'encoding')); 48 | } 49 | 50 | /** 51 | * Convert Html special characters. 52 | * 53 | * Encoding will be used based on configuration given in Config file. 54 | * 55 | * @false string $value 56 | * 57 | * @param $value 58 | * 59 | * @throws InvalidArgumentException 60 | * 61 | * @return string 62 | */ 63 | public static function specialCharacters($value) 64 | { 65 | if (is_null($value)) { 66 | throw new InvalidArgumentException('Cannot pass null argument to '.__METHOD__); 67 | } 68 | 69 | return htmlspecialchars($value, ENT_QUOTES, Config::get('global.config', 'encoding'), false); 70 | } 71 | 72 | /** 73 | * The method to sanitize data. 74 | * 75 | * @false mixed $data 76 | */ 77 | public function sanitize($value, $type = '') 78 | { 79 | switch ($type) { 80 | default: 81 | return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); 82 | break; 83 | case 'strong': 84 | return htmlentities($value, ENT_QUOTES | ENT_IGNORE, 'UTF-8'); 85 | break; 86 | case 'strict': 87 | return urlencode($value); 88 | break; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Cygnite/Auth/AuthInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Auth; 12 | 13 | use Cygnite\Foundation\Application; 14 | use Cygnite\Helpers\Inflector; 15 | 16 | abstract class AuthManager 17 | { 18 | /** 19 | * @var 20 | */ 21 | public static $model; 22 | 23 | /** 24 | * Set the model class name to authenticate user. 25 | * 26 | * @param $model 27 | */ 28 | public static function model($model) 29 | { 30 | static::$model = $model; 31 | $class = '\\'.get_called_class(); 32 | 33 | return $class::make(); 34 | } 35 | 36 | /** 37 | * get model class name. 38 | * 39 | * @return null 40 | */ 41 | public function getModel() 42 | { 43 | return isset(static::$model) ? static::$model : null; 44 | } 45 | 46 | /** 47 | * Get the application instance. 48 | * 49 | * @return Application 50 | */ 51 | public static function getContainer() 52 | { 53 | return Application::instance(); 54 | } 55 | 56 | /** 57 | * Get the model object to check user existance against database. 58 | * 59 | * @return object 60 | */ 61 | public function user() 62 | { 63 | $app = self::getContainer(); 64 | 65 | return $app->make(static::getModel()); 66 | } 67 | 68 | /** 69 | * Get the current table name. 70 | * 71 | * @return mixed 72 | */ 73 | public function table() 74 | { 75 | return Inflector::tabilize(Inflector::getClassNameFromNamespace(self::getModel())); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Cygnite/Auth/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\AuthManager; 12 | 13 | use Cygnite\DependencyInjection\ServiceProvider; 14 | use Cygnite\Foundation\Application; 15 | 16 | class AuthServiceProvider extends ServiceProvider 17 | { 18 | protected $container; 19 | 20 | public function register(Application $app) 21 | { 22 | $app->singleton('auth', function ($c) { 23 | return new Auth($c['auth.provider']); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Cygnite/Auth/Exception/InvalidCredentialException.php: -------------------------------------------------------------------------------- 1 | paths = $paths; 27 | } 28 | 29 | /** 30 | * @param array $classes 31 | */ 32 | public function registerBootstrappers(array $classes, $override = false) 33 | { 34 | if ($override) { 35 | $this->bootstrappers = $classes; 36 | 37 | return $this; 38 | } 39 | 40 | $this->bootstrappers = array_merge($this->bootstrappers, $classes); 41 | 42 | return $this; 43 | } 44 | 45 | /** 46 | * Get all paths 47 | */ 48 | public function getPaths() : Paths 49 | { 50 | return $this->paths; 51 | } 52 | 53 | /** 54 | * Return all bootstrappers 55 | * @return mixed 56 | */ 57 | public function all() : array 58 | { 59 | return $this->bootstrappers; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Cygnite/Bootstrappers/BootstrapperDispatcher.php: -------------------------------------------------------------------------------- 1 | container = $container; 28 | $this->bootstrappers = $bootstrappers; 29 | } 30 | 31 | /** 32 | * Get bootstrappers instance 33 | * @return array 34 | */ 35 | public function getBootstrapper() 36 | { 37 | return $this->bootstrappers; 38 | } 39 | 40 | /** 41 | * Run all defined bootstrappers 42 | * 43 | * @throws \RuntimeException 44 | */ 45 | public function execute() 46 | { 47 | foreach (array_unique($this->bootstrappers->all()) as $class) { 48 | $bootstrapper = $this->create($class); 49 | 50 | if (!method_exists($bootstrapper, 'run')) { 51 | throw new \RuntimeException("$class must have run() method"); 52 | } 53 | 54 | $bootstrapper->run(); 55 | } 56 | } 57 | 58 | /** 59 | * Store all bootstrappers into instance stack 60 | * 61 | * @param string $class 62 | */ 63 | public function create(string $class) : BootstrapperInterface 64 | { 65 | if (!isset($this->instances[$class])) { 66 | $this->instances[$class] = new $class($this->container, $this->bootstrappers->getPaths()); 67 | } 68 | 69 | return $this->instances[$class]; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Cygnite/Bootstrappers/BootstrapperDispatcherInterface.php: -------------------------------------------------------------------------------- 1 | $value) { 20 | $this->paths[$key] = $value; 21 | } 22 | } 23 | 24 | /** 25 | * @param mixed $offset 26 | * @return bool|void 27 | */ 28 | public function offsetExists($offset) : bool 29 | { 30 | return isset($this->paths[$offset]); 31 | } 32 | 33 | /** 34 | * @param $offset 35 | * @return null 36 | */ 37 | public function offsetGet($offset) 38 | { 39 | return isset($this->paths[$offset]) ? $this->paths[$offset] : null; 40 | } 41 | 42 | /** 43 | * @param $offset 44 | * @param $value 45 | * @throws \InvalidArgumentException 46 | */ 47 | public function offsetSet($offset, $value) 48 | { 49 | if ($offset === null) { 50 | throw new \InvalidArgumentException("Offset cannot be empty"); 51 | } 52 | 53 | $this->paths[$offset] = realpath($value); 54 | } 55 | 56 | /** 57 | * @param $offset 58 | */ 59 | public function offsetUnset($offset) 60 | { 61 | unset($this->paths[$offset]); 62 | } 63 | 64 | /** 65 | * Return all paths as array 66 | * @return array 67 | */ 68 | public function all() : array 69 | { 70 | return $this->paths; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Cygnite/Cache/Exceptions/ApcExtensionNotFoundException.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Cache\Factory; 11 | 12 | use Cygnite\Cache\Storage\ApcWrapper; 13 | use Cygnite\Cache\Storage\MemcachedConnector; 14 | use Cygnite\Cache\Storage\RedisConnector; 15 | use Cygnite\Helpers\Config; 16 | use Predis\Client as RedisClient; 17 | 18 | if (!defined('CF_SYSTEM')) { 19 | exit('External script access not allowed'); 20 | } 21 | 22 | class Cache 23 | { 24 | // Cache Drivers 25 | public static $drivers = [ 26 | 'file' => '\\Cygnite\\Cache\\Storage\\File', 27 | 'apc' => '\\Cygnite\\Cache\\Storage\\Apc', 28 | 'memcache' => '\\Cygnite\\Cache\\Storage\\MemCache', 29 | 'memcached' => '\\Cygnite\\Cache\\Storage\\Memcached', 30 | 'redis' => '\\Cygnite\\Cache\\Storage\\Redis', 31 | ]; 32 | 33 | /** 34 | * Factory Method to return appropriate driver instance. 35 | * 36 | * @param $cache 37 | * @param callable $callback 38 | * @throws \RuntimeException 39 | * @return mixed 40 | */ 41 | public static function make($cache, \Closure $callback) 42 | { 43 | // Return Closure callback 44 | if (array_key_exists($cache, static::$drivers)) { 45 | return static::getCacheDriver($callback, $cache); 46 | } 47 | 48 | throw new \RuntimeException('Cache driver not found!'); 49 | } 50 | 51 | /** 52 | * @param $callback 53 | * @param $cache 54 | * 55 | * @return mixed 56 | */ 57 | public static function getCacheDriver($callback, $cache) 58 | { 59 | switch ($cache) { 60 | case 'apc': 61 | return $callback(new static::$drivers[$cache](new ApcWrapper())); 62 | break; 63 | case 'memcached': 64 | $memcached = static::getMemcahcedDriver(); 65 | 66 | return $callback(new static::$drivers[$cache]($memcached)); 67 | 68 | break; 69 | case 'redis': 70 | $redis = static::getRedisDriver(); 71 | 72 | return $callback(new static::$drivers[$cache]($redis)); 73 | 74 | break; 75 | default: 76 | return $callback(new static::$drivers[$cache]()); 77 | break; 78 | } 79 | } 80 | 81 | /** 82 | * @return null|void 83 | */ 84 | private static function getMemcahcedDriver() 85 | { 86 | $config = Config::get('global.config', 'cache'); 87 | 88 | $memcached = null; 89 | if ($config['memcached']['autoconnnect']) { 90 | $uniqueId = $config['memcached']['uniqueId']; 91 | $memCachedInstance = (!is_null($uniqueId)) ? new \Memcached($uniqueId) : new \Memcached(); 92 | 93 | $memcached = (new MemcachedConnector($memCachedInstance))->create($config['memcached']['servers']); 94 | } 95 | 96 | return $memcached; 97 | } 98 | 99 | /** 100 | * @return RedisConnector|null 101 | */ 102 | private static function getRedisDriver() 103 | { 104 | $config = Config::get('global.config', 'cache'); 105 | 106 | $redis = null; 107 | if (isset($config['redis'])) { 108 | $redis = new RedisConnector(new RedisClient(), $config['redis']); 109 | } 110 | 111 | return $redis; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/Cygnite/Cache/Storage/Apc.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Cache\Storage; 12 | 13 | use Cygnite\Cache\StorageInterface; 14 | use Exception; 15 | 16 | if (!defined('CF_SYSTEM')) { 17 | exit('External script access not allowed'); 18 | } 19 | 20 | /** 21 | * Cygnite APC Cache Wrapper Class. 22 | * 23 | * @author Sanjoy Dey 24 | */ 25 | class Apc implements StorageInterface 26 | { 27 | protected $apc; 28 | 29 | /* 30 | * Constructor function to check availability of apc extension, 31 | * throws exception if not available 32 | * 33 | */ 34 | 35 | public function __construct(ApcWrapper $apc) 36 | { 37 | $this->apc = $apc; 38 | } 39 | 40 | /** 41 | * @param callable $callback 42 | * 43 | * @return static 44 | */ 45 | public static function make(callable $callback = null) 46 | { 47 | if (is_callable($callback) && !is_null($callback)) { 48 | return $callback(new static(new ApcWrapper())); 49 | } 50 | 51 | return new static(new ApcWrapper()); 52 | } 53 | 54 | /** 55 | * Store item into apc memory. 56 | * 57 | * @param $key 58 | * @param $value 59 | * @param null $minute 60 | * 61 | * @return mixed 62 | */ 63 | public function store($key, $value, $minute = null) 64 | { 65 | return $this->apc->store($key, $value, $minute = null); 66 | } 67 | 68 | /** 69 | * This function is used to set default life time. 70 | * 71 | * @param null $lifeTime 72 | * 73 | * @return mixed 74 | */ 75 | public function setLifeTime($lifeTime = null) 76 | { 77 | return $this->apc->setLifeTime($lifeTime); 78 | } 79 | 80 | /** 81 | * This function is used to get life time of apc cache. 82 | * 83 | * @return bool 84 | */ 85 | public function getLifeTime() 86 | { 87 | return $this->apc->getLifeTime(); 88 | } 89 | 90 | /** 91 | * Get data from memory based on its key. 92 | * 93 | * @param $key 94 | * 95 | * @return mixed 96 | */ 97 | public function get($key) 98 | { 99 | return $this->apc->get($key); 100 | } 101 | 102 | /** 103 | * @param $key 104 | * @param $value 105 | * 106 | * @return mixed 107 | */ 108 | public function increment($key, $value) 109 | { 110 | return $this->apc->increment($key, $value); 111 | } 112 | 113 | /** 114 | * @param $key 115 | * @param $value 116 | * 117 | * @return mixed 118 | */ 119 | public function decrement($key, $value) 120 | { 121 | return $this->apc->decrement($key, $value); 122 | } 123 | 124 | /** 125 | * Delete values from memory based on its key. 126 | * 127 | * @param $key 128 | * 129 | * @return mixed 130 | */ 131 | public function destroy($key) 132 | { 133 | return $this->apc->destroy($key); 134 | } 135 | 136 | /** 137 | * Remove all items from the cache. 138 | * 139 | * @return void 140 | */ 141 | public function flush() 142 | { 143 | return $this->apc->flush(); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/Cygnite/Cache/Storage/Memcached.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Cache\Storage; 12 | 13 | use Cygnite\Cache\StorageInterface; 14 | 15 | if (!defined('CF_SYSTEM')) { 16 | exit('External script access not allowed'); 17 | } 18 | 19 | /** 20 | * Cygnite Memcache Cache Wrapper Class. 21 | * 22 | * @author Sanjoy Dey 23 | */ 24 | class Memcached implements StorageInterface 25 | { 26 | public $memcached; 27 | 28 | public function __construct($connector = null) 29 | { 30 | if (!is_null($connector)) { 31 | $this->memcached = $connector; 32 | } 33 | } 34 | 35 | /** 36 | * 37 | * $connector = new MemcachedConnector() 38 | * $connection = $connector->create($servers);. 39 | * 40 | * Cache::make('memcached', function ($memcached) use($connection) 41 | * { 42 | * $memcached->setConnector($connection); 43 | * 44 | * $memcached->store('foo', 'Foo Bar'); 45 | * }); 46 | * 47 | * 48 | */ 49 | public function setConnector($connector) 50 | { 51 | $this->memcached = $connector; 52 | } 53 | 54 | public function memcached() 55 | { 56 | return $this->memcached; 57 | } 58 | 59 | /** 60 | * Store the value in the memcached memory (overwrite if key exists). 61 | * 62 | * @false string $key 63 | * @false mix $value 64 | * @false bool $compress 65 | * @false int $expire (seconds before item expires) 66 | * 67 | * @param $key 68 | * @param $value 69 | * @param int $minutes 70 | * 71 | * @throws \InvalidArgumentException 72 | * 73 | * @return bool 74 | */ 75 | public function store($key, $value, $minutes = 10) 76 | { 77 | if (is_null($key)) { 78 | throw new \InvalidArgumentException('Invalid key passed to Memcached::'.__FUNCTION__); 79 | } 80 | 81 | return $this->memcached()->set($key, $value, $minutes * 60); 82 | } 83 | 84 | /** 85 | * @param $key 86 | * @param $value 87 | * @param int $minutes 88 | * 89 | * @return mixed 90 | */ 91 | public function add($key, $value, $minutes = 10) 92 | { 93 | return $this->memcached()->add($key, $value, $minutes * 60); 94 | } 95 | 96 | /** 97 | * @param $key 98 | * @param int $value 99 | * 100 | * @return mixed 101 | */ 102 | public function increment($key, $value = 1) 103 | { 104 | return $this->memcached()->increment($key, $value); 105 | } 106 | 107 | /** 108 | * @param $key 109 | * @param int $value 110 | * 111 | * @return mixed 112 | */ 113 | public function decrement($key, $value = 1) 114 | { 115 | return $this->memcached()->decrement($key, $value); 116 | } 117 | 118 | /** 119 | * Get data from memory based on its key. 120 | * 121 | * @false string $key 122 | * 123 | * @param $key 124 | * 125 | * @return bool 126 | */ 127 | public function get($key) 128 | { 129 | $data = []; 130 | $data = $this->memcached()->get($key); 131 | 132 | return ($this->memcached()->getResultCode() == 0) ? $data : null; 133 | } 134 | 135 | /** 136 | * Delete values from memory based on its key. 137 | * 138 | * @false string $key 139 | * 140 | * @param $key 141 | * 142 | * @throws \Exception 143 | * 144 | * @return bool 145 | */ 146 | public function destroy($key) 147 | { 148 | if (is_null($key)) { 149 | throw new \InvalidArgumentException('Empty key passed to Memcached::'.__FUNCTION__); 150 | } 151 | 152 | return $this->memcached()->delete($key); 153 | } 154 | 155 | /** 156 | * Remove all items from the cache. 157 | * 158 | * @return void 159 | */ 160 | public function flush() 161 | { 162 | $this->memcached()->flush(); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/Cygnite/Cache/Storage/MemcachedConnector.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Cache\Storage; 12 | 13 | use Memcached; 14 | 15 | if (!defined('CF_SYSTEM')) { 16 | exit('External script access not allowed'); 17 | } 18 | 19 | /** 20 | * Cygnite Memcached Cache Connection Wrapper Class. 21 | * 22 | * @author Sanjoy Dey 23 | */ 24 | class MemcachedConnector 25 | { 26 | protected $memcached; 27 | 28 | /** 29 | * Set Memcached Instance. 30 | * 31 | * @param $memCached Memcached 32 | */ 33 | public function __construct($memCached) 34 | { 35 | $this->memcached = $memCached; 36 | } 37 | 38 | /** 39 | * Connect Memcached based on its host, port, weight. 40 | * 41 | * @false string $host 42 | * @false mix $port 43 | * 44 | * @param array $servers 45 | * 46 | * @throws \RuntimeException 47 | * 48 | * @internal param string $host 49 | * @internal param string $port 50 | * 51 | * @return void 52 | */ 53 | public function create(array $servers) 54 | { 55 | if (empty($servers)) { 56 | throw new \RuntimeException(sprintf('Empty configuration passed to %s::create() method.', __CLASS__)); 57 | } 58 | 59 | foreach ($servers as $server) { 60 | $this->memcached->addServer( 61 | $server['host'], $server['port'], $server['weight'] 62 | ); 63 | } 64 | 65 | $status = $this->memcached->getVersion(); 66 | 67 | if (in_array('255.255.255', $status) && count(array_unique($status)) === 1) { 68 | throw new \RuntimeException('Could not establish Memcached connection.'); 69 | } 70 | 71 | return $this->memcached; 72 | } 73 | 74 | /** 75 | * Connection object. 76 | * 77 | * @return Memcached 78 | */ 79 | public function memcached() 80 | { 81 | return $this->memcached; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Cygnite/Cache/Storage/Redis.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Cache\Storage; 12 | 13 | use Cygnite\Cache\StorageInterface; 14 | 15 | if (!defined('CF_SYSTEM')) { 16 | exit('External script access not allowed'); 17 | } 18 | 19 | /** 20 | * Cygnite Redis Cache Wrapper Class. 21 | * 22 | * @author Sanjoy Dey 23 | */ 24 | class Redis implements StorageInterface 25 | { 26 | public $redis; 27 | 28 | public $prefix = 'cygnite:'; 29 | 30 | /** 31 | * @param null $connector 32 | */ 33 | public function __construct($connector = null) 34 | { 35 | if (!is_null($connector)) { 36 | $this->redis = $connector; 37 | } 38 | } 39 | 40 | /** 41 | * @param $connection 42 | */ 43 | public function setConnection($connection) 44 | { 45 | $this->redis = $connection; 46 | } 47 | 48 | /** 49 | * @param string $name 50 | * 51 | * @return mixed 52 | */ 53 | public function connection($name = 'default') 54 | { 55 | return $this->redis->connection($name); 56 | } 57 | 58 | /** 59 | * @return null 60 | */ 61 | public function redis() 62 | { 63 | return $this->redis; 64 | } 65 | 66 | /** 67 | * @param $key 68 | * @param $data 69 | * @param int $minutes 70 | * 71 | * @return mixed 72 | */ 73 | public function store($key, $data, $minutes = 1) 74 | { 75 | $data = (!is_numeric($data)) ? serialize($data) : $data; 76 | 77 | return $this->connection()->setex($this->prefix.$key, $minutes * 60, $data); 78 | } 79 | 80 | /** 81 | * Store item with prefix. 82 | * 83 | * @param $key 84 | * @param $value 85 | * 86 | * @return mixed 87 | */ 88 | public function set($key, $value) 89 | { 90 | $value = (!is_numeric($value)) ? serialize($value) : $value; 91 | 92 | return $this->connection()->set($this->prefix.$key, $value); 93 | } 94 | 95 | /** 96 | * Get the item from redis memory. 97 | * 98 | * @param $key 99 | * 100 | * @return int|mixed|null|string 101 | */ 102 | public function get($key) 103 | { 104 | $data = $this->connection()->get($this->prefix.$key); 105 | 106 | if (!is_null($data)) { 107 | return (is_numeric($data)) ? $data : unserialize($data); 108 | } 109 | } 110 | 111 | /** 112 | * @param $key 113 | * @param int $value 114 | * 115 | * @return mixed 116 | */ 117 | public function increment($key, $value = 1) 118 | { 119 | return $this->connection()->incrby($this->prefix.$key, $value); 120 | } 121 | 122 | /** 123 | * @param $key 124 | * @param int $value 125 | * 126 | * @return mixed 127 | */ 128 | public function decrement($key, $value = 1) 129 | { 130 | return $this->connection()->decrby($this->prefix.$key, $value); 131 | } 132 | 133 | /** 134 | * @param $key 135 | * 136 | * @return mixed 137 | */ 138 | public function destroy($key) 139 | { 140 | return $this->connection()->del($this->prefix.$key); 141 | } 142 | 143 | /** 144 | * Flush all data from redis storage. 145 | */ 146 | public function flush() 147 | { 148 | $this->connection()->flushdb(); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/Cygnite/Cache/Storage/RedisConnector.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Cache\Storage; 12 | 13 | use Predis\Client as RedisClient; 14 | 15 | if (!defined('CF_SYSTEM')) { 16 | exit('External script access not allowed'); 17 | } 18 | 19 | /** 20 | * Class RedisConnector. 21 | * 22 | * @source https://github.com/nrk/predis 23 | */ 24 | class RedisConnector 25 | { 26 | protected $redisClient; 27 | 28 | public $config = []; 29 | 30 | public $connections = []; 31 | 32 | /** 33 | * @param array $config 34 | */ 35 | public function __construct($client, array $config) 36 | { 37 | $this->redisClient = $client; 38 | $this->config = $config; 39 | 40 | if ($config['connection'] !== 'deafult' && isset($config['connection']['servers'])) { 41 | $this->connect($config['connection']['servers']); 42 | } else { 43 | $this->connectDefault(); 44 | } 45 | } 46 | 47 | /** 48 | * @param array $servers 49 | * 50 | * @return array 51 | */ 52 | public function connect(array $servers) 53 | { 54 | $class = $this->redisClient; 55 | $options = isset($servers['options']) ? (array) $servers['options'] : []; 56 | 57 | foreach ($servers as $key => $server) { 58 | $this->connections[$key] = new $class($server, $options); 59 | } 60 | 61 | return $this->connections; 62 | } 63 | 64 | /** 65 | * @return RedisClient 66 | */ 67 | public function getRedis() 68 | { 69 | return $this->redisClient; 70 | } 71 | 72 | /** 73 | * @return RedisClient 74 | */ 75 | public function connectDefault() 76 | { 77 | $class = $this->redisClient; 78 | 79 | return $this->connections['default'] = new $class(); 80 | } 81 | 82 | /** 83 | * @param string $key 84 | * 85 | * @return mixed 86 | */ 87 | public function connection($key = 'default') 88 | { 89 | return $this->connections[$key ?: 'default']; 90 | } 91 | 92 | /** 93 | * Dynamically call methods of Redis. 94 | * 95 | * @param string $method 96 | * @param array $arguments 97 | * 98 | * @return mixed 99 | */ 100 | public function __call($method, array $arguments = []) 101 | { 102 | return call_user_func_array([$this->connection(), $method], $arguments); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/Cygnite/Cache/StorageInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Cache; 12 | 13 | if (!defined('CF_SYSTEM')) { 14 | exit('External script access not allowed'); 15 | } 16 | 17 | interface StorageInterface 18 | { 19 | /* Abstract store method of caching*/ 20 | public function store($key, $value); 21 | 22 | /* Abstract the cache retrieving function */ 23 | public function get($key); 24 | 25 | /* Abstract the cache destroy function */ 26 | public function destroy($key); 27 | } 28 | -------------------------------------------------------------------------------- /src/Cygnite/Common/ArrayManipulator/ArrayAccessorInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Cygnite\Common\File; 13 | 14 | // import SPL classes/interfaces into local scope 15 | use FilterIterator; 16 | 17 | if (!defined('CF_SYSTEM')) { 18 | exit('External script access not allowed'); 19 | } 20 | 21 | class FileExtensionFilter extends FilterIterator 22 | { 23 | // whitelist of file extensions 24 | protected $ext = ['php']; 25 | 26 | public function __construct($dirOrIterator) 27 | { 28 | $iterator = $dirOrIterator; 29 | if ($dirOrIterator instanceof \RecursiveIterator) { 30 | $iterator = new \RecursiveIteratorIterator($dirOrIterator); 31 | } 32 | 33 | parent::__construct($iterator); 34 | } 35 | 36 | // an abstract method which must be implemented in subclass 37 | public function accept() 38 | { 39 | $file = $this->getInnerIterator()->current(); 40 | 41 | // If we somehow have something other than an SplFileInfo object, just 42 | // return false 43 | if (!$file instanceof \SplFileInfo) { 44 | return false; 45 | } 46 | 47 | // If we have a directory, it's not a file, so return false 48 | if (!$file->isFile()) { 49 | return false; 50 | } 51 | 52 | // If not a PHP file, skip 53 | if ($file->getBasename('.php') == $file->getBasename()) { 54 | return false; 55 | } 56 | 57 | return in_array($this->getExtension(), $this->ext); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Cygnite/Common/File/Upload/FileUploadInterface.php: -------------------------------------------------------------------------------- 1 | =5.4.0" 13 | }, 14 | "autoload": { 15 | "psr-0": { 16 | "Cygnite\\Common\\File": "" 17 | } 18 | }, 19 | "target-dir": "Cygnite\\Common\\File", 20 | "minimum-stability": "dev" 21 | } 22 | -------------------------------------------------------------------------------- /src/Cygnite/Common/Input/CookieManager/CookieInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Cygnite\Common\Input\CookieManager; 13 | 14 | interface CookieInterface 15 | { 16 | /** 17 | * @param $cookie 18 | * 19 | * @return mixed 20 | */ 21 | public function get($cookie); 22 | 23 | /** 24 | * @return mixed 25 | */ 26 | public function store(); 27 | 28 | /** 29 | * @param $cookie 30 | * 31 | * @return mixed 32 | */ 33 | public function destroy($cookie); 34 | 35 | /** 36 | * @param $cookie 37 | * 38 | * @return mixed 39 | */ 40 | public function has($cookie); 41 | } 42 | -------------------------------------------------------------------------------- /src/Cygnite/Common/Input/CookieManager/InvalidCookieException.php: -------------------------------------------------------------------------------- 1 | singleton('mailer', function () { 18 | $mailer = new \Cygnite\Common\Mail\Mailer(); 19 | $mailer->setSwiftMailer(new \Swift_Mailer($mailer->getTransportInstance())); 20 | 21 | return $mailer; 22 | }); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Cygnite/Common/Mail/MailerInterface.php: -------------------------------------------------------------------------------- 1 | storage = []; 17 | 18 | return $this; 19 | } 20 | 21 | /** 22 | * Check if offset exists. 23 | * 24 | * @param mixed $key 25 | * 26 | * @return bool true or false 27 | */ 28 | public function offsetExists($key) 29 | { 30 | return isset($this->storage[$key]); 31 | } 32 | 33 | /** 34 | * Get value if exists from storage. 35 | * 36 | * @param mixed $key 37 | * 38 | * @return mixed Can return all value types. 39 | */ 40 | public function &offsetGet($key) 41 | { 42 | if (!isset($this->storage[$key])) { 43 | $this->storage[$key] = null; 44 | } 45 | 46 | return $this->storage[$key]; 47 | } 48 | 49 | /** 50 | * Setting or pushing data into storage. 51 | * 52 | * @param mixed $key 53 | * @param mixed $value 54 | * 55 | * @return void 56 | */ 57 | public function offsetSet($key, $value) 58 | { 59 | if ($key === null) { 60 | array_push($this->storage, $value); 61 | 62 | return; 63 | } 64 | $this->storage[$key] = $value; 65 | } 66 | 67 | /** 68 | * Key to unset. 69 | * 70 | * @param mixed $key 71 | * 72 | * @return void 73 | */ 74 | public function offsetUnset($key) 75 | { 76 | unset($this->storage[$key]); 77 | } 78 | 79 | /** 80 | * Count elements of an object. 81 | * 82 | * @return int 83 | */ 84 | public function count() 85 | { 86 | return count($this->storage); 87 | } 88 | 89 | /** 90 | * Return the current element. 91 | * 92 | * @return mixed 93 | */ 94 | public function current() 95 | { 96 | return current($this->storage); 97 | } 98 | 99 | /** 100 | * Return the key of the current element. 101 | * 102 | * @return mixed 103 | */ 104 | public function key() 105 | { 106 | return key($this->storage); 107 | } 108 | 109 | /** 110 | * Move forward to next element. 111 | * 112 | * @return void 113 | */ 114 | public function next() 115 | { 116 | next($this->storage); 117 | } 118 | 119 | /** 120 | * Rewind the Iterator to the first element. 121 | * 122 | * @return void 123 | */ 124 | public function rewind() 125 | { 126 | reset($this->storage); 127 | } 128 | 129 | /** 130 | * Checks if current position is valid and return bool value. 131 | * 132 | * @return bool 133 | */ 134 | public function valid() 135 | { 136 | $key = key($this->storage); 137 | if ($key === false || $key === null) { 138 | return false; 139 | } 140 | 141 | return isset($this->storage[$key]); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/Cygnite/Common/SessionManager/Exceptions/SessionNotStartedException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Cygnite\Common\UrlManager; 13 | 14 | /** 15 | * Class Url. 16 | * 17 | * @author Sanjoy Dey 18 | */ 19 | class Url 20 | { 21 | public static $urlManager; 22 | 23 | /** 24 | * Url Constructor 25 | * @param Manager $urlManager 26 | */ 27 | public function __construct(Manager $urlManager) 28 | { 29 | static::$urlManager = $urlManager; 30 | } 31 | 32 | /** 33 | * Call url Manager methods if method doesn't exists 34 | * in current scope. 35 | * 36 | * @param $method 37 | * @param array $arguments 38 | * @return mixed 39 | * @throws \BadMethodCallException 40 | */ 41 | public static function __callStatic($method, $arguments = []) 42 | { 43 | if (method_exists(static::$urlManager, $method)) { 44 | return call_user_func_array([static::$urlManager, $method], $arguments); 45 | } 46 | 47 | throw new \BadMethodCallException("Undefined method Url::$method called."); 48 | } 49 | 50 | /** 51 | * @param $method 52 | * @param $arguments 53 | */ 54 | public function __call($method, $arguments) 55 | { 56 | if (method_exists(static::$urlManager, $method)) { 57 | return call_user_func_array([static::$urlManager, $method], $arguments); 58 | } 59 | 60 | throw new \BadMethodCallException("Undefined method Url::$method called."); 61 | } 62 | 63 | /** 64 | * Return url segment 65 | * 66 | * @param $param 67 | * @return mixed 68 | */ 69 | public static function segment($param = 1) 70 | { 71 | return static::$urlManager->getSegment($param); 72 | } 73 | 74 | /** 75 | * Redirect to given url 76 | * 77 | * @param string $uri 78 | * @param string $type 79 | * @param int $httpResponseCode 80 | */ 81 | public function redirectTo($uri = '/', $type = 'location', $httpResponseCode = 302) 82 | { 83 | static::$urlManager->redirectTo($uri, $type, $httpResponseCode); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Cygnite/Console/Command/ControllerGeneratorCommand.php: -------------------------------------------------------------------------------- 1 | table = $table; 78 | } 79 | 80 | /** 81 | * We will execute the controller command and generate classes. 82 | * 83 | * @throws \Exception 84 | * 85 | * @return mixed|void 86 | */ 87 | public function process() 88 | { 89 | // Your controller name 90 | $this->controller = Inflector::classify($this->argument('name')).'Controller'; 91 | 92 | // By default we will generate basic controller, if resource set then we will generate 93 | // REST-ful Resource controller 94 | $this->setControllerType(); 95 | 96 | try { 97 | $this->makeController(); 98 | } catch (\Exception $e) { 99 | throw $e; 100 | } 101 | 102 | $this->info('Controller '.$this->controller.' Generated Successfully By Cygnite Cli.'); 103 | } 104 | 105 | /** 106 | * Set controller type. 107 | */ 108 | private function setControllerType() 109 | { 110 | $this->isResourceController = ($this->option('resource')) ? true : false; 111 | } 112 | 113 | /** 114 | * Get controller type either normal controller or resource controller. 115 | * 116 | * @return null 117 | */ 118 | public function getControllerType() 119 | { 120 | return (isset($this->isResourceController)) ? $this->isResourceController : null; 121 | } 122 | 123 | /** 124 | * @return mixed 125 | */ 126 | private function makeController() 127 | { 128 | $controller = null; 129 | // Create Controller instance 130 | $controller = Controller::instance([], null, $this); 131 | $resourcePath = 'Resources'.DS.'Stubs'.DS; 132 | $controllerTemplateDir = 133 | dirname(dirname(__FILE__)).DS.'src'.DS.ucfirst('apps').DS.'Controllers'.DS.$resourcePath; 134 | 135 | $controller->setControllerTemplatePath($controllerTemplateDir); 136 | $controller->setApplicationDirectory(CYGNITE_BASE.DS.APPPATH); 137 | $controller->setControllerName($this->controller); 138 | 139 | return $controller->{__FUNCTION__}(); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/Cygnite/Console/Command/MigrationCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Console\Command; 12 | 13 | use Cygnite\Console\Generator\Migrator; 14 | use Cygnite\Database\Table\Table; 15 | use Symfony\Component\Console\Input\InputArgument; 16 | 17 | /** 18 | * Cygnite Migration Command. 19 | * 20 | * Migration Command class used to take care of your database migrations using Cygnite CLI. 21 | * 22 | * @author Sanjoy Dey 23 | */ 24 | class MigrationCommand extends Command 25 | { 26 | /** 27 | * Name of your console command. 28 | * 29 | * @var string 30 | */ 31 | protected $name = 'migrate'; 32 | 33 | /** 34 | * Description of your console command. 35 | * 36 | * @var string 37 | */ 38 | protected $description = 'Migrate Database By Cygnite CLI'; 39 | 40 | /** 41 | * Console command arguments. 42 | * 43 | * @var array 44 | */ 45 | protected $arguments = [ 46 | ['type', null, InputArgument::OPTIONAL, ''], 47 | ]; 48 | 49 | /** 50 | * @var \Cygnite\Database\Table\Table 51 | */ 52 | public $table; 53 | 54 | /** 55 | * @param Table $table 56 | * 57 | * @throws \InvalidArgumentException 58 | */ 59 | public function __construct(Table $table) 60 | { 61 | parent::__construct(); 62 | 63 | if (!$table instanceof Table) { 64 | throw new \InvalidArgumentException(sprintf('Constructor expects instance of Table, given %s.', $table)); 65 | } 66 | 67 | $this->table = $table; 68 | } 69 | 70 | /** 71 | * @return Table 72 | */ 73 | public function table() 74 | { 75 | return $this->table; 76 | } 77 | 78 | /** 79 | * Execute Command To Run Migration. 80 | * 81 | * @return mixed|void 82 | */ 83 | public function process() 84 | { 85 | // Migrate init - to create migration table 86 | $type = $this->argument('type'); 87 | 88 | $migration = Migrator::instance($this); 89 | $migration->getLatestMigration() 90 | ->setMigrationClassName(); 91 | 92 | if ($type == '' || $type == 'up') { 93 | $migration->updateMigration(); 94 | } else { 95 | $migration->updateMigration('down'); 96 | } 97 | 98 | $this->info('Migration Completed Successfully!'); 99 | } 100 | 101 | /** 102 | * Get Migration Path. 103 | * 104 | * @return string 105 | */ 106 | public function getMigrationPath() 107 | { 108 | return realpath(CYGNITE_BASE.DS.APPPATH.DS.'Resources'.DS.'Database'.DS.'Migrations').DS; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Cygnite/Console/Command/SeederCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Console\Command; 12 | 13 | use Apps\Resources\Database\Seeding\DatabaseTable; 14 | use Symfony\Component\Console\Input\InputArgument; 15 | 16 | /** 17 | * Cygnite Seeder Command. 18 | * 19 | * Migration Command class used to take care of your database migrations using Cygnite CLI. 20 | * 21 | * @author Sanjoy Dey 22 | */ 23 | class SeederCommand extends Command 24 | { 25 | /** 26 | * Name of your console command. 27 | * 28 | * @var string 29 | */ 30 | protected $name = 'database:seed'; 31 | 32 | /** 33 | * Description of your console command. 34 | * 35 | * @var string 36 | */ 37 | protected $description = 'Seed Database By Cygnite CLI'; 38 | 39 | /** 40 | * Console command arguments. 41 | * 42 | * @var array 43 | */ 44 | protected $arguments = [ 45 | ['name', InputArgument::OPTIONAL, null], 46 | ]; 47 | 48 | /** 49 | * @var \Apps\Resources\Database\Seeding\DatabaseTable 50 | */ 51 | private $seeder; 52 | 53 | /** 54 | * @param DatabaseTable $seeder 55 | * 56 | * @throws \InvalidArgumentException 57 | */ 58 | public function __construct(DatabaseTable $seeder) 59 | { 60 | parent::__construct(); 61 | 62 | if (!$seeder instanceof DatabaseTable) { 63 | throw new \InvalidArgumentException(sprintf('Constructor expects instance of DatabaseTable, givem %s.', $seeder)); 64 | } 65 | 66 | $this->seeder = $seeder; 67 | } 68 | 69 | /** 70 | * @return DatabaseTable 71 | */ 72 | public function seeder() 73 | { 74 | return $this->seeder; 75 | } 76 | 77 | /** 78 | * Execute the command. 79 | * 80 | * @return int|null|void 81 | */ 82 | public function process() 83 | { 84 | // Migrate init - to create migration table 85 | $name = $this->argument('name'); 86 | 87 | if (!is_null($name)) { 88 | if (string_has($name, ',')) { 89 | $this->seeder()->executeOnly($name); 90 | } else { 91 | $this->seeder()->executeOnly($name); 92 | } 93 | } 94 | 95 | $this->seeder()->run(); 96 | 97 | $this->info('Seeding Completed Successfully!'); 98 | } 99 | 100 | /** 101 | * Seeder directory path. 102 | * 103 | * @return string 104 | */ 105 | public function getSeederPath() 106 | { 107 | return realpath(CYGNITE_BASE.DS.APPPATH.DS.'Resources'.DS.'Database'.DS.'Seeding').DS; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Cygnite/Console/CraftApplication.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Console; 12 | 13 | use Cygnite\Console\Foundation\Application as ConsoleApplication; 14 | use Cygnite\Foundation\Application; 15 | 16 | /** 17 | * Class CraftApplication. 18 | */ 19 | class CraftApplication 20 | { 21 | private $version; 22 | 23 | protected $commands = []; 24 | 25 | protected $app; 26 | 27 | /** 28 | * @param $version 29 | */ 30 | public function __construct($app, $version) 31 | { 32 | $this->app = $app; 33 | $this->version = $version; 34 | } 35 | 36 | /** 37 | * Register your console commands here. 38 | * 39 | * @param $commands 40 | * 41 | * @return $this 42 | */ 43 | public function register($commands) 44 | { 45 | $this->commands = $commands; 46 | 47 | return $this; 48 | } 49 | 50 | /** 51 | * We will run Cygnite Console Application. 52 | */ 53 | public function execute() 54 | { 55 | //$console = new ConsoleApplication($this->app, $this->version); 56 | 57 | /* 58 | | We will also register Application Console commands 59 | | User can register multiple commands apart from core 60 | | commands and run on the fly 61 | */ 62 | $this->app->setCommand($this->commands) 63 | ->registerCommands() 64 | ->run(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Cygnite/Console/Foundation/ConsoleApplicationInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Console\Foundation; 12 | 13 | use Symfony\Component\Console\Command\Command as SymfonyCommand; 14 | 15 | /** 16 | * Cygnite Console Application. 17 | * 18 | * Class Application 19 | * 20 | * This class is the entry point of Console component. It is the 21 | * a middle ware of all your console commands. 22 | * Cygnite CLI powered by Symfony2 Console Component. 23 | * 24 | * @author Sanjoy Dey 25 | */ 26 | interface ConsoleApplicationInterface 27 | { 28 | /** 29 | * Add new command into stack. 30 | * 31 | * @param $command 32 | * 33 | * @return $this 34 | */ 35 | public function setCommand($command); 36 | 37 | /** 38 | * @param $command 39 | * 40 | * @return \Symfony\Component\Console\Command\Command|void 41 | */ 42 | public function add(SymfonyCommand $command); 43 | 44 | /* 45 | * We will register all commands into Console 46 | * 47 | * @return true 48 | */ 49 | //public function execute($input, $output); 50 | } 51 | -------------------------------------------------------------------------------- /src/Cygnite/Console/Generator/Form.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Console\Generator; 12 | 13 | use Cygnite\Helpers\Inflector; 14 | 15 | /** 16 | * Cygnite Model Generator. 17 | * 18 | * This class is used to generate your Form class using cygnite console 19 | * 20 | * @author Sanjoy Dey 21 | */ 22 | class Form 23 | { 24 | private $formCommand; 25 | 26 | private $formTemplatePath; 27 | 28 | /* 29 | * Since constructor is private you cannot create object 30 | * for this class directly 31 | * 32 | * @access public 33 | * @param $columns array of columns 34 | * @return void 35 | */ 36 | public function __construct($controller, $formCommand = null) 37 | { 38 | $this->controllerInstance = $controller; 39 | $this->formCommand = $formCommand; 40 | } 41 | 42 | /** 43 | * Set form template path. 44 | * 45 | * @param $path 46 | */ 47 | public function setFormTemplatePath($path) 48 | { 49 | $this->formTemplatePath = $path; 50 | } 51 | 52 | /** 53 | * Get form Template path. 54 | * 55 | * @return null 56 | */ 57 | public function getFormTemplatePath() 58 | { 59 | return (isset($this->formTemplatePath)) ? 60 | $this->formTemplatePath : 61 | null; 62 | } 63 | 64 | /** 65 | * Form template name. 66 | * 67 | * @return string 68 | */ 69 | private function formTemplateName() 70 | { 71 | return 'Form'.EXT; 72 | } 73 | 74 | /** 75 | * Generate Form. 76 | */ 77 | public function generate() 78 | { 79 | $filePath = ''; 80 | $formName = Inflector::classify($this->formCommand->tableName); 81 | 82 | if (file_exists($this->getFormTemplatePath().'Form'.EXT)) { 83 | //We will generate Form Component 84 | $formContent = file_get_contents($this->getFormTemplatePath().'Form'.EXT); 85 | } else { 86 | die("Form template doesn't exists in ".$this->getFormTemplatePath().'Form'.EXT.' directory.'); 87 | } 88 | 89 | $this->controllerInstance->isFormGenerator = true; 90 | $this->controllerInstance->updateTemplate(); 91 | $this->controllerInstance->setControllerName($formName); 92 | $this->controllerInstance->setApplicationDirectory(realpath(CYGNITE_BASE.DS.APPPATH)); 93 | $formContent = str_replace('%controllerName%', $formName, $formContent); 94 | $formContent = str_replace('{%formElements%}', $this->controllerInstance->getForm().PHP_EOL, $formContent); 95 | 96 | $this->controllerInstance->generateFormComponent($formContent); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Controllers/Resources/Stubs/controller.tpl.stub: -------------------------------------------------------------------------------- 1 | setTableName('{%table_name%}'); 23 | // If you don't specify the connection name, system will use default connection 24 | //$schema->on('{%database%}'); 25 | 26 | $schema->create([ 27 | ['column'=> 'id', 'type' => 'int', 'length' => 11, 28 | 'increment' => true, 'key' => 'primary'], 29 | 30 | /*..Add columns to your table schema .*/ 31 | 32 | ['column'=> 'created_at', 'type' => 'datetime'], 33 | ['column'=> 'updated_at', 'type' => 'datetime'], 34 | 35 | ], 'InnoDB', 'latin1'); 36 | }); 37 | 38 | } 39 | 40 | /** 41 | * Revert back your migrations. 42 | * 43 | * @return void 44 | */ 45 | public function down() 46 | { 47 | //Roll back your changes done by up method. 48 | Schema::make('{%table_name%}', function ($schema) 49 | { 50 | $schema->drop(); 51 | }); 52 | } 53 | }// End of the Migration 54 | -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Form/Form.php: -------------------------------------------------------------------------------- 1 | 2 | namespace {%Apps%}\Form; 3 | 4 | use Cygnite\FormBuilder\Form; 5 | use Cygnite\Common\UrlManager\Url; 6 | use Cygnite\Validation\ValidatorInterface; 7 | 8 | /** 9 | * Sample Form using Cygnite Form Builder 10 | * This file generated by Cygnite CLI Generator. 11 | * You may alter the code to fit your needs 12 | */ 13 | 14 | class %controllerName%Form extends Form 15 | { 16 | //set entity object 17 | protected $entity; 18 | 19 | protected $validator; 20 | 21 | protected $errors = []; 22 | 23 | private $segment; 24 | 25 | // We will set action url 26 | protected $action = 'add'; 27 | 28 | public function __construct($object = null, $segment = null) 29 | { 30 | // your model object 31 | $this->model = $object; 32 | $this->segment = $segment; 33 | } 34 | 35 | /** 36 | * Set form action and request to form builder. 37 | * 38 | * @param $action 39 | * @param $request 40 | * @return $this 41 | */ 42 | public function handleRequest($action, $request) 43 | { 44 | $this->action = $action; 45 | $this->setRequest($request); 46 | 47 | return $this; 48 | } 49 | 50 | /** 51 | * Set validator used for displaying validation 52 | * errors below each form elements 53 | * 54 | * @param ValidatorInterface $validator 55 | * @return $this 56 | */ 57 | public function setValidator(ValidatorInterface $validator) 58 | { 59 | $this->validator = $validator; 60 | 61 | return $this; 62 | } 63 | 64 | /** 65 | * Get validator instance if set. 66 | * 67 | * @return mixed 68 | */ 69 | public function getValidator() 70 | { 71 | return $this->validator; 72 | } 73 | 74 | /** 75 | * Set validator object. If object is set you can customize the 76 | * validator error messages into the form elements. 77 | * 78 | * @return void 79 | */ 80 | public function setValidationErrors($errors) 81 | { 82 | $this->errors = $errors; 83 | 84 | return $this; 85 | } 86 | 87 | /** 88 | * Get form validation errors. 89 | * 90 | * @return mixed 91 | */ 92 | public function getValidationErrors() 93 | { 94 | return ($this->validator instanceof ValidatorInterface && !empty($this->validator->getErrors())) 95 | ? $this->validator->getErrors() 96 | : $this->errors; 97 | } 98 | 99 | /** 100 | * Build form and return object 101 | * @return %controllerName%Form 102 | */ 103 | public function buildForm() 104 | { 105 | $id = (isset($this->model->id)) ? $this->model->id : ''; 106 | 107 | // Below code is to display validation errors below the input box 108 | if (is_object($this->validator) && $this->validator instanceof ValidatorInterface) { 109 | //$this->displayValidationError('inline', false); 110 | $this->displayValidationError('highlightElement', false); 111 | // Set your custom errors 112 | //$this->validator->setCustomError('column.error', 'Your Custom Error Message'); 113 | } 114 | 115 | {%formElements%} 116 | 117 | return $this; 118 | } 119 | 120 | /** 121 | * Render form 122 | * @return type 123 | */ 124 | public function render() 125 | { 126 | return $this->buildForm()->getForm(); 127 | } 128 | } -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Models/Model.php: -------------------------------------------------------------------------------- 1 | namespace {%Apps%}\Models; 2 | 3 | use Cygnite\Common\UrlManager\Url; 4 | use Cygnite\Database\Cyrus\ActiveRecord; 5 | use Cygnite\Validation\ValidationTrait; 6 | 7 | /** 8 | * This file is generated by Craft Console's Crud generator 9 | */ 10 | 11 | class %StaticModelName% extends ActiveRecord 12 | { 13 | use ValidationTrait; 14 | 15 | //your database connection name 16 | protected $database = '%databaseName%'; 17 | 18 | // your table name here 19 | //protected $tableName = '%modelName%'; 20 | 21 | protected $primaryKey = '{%primaryKey%}'; 22 | 23 | //public $perPage = 5; // used to create pagination links 24 | 25 | /** 26 | * Set Validation rules for Form 27 | * 28 | * @param $input 29 | * @return mixed 30 | */ 31 | public $rules = [ 32 | {%rules%} 33 | ]; 34 | 35 | public function __construct() 36 | { 37 | parent::__construct(); 38 | } 39 | 40 | /* 41 | // Used to set pagination limit 42 | public function pageLimit() 43 | { 44 | return Url::segment(3); 45 | } 46 | */ 47 | }// End of the %StaticModelName% Model -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/controller/Php/create.html.stub: -------------------------------------------------------------------------------- 1 |
2 | asset()->anchor('#controllerName#', 'Back', ['class' => 'btn btn-default btn-small btn-inverse']); ?> 3 |
4 | 5 |
6 | $message) { ?> 12 | 13 |

14 | 18 |
19 | 20 |
21 | 22 |
-------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/controller/Php/index.html.stub: -------------------------------------------------------------------------------- 1 | hasFlash('success')) { 5 | echo $view->getFlash('success'); 6 | } elseif ($view->hasError()) { 7 | echo $view->getFlash('error'); 8 | } 9 | ?> 10 | 18 | 19 | 20 | 21 | 22 | 23 | {#thColumns#} 24 | 25 | 26 | 27 | 28 | 0) { 30 | //$i = 1; 31 | if (Url::segment(2) == '' || Url::segment(3) == '' || Url::segment(3) == 1 ) { 32 | $i =1; 33 | } else { 34 | $i = (Url::segment(3) - 1) * $records[0]->perPage + 1; 35 | } 36 | 37 | $rowType = null; 38 | foreach ($records as $key => $row) { 39 | 40 | $rowType = ($i % 2 == 0) ? 'even' : 'odd'; 41 | ?> 42 | 43 | 44 | {#tdColumns#} 45 | 53 | 54 | 58 | 59 | 60 |
Sl No.Action
46 | asset()->anchor('#controllerName#/show/' . $row->{%primaryKey%}, 'View', ['class' => 'btn btn btn-info btn-xs']); 48 | echo $view->asset()->anchor('#controllerName#/edit/' . $row->{%primaryKey%}, 'Edit', ['class' => 'btn btn-default btn-xs']); 49 | echo $view->asset()->anchor('#controllerName#/delete/' . $row->{%primaryKey%}, 'Delete', ['class' => 'btn btn-danger btn-xs' ]); 50 | ?> 51 | 52 |
61 | 62 | 63 | -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/controller/Php/show.html.stub: -------------------------------------------------------------------------------- 1 |
2 | asset()->anchor('#controllerName#', 'Back', ['class' => 'btn btn-default btn-small btn-inverse']); ?> 3 |
4 | 5 |
6 |

Showing #controllerName# #id; ?>

7 | 8 | {#recordDivElements#} 9 | 10 |
-------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/controller/Php/update.html.stub: -------------------------------------------------------------------------------- 1 |
2 | asset()->anchor('#controllerName#', 'Back', ['class' => 'btn btn-default btn-small btn-inverse']); ?> 3 |
4 | 5 |
6 | $message) { ?> 12 | 13 |

14 | 18 |
19 | 20 |
21 | 22 |
-------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/controller/create.html.stub: -------------------------------------------------------------------------------- 1 | {% extends 'layouts/main/base.html.twig' %} 2 | 3 | {% block title %} 4 | {{ title }} 5 | {% endblock %} 6 | 7 | {% block content %} 8 | 9 | {# dump(#controllerName#) #} 10 | 11 |
12 | {{ link('#controllerName#/', 'Back',{'class': 'btn btn-default btn-small btn-inverse'}) | raw }} 13 |
14 | 15 |
16 | {% for key, message in validation_errors %} 17 |

{{ message | raw }}

18 | {% endfor %} 19 |
20 | 21 |
22 | {{ form | raw }} 23 |
24 | 25 | 26 | {% endblock %} 27 | 28 | {% block footer %} 29 | 30 | {% endblock %} -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/controller/index.html.stub: -------------------------------------------------------------------------------- 1 | {% extends 'layouts/main/base.html.twig' %} 2 | 3 | {% block title %} 4 | {{ title }} 5 | {% endblock %} 6 | 7 | {% block content %} 8 | 9 | {# dump(records) #} 10 | 11 | {{ flashMessage | raw }} 12 | 13 | 21 | 22 | 23 | 24 | 25 | 26 | {#thColumns#} 27 | 28 | 29 | 30 | 31 | 32 | {% if records|length > 0 %} 33 | 34 | {% for key, row in records %} 35 | 36 | {% if loop.index % 2 == 0 %} 37 | {% set rowType = 'even' %} 38 | {% else %} 39 | {% set rowType = 'odd' %} 40 | {% endif %} 41 | 42 | 43 | 44 | 45 | {#tdColumns#} 46 | 47 | 54 | 55 | 56 | {% endfor %} 57 | {% else %} 58 | No records found ! 59 | {% endif %} 60 | 61 | 62 | 63 |
Sl No.Action
{{ loop.index }} 48 | 49 | {{ link('#controllerName#.show.' ~ row.{%primaryKey%} , 'View' , {'class': 'btn btn btn-info btn-xs'}) | raw }} 50 | {{ link('#controllerName#.edit.' ~ row.{%primaryKey%}, 'Edit' , {'class':'btn btn-default btn-xs'}) | raw }} 51 | {{ link('#controllerName#.delete.' ~ row.{%primaryKey%} , 'Delete' , {'class':'btn btn-danger btn-xs'}) | raw }} 52 | 53 |
64 | 65 | 66 | 67 | 68 | {% endblock %} 69 | 70 | {% block footer %} 71 | 72 | {% endblock %} -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/controller/show.html.stub: -------------------------------------------------------------------------------- 1 | {% extends 'layouts/main/base.html.twig' %} 2 | 3 | {% block title %} 4 | {{ title }} 5 | {% endblock %} 6 | 7 | {% block content %} 8 | 9 |
10 | {{ link('#controllerName#/', 'Back',{'class': 'btn btn-default btn-small btn-inverse'}) | raw }} 11 |
12 | 13 |
14 |

Showing #controllerName# #{{ record.id }}

15 | 16 | {#recordDivElements#} 17 | 18 |
19 | 20 | {% endblock %} 21 | 22 | {% block footer %} 23 | 24 | {% endblock %} 25 | -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/controller/update.html.stub: -------------------------------------------------------------------------------- 1 | {% extends 'layouts/main/base.html.twig' %} 2 | 3 | {% block title %} 4 | {{ title }} 5 | {% endblock %} 6 | 7 | {% block content %} 8 | 9 | {# dump(#controllerName#) #} 10 | 11 |
12 | {{ link('#controllerName#/', 'Back',{'class': 'btn btn-default btn-small btn-inverse'}) | raw }} 13 |
14 | 15 |
16 | {% for key, message in validation_errors %} 17 |

{{ message | raw }}

18 | {% endfor %} 19 |
20 | 21 |
22 | {{ form | raw }} 23 |
24 | 25 | 26 | {% endblock %} 27 | 28 | {% block footer %} 29 | 30 | {% endblock %} -------------------------------------------------------------------------------- /src/Cygnite/Console/src/Apps/Views/layouts/base.view.stub: -------------------------------------------------------------------------------- 1 | createAssetCollection('\Apps\Views\Base\Assets\BaseAssetCollection'); 3 | ?> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <?php echo $title; ?> 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | where('header')->dump('style');// Header Style block ?> 22 | 26 | 27 | 30 | 31 | 32 | 33 | 34 |
35 | 36 | 37 | widget()->make('layouts:widgets:navbar'); ?> 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 | 47 | 48 |
49 | 50 | where('footer')->dump('style'); 53 | //Script block. Scripts will render here 54 | $asset->where('footer')->dump('script'); 55 | ?> 56 | 57 | 62 | 63 | -------------------------------------------------------------------------------- /src/Cygnite/Container/ContainerAwareInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Container; 11 | 12 | /** 13 | * Describes the basic interface of a container. 14 | * 15 | * Interface ContainerAwareInterface 16 | * 17 | * @author Sanjoy Dey 18 | */ 19 | interface ContainerAwareInterface 20 | { 21 | /** 22 | * Set value to container. 23 | * 24 | * @param $key 25 | * @param $instance 26 | * @return ContainerAwareInterface 27 | */ 28 | public function set($key, $instance) : ContainerAwareInterface; 29 | 30 | /** 31 | * Returns an entry of the container by its name. 32 | * 33 | * @param string $name Name of the entry to look for. 34 | * 35 | * @throws NotFoundException No entry was found for this name. 36 | * 37 | * @return mixed Entry. Can be anything: object, value, ... 38 | */ 39 | public function get($name); 40 | 41 | /** 42 | * Check if the container can return an entry for the given name. 43 | * 44 | * @param string $name Name of the entry to look for. 45 | * @param $name 46 | * 47 | * @return bool 48 | */ 49 | public function has($name); 50 | 51 | /** 52 | * Resolve all dependencies of your class and return instance of 53 | * your class. 54 | * 55 | * @param string $class 56 | * @param array $arguments 57 | * @internal param $ |string $class 58 | * 59 | * @return mixed 60 | */ 61 | public function make(string $class, array $arguments = []); 62 | 63 | /** 64 | * Resolve the class. We will create and return instance if already 65 | * not exists. 66 | * 67 | * @param $class 68 | * @param array $arguments 69 | * 70 | * @return object 71 | */ 72 | public function resolve($class, $arguments = []); 73 | 74 | /** 75 | * Get singleton instance of your class. 76 | * 77 | * @param $key 78 | * @param null $callback 79 | * 80 | * @return mixed 81 | */ 82 | public function singleton(string $name, callable $callback = null); 83 | 84 | /** 85 | * Reference 86 | * http://fabien.potencier.org/article/17/on-php-5-3-lambda-functions-and-closures. 87 | * 88 | * @param Closure $callable 89 | * 90 | * @internal param $callable 91 | * 92 | * @return type 93 | */ 94 | public function share(\Closure $callable); 95 | 96 | /** 97 | * @param string $key 98 | * @param callable $callable 99 | * 100 | * @return mixed 101 | */ 102 | public function extend(string $key, \Closure $callable); 103 | 104 | /** 105 | * Create new instance. 106 | * 107 | * @param $class 108 | * @param array $arguments 109 | * @throws Exceptions\ContainerException 110 | * @return mixed 111 | */ 112 | public function makeInstance(string $class, $arguments = []); 113 | } 114 | -------------------------------------------------------------------------------- /src/Cygnite/Container/Exceptions/ContainerException.php: -------------------------------------------------------------------------------- 1 | getClass()->name; 22 | 23 | return [$resolveClass, new \ReflectionClass($resolveClass)]; 24 | } 25 | 26 | /** 27 | * @param $dependency 28 | * 29 | * @return mixed 30 | */ 31 | public function isOptionalArgs($dependency) 32 | { 33 | /* 34 | | Check parameters are optional or not 35 | | if it is optional we will set the default value 36 | */ 37 | if ($dependency->isOptional()) { 38 | return $dependency->getDefaultValue(); 39 | } 40 | } 41 | 42 | /** 43 | * We will inject interface implementation. 44 | * 45 | * @param $reflectionParam 46 | * 47 | * @return array 48 | */ 49 | public function interfaceInjection($reflectionParam) 50 | { 51 | $constructorArgs = null; 52 | /* 53 | | Check if constructor dependency is Interface or not. 54 | | if interface we will check definition for the interface 55 | | and inject into controller constructor 56 | */ 57 | if (!$reflectionParam->IsInstantiable() && $reflectionParam->isInterface()) { 58 | $aliases = $this->definition['definition.config']['register.alias']; 59 | $interface = Inflector::getClassName($reflectionParam->getName()); 60 | 61 | if (array_key_exists($interface, $aliases)) { 62 | $constructorArgs = $this->container->makeInstance($aliases[$interface]); 63 | } 64 | } 65 | 66 | return $constructorArgs; 67 | } 68 | 69 | /** 70 | * @param $dependency 71 | * @param $arguments 72 | * 73 | * @return mixed 74 | */ 75 | public function checkIfConstructorHasDefaultArgs($dependency, $arguments) 76 | { 77 | $parameters = $dependency->getDefaultValue(); 78 | 79 | if (empty($parameters) && !empty($arguments)) { 80 | $parameters = $arguments; 81 | } 82 | 83 | return $parameters; 84 | } 85 | 86 | /** 87 | * Set definition configuration. 88 | * 89 | * @param array $definition 90 | */ 91 | public function setDefinitionConfig(array $definition = []) 92 | { 93 | $this->definition = ['definition.config' => $definition]; 94 | } 95 | 96 | public function setContainer($container) 97 | { 98 | $this->container = $container; 99 | 100 | return $this; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Cygnite/Container/Service/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | container = $container; 23 | } 24 | 25 | /** 26 | * Register the service provider. 27 | * 28 | * @param \Cygnite\Container\ContainerAwareInterface $container 29 | * 30 | * @return void 31 | */ 32 | abstract public function register(ContainerAwareInterface $container); 33 | } 34 | -------------------------------------------------------------------------------- /src/Cygnite/Container/index.php: -------------------------------------------------------------------------------- 1 | [ 7 | 'HomeController' => [ 8 | 'api' => \Apps\Resources\Extensions\Api::class, 9 | ], 10 | ], 11 | 'register.alias' => [ 12 | 'CustomInterface' => Apps\Resources\Extensions\Custom::class 13 | ] 14 | ]; 15 | $container->setAppNamespace('\\Apps\\Controllers\\\''); 16 | $container->setDefinitions($definitions); 17 | 18 | //$obj = new Service; 19 | 20 | $container['a'] = 'Store A'; 21 | $container['b'] = 'Store B'; 22 | $container->c = 'Store C'; 23 | // $container->d = function ($name) { 24 | // return "Hello World!"; 25 | // }; 26 | // 27 | //var_dump($container['a']());exit; 28 | $container['d'] = function ($c) use ($service) { 29 | return new Tes($c['a']); 30 | }; 31 | 32 | //var_dump($container['d']());exit; 33 | //$container['e'] = 34 | $container['d'] = $container->extend('d', function ($tes, $c) { 35 | $tes->name = 'Sanjay'; 36 | 37 | return $tes; 38 | }); 39 | var_dump($container['d']()); 40 | 41 | echo '
';
42 | var_dump($container['d']);
43 | //var_dump($container['e']);
44 | 
45 | $obj['dynamicFields'] = function ($c) {
46 |     return new Users();
47 | };
48 | 
49 | //var_dump($obj['dynamicFields']);
50 | 
51 | $container['dynamicFields'] = $container->extend('dynamicFields', function ($user, $c) {
52 |     $user->form = 'User Form';
53 |     $user->setUser($c['a']);
54 | 
55 |     return $user;
56 | });
57 | 
58 | $container['dynamicFields']()->start('Ami');
59 | var_dump($container['dynamicFields']());
60 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Configure.php:
--------------------------------------------------------------------------------
 1 | default) ? 'db' : $this->default;
38 | 
39 |         if (!is_null($defaultConnection)) {
40 |             $this->setDefaultConnection($config[$defaultConnection]);
41 |         }
42 |     }
43 | 
44 |     public static function getDatabaseConfiguration()
45 |     {
46 |         return self::$config;
47 |     }
48 | 
49 |     /**
50 |      * @param $value
51 |      */
52 |     private function setDefaultConnection($value)
53 |     {
54 |         self::$defaultConnection = $value;
55 |     }
56 | 
57 |     /**
58 |      * @return mixed
59 |      */
60 |     public static function getDefault()
61 |     {
62 |         return isset(self::$defaultConnection) ? self::$defaultConnection : null;
63 |     }
64 | }
65 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Connections/ConnectionFactory.php:
--------------------------------------------------------------------------------
 1 | 
 7 |  *
 8 |  * For the full copyright and license information, please view the LICENSE
 9 |  * file that was distributed with this source code.
10 |  */
11 | 
12 | namespace Cygnite\Database\Connections;
13 | 
14 | /**
15 |  * Class ConnectionFactory.
16 |  */
17 | class ConnectionFactory
18 | {
19 |     /**
20 |      * Defined various database drivers.
21 |      *
22 |      * @var array
23 |      */
24 |     public $drivers = [
25 |         'MySql'  => 'Cygnite\Database\Connections\MySql',
26 |         'Oracle' => 'Cygnite\Database\Connections\Oracle',
27 |         'MsSql'  => 'Cygnite\Database\Connections\MsSql',
28 |     ];
29 | 
30 |     protected $config = [];
31 | 
32 |     /**
33 |      * We will set configuration for database connections.
34 |      *
35 |      * @param $config
36 |      *
37 |      * @return $this
38 |      */
39 |     public function setConfig($config)
40 |     {
41 |         $this->config = $config;
42 | 
43 |         return $this;
44 |     }
45 | 
46 |     /**
47 |      * @return array
48 |      */
49 |     public function getConfig()
50 |     {
51 |         return $this->config;
52 |     }
53 | 
54 |     /**
55 |      * @param $class
56 |      *
57 |      * @return mixed
58 |      */
59 |     public function make($class)
60 |     {
61 |         $class = $this->drivers[$class];
62 | 
63 |         return (new $class($this->getConfig()))->create();
64 |     }
65 | }
66 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Connections/Connector.php:
--------------------------------------------------------------------------------
  1 | 
  6 |  *
  7 |  * For the full copyright and license information, please view the LICENSE
  8 |  * file that was distributed with this source code.
  9 |  */
 10 | 
 11 | namespace Cygnite\Database\Connections;
 12 | 
 13 | use PDO;
 14 | 
 15 | /**
 16 |  * Class Connector.
 17 |  */
 18 | class Connector
 19 | {
 20 |     /**
 21 |      * @var array
 22 |      */
 23 |     public $options = [
 24 |         PDO::ATTR_ERRMODE              => PDO::ERRMODE_EXCEPTION,
 25 |         PDO::ATTR_CASE                 => PDO::CASE_NATURAL,
 26 |         PDO::ATTR_ORACLE_NULLS         => PDO::NULL_NATURAL,
 27 |         PDO::ATTR_PERSISTENT           => true,
 28 |         PDO::ATTR_STRINGIFY_FETCHES    => false,
 29 |         PDO::ATTR_EMULATE_PREPARES     => false,
 30 |     ];
 31 | 
 32 |     protected $config;
 33 | 
 34 |     /**
 35 |      * @param array $config
 36 |      */
 37 |     public function __construct(array $config)
 38 |     {
 39 |         $this->config = $config;
 40 |     }
 41 | 
 42 |      /**
 43 |      * Return PDO connection object. If connection lost will try again to connect.
 44 |      *
 45 |      * @return PDO
 46 |      */
 47 |     public function create()
 48 |     {
 49 |         $pdo = null;
 50 |         try {
 51 |             $pdo = $this->connect();
 52 |         } catch (\Exception $e) {
 53 |             $pdo = null;
 54 |             if ($this->isLostConnection($e)) {
 55 |                 $pdo = $this->reconnect();
 56 |             }
 57 | 
 58 |             throw new \LogicException('Connection lost and no reconnector available.');
 59 |         }
 60 | 
 61 |         return $pdo;
 62 |     }
 63 | 
 64 |     /**
 65 |      * Recreate connection object.
 66 |      *
 67 |      * @return PDO
 68 |      */
 69 |     public function reconnect()
 70 |     {
 71 |         return $this->connect();
 72 |     }
 73 | 
 74 |     /**
 75 |      * Create connection
 76 |      * @return PDO
 77 |      */
 78 |     public function connect()
 79 |     {
 80 |         return new PDO($this->getDsn(), $this->config['username'], $this->config['password'], $this->getOptions());
 81 |     }
 82 | 
 83 |     /**
 84 |      * Get DSN string.
 85 |      *
 86 |      * @return string
 87 |      */
 88 |     public function getDsn()
 89 |     {
 90 |         return ($this->config['port'] !== '')
 91 |             ? "mysql:host={$this->config['hostname']};port={$this->config['port']};dbname={$this->config['database']}"
 92 |             : "mysql:host={$this->config['hostname']};dbname={$this->config['database']}";
 93 |     }
 94 | 
 95 |     /**
 96 |      * @param $options
 97 |      *
 98 |      * @return $this
 99 |      */
100 |     public function setOptions($options)
101 |     {
102 |         $this->options = $options;
103 | 
104 |         return $this;
105 |     }
106 | 
107 |     /**
108 |      * @return array
109 |      */
110 |     public function getOptions()
111 |     {
112 |         return $this->options;
113 |     }
114 |     
115 |     /**
116 |      * Find if exception caused by lost connection.
117 |      *
118 |      * @param \Exception $e
119 |      * @return bool
120 |      */
121 |     protected function isLostConnection(\Exception $e)
122 |     {
123 |         return string_has(strtolower($e->getMessage()), [
124 |             'server has gone away',
125 |             'Lost connection',
126 |             'is dead or not enabled',
127 |             'Resource deadlock avoided',
128 |             'Error while sending',
129 |             'no connection to the server',
130 |             'decryption failed or bad record mac',
131 |             'Error writing data to the connection',
132 |             'Deadlock found when trying to get lock',
133 |             'server closed the connection unexpectedly',
134 |             'SSL connection has been closed unexpectedly',
135 |             'Connection lost and no reconnector available.',
136 |         ]);
137 |     }
138 | }
139 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Connections/MySql.php:
--------------------------------------------------------------------------------
 1 | 
 6 |  *
 7 |  * For the full copyright and license information, please view the LICENSE
 8 |  * file that was distributed with this source code.
 9 |  */
10 | 
11 | namespace Cygnite\Database\Connections;
12 | 
13 | use PDO;
14 | 
15 | class MySql extends Connector
16 | {
17 |     /**
18 |      * @param array $config
19 |      */
20 |     public function __construct(array $config)
21 |     {
22 |         parent::__construct($config);
23 |     }
24 | 
25 |     /**
26 |      * @return PDO
27 |      */
28 |     public function create()
29 |     {
30 |         $connection = parent::create();
31 | 
32 |         if (isset($this->config['unix_socket'])) {
33 |             $connection->exec("use `{$this->config['database']}`;");
34 |         }
35 | 
36 |         $this->setNamesAndCollation($connection);
37 | 
38 | 
39 |         return $connection;
40 |     }
41 | 
42 |     /**
43 |      * @param $connection
44 |      */
45 |     private function setNamesAndCollation($connection)
46 |     {
47 |         $names = "set names '".$this->config['charset']."'".
48 |             (!is_null($this->config['collation']) ? " collate '".$this->config['collation']."'" : '');
49 | 
50 |         $connection->prepare($names)->execute();
51 |     }
52 | }
53 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Connections/Oracle.php:
--------------------------------------------------------------------------------
1 | 
  6 |  *
  7 |  * For the full copyright and license information, please view the LICENSE
  8 |  * file that was distributed with this source code.
  9 |  */
 10 | namespace Cygnite\Database\Cyrus;
 11 | 
 12 | /**
 13 |  * Database ActiveRecord.
 14 |  *
 15 |  * @author Sanjoy Dey 
 16 |  */
 17 | interface ActiveRecordInterface extends \ArrayAccess
 18 | {
 19 |     /**
 20 |      * @param $argument
 21 |      *
 22 |      * @return mixed
 23 |      */
 24 |     public static function find($argument);
 25 | 
 26 |     /**
 27 |      * @return mixed
 28 |      */
 29 |     public static function first();
 30 | 
 31 |     /**
 32 |      * @param array $arguments
 33 |      *
 34 |      * @return mixed
 35 |      */
 36 |     public static function all($arguments = []);
 37 | 
 38 |     /**
 39 |      * @return mixed
 40 |      */
 41 |     public static function last();
 42 | 
 43 |     /**
 44 |      * @param $query
 45 |      *
 46 |      * @return mixed
 47 |      */
 48 |     public static function sql($query);
 49 | 
 50 |     /**
 51 |      * @return mixed
 52 |      */
 53 |     public static function createLinks();
 54 | 
 55 |     /**
 56 |      * @return mixed
 57 |      */
 58 |     public static function lastQuery();
 59 | 
 60 |     /*
 61 |     * Set your table columns dynamically
 62 |     * @access public
 63 |     * @param $key hold your table columns
 64 |     * @param $value hold your table column values
 65 |     * @return void
 66 |     *
 67 |     */
 68 |     public function getModelEvents();
 69 | 
 70 |     /**
 71 |      * get table name.
 72 |      *
 73 |      * @return null
 74 |      */
 75 |     public function getTableName();
 76 | 
 77 |     /**
 78 |      * @param array $attributes
 79 |      *
 80 |      * @return mixed
 81 |      */
 82 |     public function setAttributes($attributes = []);
 83 | 
 84 |     /**
 85 |      * Get attributes array.
 86 |      *
 87 |      * @return array|null
 88 |      */
 89 |     public function getAttributes();
 90 | 
 91 |     /**
 92 |      * Save model attributes into database.
 93 |      *
 94 |      * @param array $attributes
 95 |      *
 96 |      * @return mixed
 97 |      */
 98 |     public function save($attributes = []);
 99 | 
100 |     /**
101 |      * @param      $arguments
102 |      * @param bool $multiple
103 |      *
104 |      * @return mixed
105 |      */
106 |     public function trash($arguments, $multiple = false);
107 | 
108 |     /** Check id is null or not.
109 |      *  If null return true else false.
110 |      *
111 |      * @return bool
112 |      */
113 |     public function isNew();
114 | 
115 |     /**
116 |      * Get the primary key of table.
117 |      *
118 |      * @return null|string
119 |      */
120 |     public function getKeyName();
121 | 
122 |     /**
123 |      * @param $arguments
124 |      *
125 |      * @return mixed
126 |      */
127 |     public function findByPK($arguments);
128 | 
129 |     /**
130 |      * @param $key
131 |      *
132 |      * @return mixed
133 |      */
134 |     public function getId($key);
135 | 
136 |     /**
137 |      * Set the pagination limit.
138 |      *
139 |      * @param null $number
140 |      */
141 |     public function setPageLimit($number = null);
142 | 
143 |     /**
144 |      * @param $arguments
145 |      *
146 |      * @return mixed
147 |      */
148 |     public function joinWith($arguments);
149 | 
150 |     /**
151 |      * We will get Fluent Query Object.
152 |      *
153 |      * @return Query
154 |      */
155 |     public function queryBuilder();
156 | 
157 |     /**
158 |      * Use Connection to build fluent queries against any table.
159 |      *
160 |      * @param $database
161 |      *
162 |      * @return mixed
163 |      */
164 |     public static function db($database);
165 | 
166 |     /**
167 |      * Get Database Connection.
168 |      *
169 |      * @param $database
170 |      *
171 |      * @return mixed
172 |      */
173 |     public static function connection($database);
174 | 
175 |     /**
176 |      * @return mixed
177 |      */
178 |     public function getPrimaryKey();
179 | }
180 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Cyrus/Relations/BelongsTo.php:
--------------------------------------------------------------------------------
1 | foreignClass
24 |      * @param null $mapClass
25 |      * @param null $localId
26 |      * @param null $foreignId
27 |      * @param null $firstKey
28 |      * @param null $secondKey
29 |      */
30 |     public function __construct(
31 |         $ar,
32 |         $foreignClass,
33 |         $mapClass = null,
34 |         $localId = null,
35 |         $foreignId = null,
36 |         $firstKey = null,
37 |         $secondKey = null
38 |     ) {
39 |         $this->baseClass = get_class($ar);
40 |         $this->foreignClass = $foreignClass;
41 |         $this->mapClass = $mapClass;
42 |         $this->localId = $localId;
43 |         $this->foreignId = $foreignId;
44 |         $this->firstKey = $firstKey;
45 |         $this->secondKey = $secondKey;
46 |     }
47 | 
48 |     public function match()
49 |     {
50 |         if (is_null($this->mapClass)) {
51 |             $this->mapClass = $this->getJoinClassName($this->baseClass, $this->foreignClass);
52 |         }
53 | 
54 |         // Get table names from each model class
55 |         $classes = [$this->baseClass, $this->foreignClass, $this->mapClass];
56 |         list($baseTable, $associatedTable, $joinTable) = $this->filterTableNameFromClass($classes);
57 | 
58 |         // Get baseTableId & associatedTableId from the given input
59 |         $localId = (is_null($this->firstKey)) ? $this->getIdColumn($this->baseClass) : $this->firstKey;
60 |         $foreignId = (is_null($this->secondKey)) ? $this->getIdColumn($this->foreignClass) : $this->secondKey;
61 | 
62 |         // Get the mappingId and associatedId for joining table
63 |         $mappingId = $this->buildForeignKeyName($localId, $baseTable);
64 |         $foreignId = $this->buildForeignKeyName($foreignId, $associatedTable);
65 | 
66 |         return (new $this->foreignClass())
67 |             ->select("{$associatedTable}.*")
68 |             ->innerJoin($joinTable, [
69 |                     "{$associatedTable}.{$foreignId}",
70 |                     '=',
71 |                     "{$joinTable}.{$foreignId}", ]
72 |             )->where("{$joinTable}.{$mappingId}", '=', $this->$localId);
73 |     }
74 | }
75 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Cyrus/Relations/HasOne.php:
--------------------------------------------------------------------------------
1 | query();
 50 |         $this->setDatabase($connection == 'default' ? $query->getDefaultConnection() : $connection);
 51 |         $this->setTableName($table);
 52 |         $query->setActiveRecord($this);
 53 | 
 54 |         return $query;
 55 |     }
 56 | 
 57 |     /**
 58 |      * Get Query instance.
 59 |      *
 60 |      * @param        $table
 61 |      * @param string $connection
 62 |      *
 63 |      * @return QueryBuilder
 64 |      */
 65 |     public static function table($table, $connection = 'default')
 66 |     {
 67 |         return static::make()->setup($table, $connection);
 68 |     }
 69 | 
 70 |     /**
 71 |      * Return Query Builder Instance.
 72 |      *
 73 |      * @return QueryBuilder
 74 |      */
 75 |     public static function query()
 76 |     {
 77 |         QueryBuilder::$dataSource = true;
 78 | 
 79 |         return new QueryBuilder();
 80 |     }
 81 | 
 82 |     /**
 83 |      * Set table name to run queries.
 84 |      *
 85 |      * @param $table
 86 |      *
 87 |      * @return $this
 88 |      */
 89 |     public function setTableName($table)
 90 |     {
 91 |         $this->tableName = $table;
 92 | 
 93 |         return $this;
 94 |     }
 95 | 
 96 |     /**
 97 |      * Get Table name.
 98 |      *
 99 |      * @return mixed
100 |      */
101 |     public function getTableName()
102 |     {
103 |         return $this->tableName;
104 |     }
105 | 
106 |     /**
107 |      * This method won't be used though.
108 |      *
109 |      * @return string
110 |      */
111 |     public function getModelClassNs()
112 |     {
113 |     }
114 | 
115 |     /**
116 |      * Set database name to retrieve connection object.
117 |      *
118 |      * @param $database
119 |      *
120 |      * @return $this
121 |      */
122 |     public function setDatabase($database)
123 |     {
124 |         $this->database = $database;
125 | 
126 |         return $this;
127 |     }
128 | 
129 |     /**
130 |      * Get database name.
131 |      *
132 |      * @return mixed
133 |      */
134 |     public function getDatabase()
135 |     {
136 |         return $this->database;
137 |     }
138 | 
139 |     /**
140 |      * Set the primary key.
141 |      */
142 |     protected function setPrimaryKey($key)
143 |     {
144 |         $this->primaryKey = !is_null($key) ? $key : static::$defaultPrimaryKey;
145 | 
146 |         return $this;
147 |     }
148 | 
149 |     /**
150 |      * Get the primary key of table.
151 |      *
152 |      * @return null|string
153 |      */
154 |     public function getKeyName()
155 |     {
156 |         return isset($this->primaryKey) ? $this->primaryKey : static::$defaultPrimaryKey;
157 |     }
158 | }
159 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Exceptions/ActiveRecordMethodMissingException.php:
--------------------------------------------------------------------------------
1 | connection->errorInfo()),
16 |                 intval($exceptions->connection->errorCode())
17 |             );
18 |         } elseif ($exceptions instanceof PDOStatement) {
19 |             parent::__construct(
20 |                 implode(', ', $exceptions->errorInfo()),
21 |                 intval($exceptions->errorCode())
22 |             );
23 |         }
24 |     }
25 | }
26 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Migration.php:
--------------------------------------------------------------------------------
 1 | tableName = $table;
32 |         $this->setAttributes($attributes);
33 | 
34 |         if ($this->save()) {
35 |             return true;
36 |         } else {
37 |             return false;
38 |         }
39 |     }
40 | 
41 |     /**
42 |      * Delete rows using migration.
43 |      *
44 |      * @param       $table
45 |      * @param array $attribute
46 |      *
47 |      * @return bool
48 |      */
49 |     public function delete($table, $attribute)
50 |     {
51 |         $this->tableName = $table;
52 | 
53 |         if (is_array($attribute)) {
54 |             return $this->trash($attribute, true);
55 |         } elseif (is_string($attribute) || is_int($attribute)) {
56 |             return $this->trash($attribute);
57 |         }
58 |     }
59 | }
60 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/ResultSet.php:
--------------------------------------------------------------------------------
1 | 
13 |  * class User extends \Cygnite\Database\Service\Eloquent
14 |  * {
15 |  *
16 |  * }
17 |  * 
18 |  *
19 |  * Class Eloquent
20 |  */
21 | class Eloquent extends Model
22 | {
23 | }
24 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Service/Providers/EloquentServiceProvider.php:
--------------------------------------------------------------------------------
 1 | 
18 |  * class User extends \Cygnite\Database\Service\Eloquent
19 |  * {
20 |  *
21 |  *
22 |  * }
23 |  * 
24 |  *
25 |  * Class EloquentServiceProvider
26 |  */
27 | class EloquentServiceProvider extends ServiceProvider
28 | {
29 |     protected $app;
30 | 
31 |     public $eloquent;
32 | 
33 |     /**
34 |      * Setup Eloquent ORM Service Provider.
35 |      *
36 |      * @param Application $app
37 |      * @source https://github.com/illuminate/database
38 |      */
39 |     public function register(Application $app)
40 |     {
41 |         $this->eloquent = new EloquentCapsule();
42 |         $config = Database::getDatabaseConfiguration();
43 | 
44 |         /*
45 |          | We will loop over all connections
46 |          | and set connection
47 |          */
48 |         foreach ($config as $key => $c) {
49 |             $this->setConnection($c);
50 |         }
51 | 
52 |         $this->eloquent->setEventDispatcher(new Dispatcher(new Container()));
53 |         // Make this Capsule instance available globally via static methods... (optional)
54 |         $this->eloquent->setAsGlobal();
55 |         // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
56 |         $this->eloquent->bootEloquent();
57 |     }
58 | 
59 |     /**
60 |      * @param $c
61 |      */
62 |     private function setConnection($c)
63 |     {
64 |         $this->eloquent->addConnection([
65 |             'driver'    => $c['driver'],
66 |             'host'      => $c['host'],
67 |             'database'  => $c['database'],
68 |             'username'  => $c['username'],
69 |             'password'  => $c['password'],
70 |             'charset'   => $c['charset'],
71 |             'collation' => $c['collation'],
72 |             'prefix'    => $c['prefix'],
73 |         ]);
74 |     }
75 | }
76 | 


--------------------------------------------------------------------------------
/src/Cygnite/Database/Table/Seeder.php:
--------------------------------------------------------------------------------
  1 | 
  6 |  *
  7 |  * For the full copyright and license information, please view the LICENSE
  8 |  * file that was distributed with this source code.
  9 |  */
 10 | 
 11 | namespace Cygnite\Database\Table;
 12 | 
 13 | abstract class Seeder
 14 | {
 15 |     /**
 16 |      * Seeder Command.
 17 |      *
 18 |      * @var
 19 |      */
 20 |     public $command;
 21 | 
 22 |     /**
 23 |      * Filter out other class and set only class to seed.
 24 |      *
 25 |      * @param $class
 26 |      */
 27 |     public function executeOnly($class)
 28 |     {
 29 |         /*
 30 |          | We will check if user requesting for seeding multiple table
 31 |          | Then we will filter out only those class to seed from the
 32 |          | specified seeder array
 33 |          */
 34 |         if ($exp = string_split($class, ',')) {
 35 |             $this->seeders = $this->filterClass($exp);
 36 |         } else {
 37 |             $hasClass = (in_array($class, $this->seeders)) ? true : false;
 38 | 
 39 |             if ($hasClass) {
 40 |                 $this->seeders = $this->filterClass([$class]);
 41 |             }
 42 |         }
 43 |     }
 44 | 
 45 |     /**
 46 |      * Filter the class name from seeder array.
 47 |      *
 48 |      * @param array $class
 49 |      *
 50 |      * @return array
 51 |      */
 52 |     private function filterClass(array $class = [])
 53 |     {
 54 |         return array_intersect($this->seeders, $class);
 55 |     }
 56 | 
 57 |     /**
 58 |      * We will execute all seeder and populate database table.
 59 |      */
 60 |     public function execute()
 61 |     {
 62 |         $this->resolveSeeders($this->seeders);
 63 |     }
 64 | 
 65 |     /**
 66 |      * @param $seeders
 67 |      */
 68 |     public function resolveSeeders($seeders)
 69 |     {
 70 |         foreach ($seeders as $key => $class) {
 71 |             $this->resolve($class);
 72 |         }
 73 |     }
 74 | 
 75 |     /**
 76 |      * @param $class
 77 |      *
 78 |      * @return mixed
 79 |      */
 80 |     private function resolve($class)
 81 |     {
 82 |         $class = APP_NS.'\\Resources\\Database\\Seeding\\'.$class;
 83 | 
 84 |         $return = (new $class())->execute();
 85 | 
 86 |         if (isset($this->command)) {
 87 |             $this->command->info("Seeded: $class OK!");
 88 |         }
 89 | 
 90 |         return $return;
 91 |     }
 92 | 
 93 |     /**
 94 |      * @param $command
 95 |      */
 96 |     public function setSeederCommand($command)
 97 |     {
 98 |         $this->command = $command;
 99 |     }
100 | 
101 |     /**
102 |      * Run method is abstract therefore it must be implemented.
103 |      *
104 |      * @return mixed
105 |      */
106 |     abstract public function run();
107 | }
108 | 


--------------------------------------------------------------------------------
/src/Cygnite/EventHandler/EventInterface.php:
--------------------------------------------------------------------------------
 1 | 
 6 |  *
 7 |  * For the full copyright and license information, please view the LICENSE
 8 |  * file that was distributed with this source code.
 9 |  */
10 | namespace Cygnite\EventHandler;
11 | 
12 | use Cygnite\Helpers\Inflector;
13 | 
14 | /**
15 |  * Class EventRegistrarTrait.
16 |  */
17 | trait EventRegistrarTrait
18 | {
19 |     /**
20 |      * Register event listeners.
21 |      *
22 |      * @param array $listen
23 |      * @return $this
24 |      */
25 |     public function boot(array $listen)
26 |     {
27 |         $this->registerEvents($listen);
28 | 
29 |         return $this;
30 |     }
31 | 
32 |     /**
33 |      * We will register user defined events, it will trigger event when matches.
34 |      *
35 |      * @param $events
36 |      * @throws \RuntimeException
37 |      */
38 |     public function registerEvents($events)
39 |     {
40 |         if (empty($events)) {
41 |             throw new \RuntimeException(sprintf('Empty argument passed %s', __FUNCTION__));
42 |         }
43 | 
44 |         foreach ($events as $event => $namespace) {
45 |             $parts = explode('@', $namespace);
46 |             // attach all before and after event to handler
47 |             $this->register("$event.before", $parts[0].'@before'.ucfirst(Inflector::pathAction(end($parts))))
48 |                  ->register("$event", $parts[0].'@'.Inflector::pathAction(end($parts)))
49 |                  ->register("$event.after", $parts[0].'@after'.ucfirst(Inflector::pathAction(end($parts))));
50 |         }
51 |     }
52 | 
53 |     /**
54 |      * Fire all events registered with EventHandler.
55 |      *
56 |      * @param $event
57 |      * @return $this
58 |      */
59 |     public function fire($event)
60 |     {
61 |         $this->dispatch("$event.before");
62 |         $this->dispatch($event);
63 |         $this->dispatch("$event.after");
64 | 
65 |         return $this;
66 |     }
67 | }
68 | 


--------------------------------------------------------------------------------
/src/Cygnite/Exception/ExceptionInterface.php:
--------------------------------------------------------------------------------
 1 | statusCode = $statusCode;
21 |         $this->headers = $headers;
22 | 
23 |         parent::__construct($message, $code, $previous);
24 |     }
25 | 
26 |     /**
27 |      * @return int|string
28 |      */
29 |     public function getStatusCode()
30 |     {
31 |         return $this->statusCode;
32 |     }
33 | 
34 |     /**
35 |      * @return array
36 |      */
37 |     public function getHeaders()
38 |     {
39 |         return $this->headers;
40 |     }
41 | }
42 | 


--------------------------------------------------------------------------------
/src/Cygnite/Exception/Http/HttpExceptionInterface.php:
--------------------------------------------------------------------------------
 1 | 
2 |         
3 |              Cygnite Framework 
4 |         
5 |     
6 |     


--------------------------------------------------------------------------------
/src/Cygnite/FormBuilder/FormInterface.php:
--------------------------------------------------------------------------------
 1 | container = $container;
34 |         $this->paths = $paths;
35 |     }
36 | 
37 |     /**
38 |      * Register Log instance into Container.
39 |      */
40 |     public function run()
41 |     {
42 |         $config = Config::get('global.config', 'aliases');
43 |         $alias = new Manager($config['classes']);
44 |         $alias->register();
45 |         $this->container->set('alias', $alias);
46 |     }
47 | }
48 | 


--------------------------------------------------------------------------------
/src/Cygnite/Foundation/Bootstrappers/ApplicationBootstraper.php:
--------------------------------------------------------------------------------
 1 | container = $container;
23 |         $this->paths = $paths;
24 |     }
25 | 
26 |     /**
27 |      * @throws \Exception
28 |      */
29 |     public function run()
30 |     {
31 |         define('APP', str_replace('src/', 'src'.DS, APPPATH));
32 | 
33 |         $this->container->singleton('url', function () {
34 |             $manager = new \Cygnite\Common\UrlManager\Manager($this->container);
35 |             //Set URL base path.
36 |             $manager->setBase(
37 |                 (Config::get('global.config', 'base_path') == '') ?
38 |                     $this->container['router']->getBaseUrl() :
39 |                     Config::get('global.config', 'base_path')
40 |             );
41 | 
42 |             return new Url($manager);
43 |         });
44 | 
45 |         /* --------------------------------------------------
46 |          *  Set application encryption key
47 |          * ---------------------------------------------------
48 |          */
49 |         if (!is_null(Config::get('global.config', 'encryption.key'))) {
50 |             define('CF_ENCRYPT_KEY', Config::get('global.config', 'encryption.key'));
51 |         }
52 | 
53 |         /*
54 |          * ----------------------------------------------------
55 |          * Throw Exception is default controller
56 |          * has not been set in configuration
57 |          * ----------------------------------------------------
58 |          */
59 |         if (is_null(Config::get('global.config', 'default.controller'))) {
60 |             throw new \Exception('You must set default controller in '.APPPATH.'/Configs/application.php');
61 |         }
62 |     }
63 | }
64 | 


--------------------------------------------------------------------------------
/src/Cygnite/Foundation/Bootstrappers/LogBootstraper.php:
--------------------------------------------------------------------------------
 1 | container = $container;
21 |         $this->paths = $paths;
22 |     }
23 | 
24 |     /**
25 |      * Register Log instance into Container.
26 |      */
27 |     public function run()
28 |     {
29 |         $this->container->make(\Cygnite\Logger\Log::class);
30 |     }
31 | }
32 | 


--------------------------------------------------------------------------------
/src/Cygnite/Foundation/Bootstrappers/ViewBootstraper.php:
--------------------------------------------------------------------------------
 1 | container = $container;
33 |         $this->paths = $paths;
34 |     }
35 | 
36 |     /**
37 |      * Create, configure view and store view instance
38 |      * in container
39 |      */
40 |     public function run()
41 |     {
42 |         // Configure view & widget class.
43 |         ViewFactory::make(\Cygnite\Mvc\View\View::class, $this->container, function ($v) {
44 |             $v->setContainer($this->container);
45 | 
46 |             // Configure widget and register into container.
47 |             $widget = new \Cygnite\Mvc\View\Widget($this->paths, $v->getOutput());
48 |             $this->container->set('widget', $widget);
49 |         });
50 |     }
51 | }
52 | 


--------------------------------------------------------------------------------
/src/Cygnite/Foundation/Http/KernelInterface.php:
--------------------------------------------------------------------------------
 1 | cost = (int) $cost;
 41 | 
 42 |         return $this;
 43 |     }
 44 | 
 45 |     /**
 46 |      * We will creating hash for the given string and return it.
 47 |      *
 48 |      * @param string $string
 49 |      * @param array  $arguments
 50 |      *
 51 |      * @throws \RuntimeException
 52 |      *
 53 |      * @return string
 54 |      */
 55 |     public function create($string, array $arguments = [])
 56 |     {
 57 |         $cost = isset($arguments['cost']) ? $arguments['cost'] : $this->cost;
 58 | 
 59 |         if (isset($arguments['salt'])) {
 60 |             $hash = password_hash($string, PASSWORD_BCRYPT, ['cost' => $cost, 'salt' => $arguments['salt']]);
 61 |         } else {
 62 |             $hash = password_hash($string, PASSWORD_BCRYPT, ['cost' => $cost]);
 63 |         }
 64 | 
 65 |         if ($hash === false) {
 66 |             throw new \RuntimeException('BCrypt hashing support not available.');
 67 |         }
 68 | 
 69 |         return $hash;
 70 |     }
 71 | 
 72 |     /**
 73 |      * We will verify the given string(password) against hashed password.
 74 |      *
 75 |      * @param string $string
 76 |      * @param string $hash
 77 |      * @param array  $arguments
 78 |      *
 79 |      * @return bool
 80 |      */
 81 |     public function verify($string, $hash, array $arguments = [])
 82 |     {
 83 |         return password_verify($string, $hash);
 84 |     }
 85 | 
 86 |     /**
 87 |      * We will check if given hashed string has been
 88 |      * hashed using the given options.
 89 |      *
 90 |      * @param string $hashedString
 91 |      * @param array  $arguments
 92 |      *
 93 |      * @return bool
 94 |      */
 95 |     public function needReHash($hashedString, array $arguments = [])
 96 |     {
 97 |         $cost = isset($arguments['cost']) ? $arguments['cost'] : $this->cost;
 98 | 
 99 |         return password_needs_rehash($hashedString, PASSWORD_BCRYPT, ['cost' => $cost]);
100 |     }
101 | }
102 | 


--------------------------------------------------------------------------------
/src/Cygnite/Hash/Hash.php:
--------------------------------------------------------------------------------
 1 | {__FUNCTION__}($string, $arguments);
35 |     }
36 | 
37 |     /**
38 |      * @param       $string
39 |      * @param       $hash
40 |      * @param array $arguments
41 |      *
42 |      * @return mixed
43 |      */
44 |     public static function verify($string, $hash, array $arguments = [])
45 |     {
46 |         return self::instance()->{__FUNCTION__}($string, $hash, $arguments);
47 |     }
48 | 
49 |     /**
50 |      * @param       $hashedString
51 |      * @param array $arguments
52 |      *
53 |      * @return mixed
54 |      */
55 |     public static function needReHash($hashedString, array $arguments = [])
56 |     {
57 |         return self::instance()->{__FUNCTION__}($hashedString, $arguments);
58 |     }
59 | }
60 | 


--------------------------------------------------------------------------------
/src/Cygnite/Hash/HashInterface.php:
--------------------------------------------------------------------------------
 1 | =5.4.0",
12 |         "cygnite/proxy": "1.0.*",
13 |         "ircmaxell/password-compat": "~1.0"
14 |     },
15 |     "autoload": {
16 |         "psr-0": {
17 |             "Cygnite\\Hash": ""
18 |         }
19 |     },
20 |     "target-dir": "Cygnite/Hash",
21 |     "extra": {
22 |         "branch-alias": {
23 |             "dev-master": "2.0-dev"
24 |         }
25 |     },
26 |     "minimum-stability": "dev"
27 | }
28 | 


--------------------------------------------------------------------------------
/src/Cygnite/Helpers/Profiler.php:
--------------------------------------------------------------------------------
 1 | 
Total elapsed time : ".round(self::getTime() - self::$blocks[$endToken], 3).' s'; 47 | //$html .= self::getMemoryPeakUsage(); 48 | $html .= '     Total memory :'.self::getMemorySpaceUsage().'
'; 49 | echo $html; 50 | } 51 | 52 | /** 53 | * This Function is to get the memory usage by the script. 54 | * 55 | * @return get memory usage 56 | */ 57 | private static function getMemorySpace() 58 | { 59 | return memory_get_usage(); 60 | } 61 | 62 | /** 63 | * This function is to calculate the total memory usage by the running script. 64 | * 65 | * @false string 66 | * 67 | * @return string 68 | */ 69 | public static function getMemorySpaceUsage() 70 | { 71 | //round(memory_get_usage()/1024/1024, 2).'MB'; 72 | return round(((self::getMemorySpace() - MEMORY_START_POINT) / 1024), 2).' KB
'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Cygnite/Helpers/Str.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Http; 12 | 13 | use Cygnite\Foundation\Collection; 14 | 15 | /** 16 | * Class Header. 17 | */ 18 | class Header extends Collection 19 | { 20 | //The list of HTTP request headers are not starting with "HTTP_" prefix 21 | protected static $specialCaseHeaders = [ 22 | 'AUTH_TYPE' => true, 23 | 'CONTENT_LENGTH' => true, 24 | 'CONTENT_TYPE' => true, 25 | 'PHP_AUTH_DIGEST' => true, 26 | 'PHP_AUTH_PW' => true, 27 | 'PHP_AUTH_TYPE' => true, 28 | 'PHP_AUTH_USER' => true, 29 | ]; 30 | 31 | /** 32 | * Constructor. 33 | * 34 | * @param array $values 35 | */ 36 | public function __construct(array $values = []) 37 | { 38 | // Only add "HTTP_" server values 39 | foreach ($values as $name => $value) { 40 | $name = strtoupper($name); 41 | 42 | if (isset(self::$specialCaseHeaders[$name]) || strpos($name, 'HTTP_') === 0) { 43 | $this->set($name, $value); 44 | } 45 | } 46 | } 47 | 48 | /** 49 | * Set header values. 50 | * 51 | * @param $name 52 | * @param $values 53 | * @param bool $shouldReplace 54 | * 55 | * @return $this|void 56 | */ 57 | public function add(string $name, $values, $shouldReplace = true) 58 | { 59 | $this->set($name, $values, $shouldReplace); 60 | } 61 | 62 | /** 63 | * Return only first header values if exists otherwise 64 | * return all header information. 65 | * 66 | * @param mixed $name 67 | * @param null $default 68 | * @param bool $onlyReturnFirst 69 | * 70 | * @return mixed|null 71 | */ 72 | public function get(string $name, $default = null, $onlyReturnFirst = true) 73 | { 74 | if ($this->has($name)) { 75 | $value = $this->data[$this->normalizeName($name)]; 76 | 77 | if ($onlyReturnFirst) { 78 | return $value[0]; 79 | } 80 | } else { 81 | $value = $default; 82 | } 83 | 84 | return $value; 85 | } 86 | 87 | /** 88 | * Check if header key exists. 89 | * 90 | * @param $name 91 | * 92 | * @return bool 93 | */ 94 | public function has(string $name) : bool 95 | { 96 | return parent::has($this->normalizeName($name)); 97 | } 98 | 99 | /** 100 | * Remove header key from the collection. 101 | * 102 | * @param $name 103 | * 104 | * @return Collection 105 | */ 106 | public function remove(string $name) : Collection 107 | { 108 | return parent::remove($this->normalizeName($name)); 109 | } 110 | 111 | /** 112 | * Set header information. 113 | * 114 | * @param $name 115 | * @param $value 116 | * @param bool $shouldReplace 117 | */ 118 | public function set($name, $value, $shouldReplace = true) 119 | { 120 | $name = $this->normalizeName($name); 121 | $value = (array) $value; 122 | 123 | if ($shouldReplace || !$this->has($name)) { 124 | parent::add($name, $value); 125 | } else { 126 | parent::add($name, array_merge($this->data[$name], $value)); 127 | } 128 | } 129 | 130 | /** 131 | * Normalizes a key string. 132 | * 133 | * @param $name 134 | * 135 | * @return string 136 | */ 137 | protected function normalizeName($name) 138 | { 139 | $name = strtr(strtolower($name), '_', '-'); 140 | 141 | if (strpos($name, 'http-') === 0) { 142 | $name = substr($name, 5); 143 | } 144 | 145 | return $name; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/Cygnite/Http/Requests/Files.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Http\Requests; 11 | 12 | use Cygnite\Foundation\Collection; 13 | 14 | /** 15 | * Class Files. 16 | */ 17 | class Files extends Collection 18 | { 19 | /** 20 | * @param $name 21 | * @param $value 22 | * 23 | * @return $this|void 24 | */ 25 | public function add(string $name, $value) 26 | { 27 | parent::add($name, $value); 28 | } 29 | 30 | /** 31 | * @param mixed $name 32 | * @param null $default 33 | * 34 | * @return mixed 35 | */ 36 | public function get(string $name, $default = null) 37 | { 38 | return parent::get($name, $default); 39 | } 40 | 41 | /** 42 | * @return array 43 | */ 44 | public function all() : array 45 | { 46 | return parent::all(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Cygnite/Http/Requests/RequestHeaderConstants.php: -------------------------------------------------------------------------------- 1 | jsonEncode($content, $prettyPrint); 26 | } 27 | 28 | parent::__construct($content, ResponseHeader::HTTP_OK, $headers); 29 | $this->setContentType(ResponseHeader::CONTENT_TYPE_JSON); 30 | } 31 | 32 | /** 33 | * @param $data 34 | * @param $prettyPrint 35 | * 36 | * @throws \InvalidArgumentException 37 | * @throws \Exception 38 | * 39 | * @return string 40 | * @reference https://github.com/symfony/HttpFoundation/blob/master/JsonResponse.php 41 | */ 42 | public function jsonEncode($data, $prettyPrint) 43 | { 44 | try { 45 | $data = json_encode($data, (($prettyPrint) ? JSON_PRETTY_PRINT : 15)); 46 | } catch (\Exception $e) { 47 | if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) { 48 | throw $e->getPrevious() ?: $e; 49 | } 50 | 51 | throw $e; 52 | } 53 | 54 | if (JSON_ERROR_NONE !== json_last_error()) { 55 | throw new \InvalidArgumentException(json_last_error_msg()); 56 | } 57 | 58 | return $data; 59 | } 60 | 61 | /** 62 | * @param null $data 63 | * @param array $headers 64 | * 65 | * @return static 66 | */ 67 | public static function sendJson($data = null, $headers = []) 68 | { 69 | $response = new static($data, $headers); 70 | $response->send(); 71 | 72 | return $response; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Cygnite/Http/Responses/RedirectResponse.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Http\Responses; 11 | 12 | /** 13 | * Class Response. 14 | */ 15 | class RedirectResponse extends Response 16 | { 17 | /** @var string Redirect URL */ 18 | protected $redirectUrl; 19 | 20 | public function __construct($targetUrl, $statusCode = ResponseHeader::HTTP_FOUND, array $headers = []) 21 | { 22 | parent::__construct('', $statusCode, $headers); 23 | 24 | $this->setRedirectToUrl($targetUrl); 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getUrl() 31 | { 32 | return $this->redirectUrl; 33 | } 34 | 35 | /** 36 | * @param string $targetUrl 37 | */ 38 | public function setRedirectToUrl($redirectUrl) 39 | { 40 | $this->redirectUrl = $redirectUrl; 41 | $this->headers->set('Location', $this->redirectUrl); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Cygnite/Http/Responses/ResponseInterface.php: -------------------------------------------------------------------------------- 1 | . 12 | * 13 | * Response::make($content, ResponseHeader::HTTP_OK)->send(); 14 | * 15 | * Response::make($content, function ($response) 16 | * { 17 | * return $response->setHeader($key, $value)->send(); 18 | * }); 19 | * 20 | * 21 | * 22 | * @param string $content 23 | * @param callable|int $statusCode 24 | * @param array $headers 25 | * 26 | * @return static 27 | */ 28 | public static function make($content = '', $statusCode = ResponseHeader::HTTP_OK, $headers = []); 29 | 30 | /** 31 | * @param null $content 32 | * 33 | * @return mixed 34 | */ 35 | public function setContent($content = null); 36 | 37 | /** 38 | * @return mixed 39 | */ 40 | public function getContent(); 41 | 42 | /** 43 | * @param int $statusCode 44 | * 45 | * @return mixed 46 | */ 47 | public function setStatusCode($statusCode = ResponseHeader::HTTP_OK); 48 | 49 | /** 50 | * @return mixed 51 | */ 52 | public function getStatusCode(); 53 | 54 | /** 55 | * @param $name 56 | * @param $value 57 | * @param bool $replace 58 | * 59 | * @return mixed 60 | */ 61 | public function setHeader($name, $value); 62 | 63 | /** 64 | * @param $contentType 65 | * 66 | * @return mixed 67 | */ 68 | public function setContentType($contentType); 69 | 70 | /** 71 | * @return mixed 72 | */ 73 | public function getContentType(); 74 | 75 | /** 76 | * @param $charset 77 | * 78 | * @return mixed 79 | */ 80 | public function setCharset($charset); 81 | 82 | /** 83 | * @return mixed 84 | */ 85 | public function getCharset(); 86 | 87 | /** 88 | * Send header and content to the browser. 89 | * 90 | * @return $this 91 | */ 92 | public function send(); 93 | } 94 | -------------------------------------------------------------------------------- /src/Cygnite/Http/Responses/StreamedResponse.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Http\Responses; 11 | 12 | /** 13 | * Class StreamedResponse. 14 | */ 15 | class StreamedResponse extends Response 16 | { 17 | protected $callback = null; 18 | 19 | protected $streamed = false; 20 | 21 | /** 22 | * Constructor of StreamedResponse class. 23 | * 24 | * @param \Cygnite\Http\Responses\callable $callback 25 | * @param type $status 26 | * @param type $headers 27 | */ 28 | public function __construct(callable $callback = null, $status = ResponseHeaders::HTTP_OK, $headers = []) 29 | { 30 | parent::__construct('', $status, $headers); 31 | 32 | if ($callback !== null) { 33 | $this->setCallback($callback); 34 | } 35 | } 36 | 37 | /** 38 | * Factory method to return StreamedResponse object to chain methods. 39 | * 40 | * @param type $callback 41 | * @param type $status 42 | * @param type $headers 43 | * 44 | * @return \static 45 | */ 46 | public static function make($callback = null, $status = ResponseHeaders::HTTP_OK, $headers = []) 47 | { 48 | return new static($callback, $status, $headers); 49 | } 50 | 51 | /** 52 | * Send streamed contents. 53 | * 54 | * @throws \LogicException 55 | */ 56 | public function sendContent() 57 | { 58 | if (null === $this->callback) { 59 | throw new \LogicException('The SteamedResponse callback must not be null.'); 60 | } 61 | 62 | if (!$this->streamed && $this->callback !== null) { 63 | call_user_func($this->callback); 64 | $this->streamed = true; 65 | } 66 | } 67 | 68 | /** 69 | * Throw exception if user tries to send content for 70 | * StreamedResponse. 71 | * 72 | * @param type $content 73 | * 74 | * @throws \LogicException 75 | */ 76 | public function setContent($content = null) 77 | { 78 | //you are not alowed to set content for a stream response 79 | if ($content !== null && $content !== '') { 80 | throw new \LogicException('Cannot set content in a stream response'); 81 | } 82 | } 83 | 84 | /** 85 | * Returns false. 86 | * 87 | * @return bool 88 | */ 89 | public function getContent() 90 | { 91 | return false; 92 | } 93 | 94 | /** 95 | * Set the callback for streaming response. 96 | * 97 | * @param \Cygnite\Http\Responses\callable $callback 98 | */ 99 | public function setCallback(callable $callback) 100 | { 101 | $this->callback = $callback; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Cygnite/Mvc/Controller/ServiceController.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | namespace Cygnite\Mvc\Controller; 12 | 13 | /** 14 | * ServiceController. 15 | * 16 | * Extend the features of AbstractBaseController. 17 | * 18 | * @author Sanjoy Dey 19 | */ 20 | class ServiceController extends AbstractBaseController implements ServiceControllerInterface 21 | { 22 | /** 23 | * The container's bind data. 24 | * 25 | * @var array 26 | */ 27 | private $service = []; 28 | 29 | public function __construct() 30 | { 31 | } 32 | 33 | 34 | 35 | /** 36 | * Get a data by key. 37 | * 38 | * @param $key 39 | * 40 | * @throws InvalidArgumentException 41 | * 42 | * @return 43 | */ 44 | public function &__get($key) 45 | { 46 | if (!isset($this->service[$key])) { 47 | throw new InvalidArgumentException(sprintf('Value "%s" is not defined.', $key)); 48 | } 49 | 50 | return 51 | isset($this->service[$key]) && 52 | is_callable($this->service[$key]) ? 53 | $this->service[$key]($this) : 54 | $this->service[$key]; 55 | } 56 | 57 | /** 58 | * Assigns a value to the specified data. 59 | * 60 | * @param string The data key to assign the value to 61 | * @param mixed The value to set 62 | */ 63 | public function __set($key, $value) 64 | { 65 | $this->service[$key] = $value; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Cygnite/Mvc/Controller/ServiceControllerInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Mvc; 11 | 12 | use Cygnite\Container\Exceptions\ContainerException; 13 | 14 | /** 15 | * trait ControllerViewBridgeTrait. 16 | */ 17 | trait ControllerViewBridgeTrait 18 | { 19 | public $validFlashMessage = ['setFlash', 'hasFlash', 'getFlash', 'hasError']; 20 | 21 | /** 22 | * Call Flash methods. 23 | * 24 | * @param $method 25 | * @param $arguments 26 | * @return AbstractBaseController|mixed 27 | */ 28 | public function setFlashMessage($method, $arguments) 29 | { 30 | $flashSession = $this->resolve('cygnite.common.session-manager.flash.flash-message'); 31 | 32 | if ($method == 'setFlash') { 33 | $this->_call($flashSession, $method, $arguments); 34 | 35 | return $this; 36 | } 37 | 38 | return $this->_call($flashSession, $method, $arguments); 39 | } 40 | 41 | /** 42 | * Returns registered item from container. 43 | * 44 | * @param $class 45 | * @return mixed 46 | * @throws ContainerException 47 | */ 48 | public function resolve($class) 49 | { 50 | return $this->container()->resolve($class); 51 | } 52 | 53 | /** 54 | * Call class methods dynamically. 55 | * 56 | * @param $instance 57 | * @param $method 58 | * @param array $arguments 59 | * 60 | * @return mixed 61 | */ 62 | public function _call($instance, $method, $arguments = []) 63 | { 64 | if (method_exists($instance, $method)) { 65 | return call_user_func_array([$instance, $method], $arguments); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Cygnite/Mvc/View/Exceptions/ViewEventNotFoundException.php: -------------------------------------------------------------------------------- 1 | view = $view; 23 | } 24 | 25 | /** 26 | * Get View instance 27 | */ 28 | public function getView() : View 29 | { 30 | return $this->view; 31 | } 32 | 33 | /** 34 | * @param $path 35 | * @param $data 36 | * 37 | * @return string 38 | */ 39 | public function renderView($path, $data) 40 | { 41 | $obLevel = ob_get_level(); 42 | ob_start(); 43 | extract($data); 44 | 45 | /* 46 | | We will try to include view file and check content into try catch block 47 | | so that if any exception occurs output buffer will get flush out. 48 | */ 49 | try { 50 | include $path; 51 | } catch (Exception $e) { 52 | $this->handleViewException($e, $obLevel); 53 | } 54 | 55 | return ltrim(ob_get_clean()); 56 | } 57 | 58 | /** 59 | * @param $e 60 | * @param $obLevel 61 | * 62 | * @throws 63 | */ 64 | public function handleViewException($e, $obLevel) 65 | { 66 | while (ob_get_level() > $obLevel) { 67 | ob_end_clean(); 68 | } 69 | 70 | throw $e; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Cygnite/Mvc/View/ViewFactory.php: -------------------------------------------------------------------------------- 1 | make($class)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Cygnite/Mvc/View/ViewInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Pipeline; 11 | 12 | class PipelineException extends \Exception 13 | { 14 | } 15 | -------------------------------------------------------------------------------- /src/Cygnite/Pipeline/PipelineInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Pipeline; 11 | 12 | use Cygnite\Container\ContainerAwareInterface; 13 | 14 | interface PipelineInterface 15 | { 16 | /** 17 | * Set container into pipeline for resolving objects. 18 | * 19 | * @param ContainerAwareInterface $container 20 | * 21 | * @return $this 22 | */ 23 | public function setContainer(ContainerAwareInterface $container); 24 | 25 | /** 26 | * Send request through pipeline. 27 | * 28 | * @param $request 29 | * 30 | * @return $this 31 | */ 32 | public function send($request); 33 | 34 | /** 35 | * Apply filters over pipes before executing. 36 | * 37 | * @param callable $callback 38 | * 39 | * @return $this 40 | */ 41 | public function then(callable $callback); 42 | 43 | /** 44 | * Pass request through the pipeline. 45 | * 46 | * @param array $pipes 47 | * @param string|null $method 48 | * 49 | * @return $this 50 | */ 51 | public function through(array $pipes, string $method = null); 52 | 53 | /** 54 | * Run all pipeline requests. 55 | * 56 | * @return mixed 57 | */ 58 | public function run(); 59 | } 60 | -------------------------------------------------------------------------------- /src/Cygnite/Pipeline/PipelineServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Pipeline; 11 | 12 | use Cygnite\Container\ContainerAwareInterface; 13 | use Cygnite\Container\Service\ServiceProvider; 14 | 15 | /** 16 | * Class PipelineServiceProvider. 17 | */ 18 | class PipelineServiceProvider extends ServiceProvider 19 | { 20 | protected $container; 21 | 22 | /** 23 | * Register Pipeline into application container. 24 | * 25 | * @param ContainerAwareInterface $container 26 | */ 27 | public function register(ContainerAwareInterface $container) 28 | { 29 | $container->set('pipeline', new Pipeline($container)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Cygnite/Proxy/Asset.php: -------------------------------------------------------------------------------- 1 | $method(); 58 | case 1: 59 | return (new $class())->$method($arguments[0]); 60 | case 2: 61 | return (new $class())->$method($arguments[0], $arguments[1]); 62 | case 3: 63 | return (new $class())->$method($arguments[0], $arguments[1], $arguments[2]); 64 | case 4: 65 | return (new $class())->$method($arguments[0], $arguments[1], $arguments[2], $arguments[3]); 66 | default: 67 | return call_user_func_array([new $class(), $method], $arguments); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Cygnite/Router/Controller/RouteControllerInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace Cygnite\Router\Controller; 12 | 13 | if (!defined('CF_SYSTEM')) { 14 | exit('No External script access allowed'); 15 | } 16 | 17 | /** 18 | * Class RouteControllerInterface. 19 | */ 20 | interface RouteControllerInterface 21 | { 22 | /** 23 | * Set the controller as Route Controller 24 | * Cygnite Router knows how to respond to routes controller 25 | * request automatically. 26 | * 27 | * @param $controller 28 | * 29 | * @return $this 30 | */ 31 | public function routeController($controller); 32 | 33 | /** 34 | * @param $actions 35 | * 36 | * @return array 37 | */ 38 | public function setActions($actions); 39 | 40 | /** 41 | * @return array 42 | */ 43 | public function getActions(); 44 | } 45 | -------------------------------------------------------------------------------- /src/Cygnite/Router/InvalidRouterCollectionException.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Services\Omnipay; 11 | 12 | use Cygnite\Foundation\Application; 13 | use Cygnite\Helpers\Config; 14 | use Omnipay\Common\CreditCard; 15 | use Omnipay\Common\GatewayFactory; 16 | 17 | /** 18 | * Class Omnipay. 19 | */ 20 | class GatewayManager 21 | { 22 | protected $factory; 23 | 24 | protected $config; 25 | 26 | /** 27 | * The array of resolved queue connections. 28 | * 29 | * @var array 30 | */ 31 | protected $gateways = []; 32 | 33 | public function __construct(Application $app, GatewayFactory $factory, $config = []) 34 | { 35 | $this->app = $app; 36 | $this->factory = $factory; 37 | $this->config = $config; 38 | } 39 | 40 | /** 41 | * Gateway factory return the gateway instance. 42 | * 43 | * @param null $class 44 | * 45 | * @return mixed 46 | */ 47 | public function gateway($class = null) 48 | { 49 | $class = $class ?: $this->getDefaultGateway(); 50 | 51 | if (!isset($this->gateways[$class])) { 52 | $gateway = $this->factory->create($class); 53 | $gateway->initialize($this->getConfig($class)); 54 | $this->gateways[$class] = $gateway; 55 | } 56 | 57 | return $this->gateways[$class]; 58 | } 59 | 60 | /** 61 | * Returns Gateways. 62 | * 63 | * @return array 64 | */ 65 | public function getGateways() 66 | { 67 | return $this->gateways; 68 | } 69 | 70 | /** 71 | * Get the config item. 72 | * 73 | * @param $name 74 | * 75 | * @return mixed 76 | */ 77 | protected function getConfig($name) 78 | { 79 | return $this->config['gateways'][$name]; 80 | } 81 | 82 | /** 83 | * Return Omnipay\Common\CreditCard instance. 84 | * 85 | * @param $input 86 | * 87 | * @return CreditCard 88 | */ 89 | public function creditCard($input) 90 | { 91 | return new CreditCard($input); 92 | } 93 | 94 | /** 95 | * Set the payment gateway. 96 | * 97 | * @param $name 98 | * 99 | * @return $this 100 | */ 101 | public function setGateway($name) 102 | { 103 | $this->gateway = $name; 104 | 105 | return $this; 106 | } 107 | 108 | /** 109 | * Get the Gateway. 110 | * 111 | * @return string 112 | */ 113 | public function getGateway() 114 | { 115 | return (!isset($this->gateway)) ? 116 | $this->gateway = $this->getDefaultGateway() : 117 | $this->gateway; 118 | } 119 | 120 | /** 121 | * Get the default gateway. 122 | * 123 | * @return string 124 | */ 125 | public function getDefaultGateway() 126 | { 127 | return $this->config['default']; 128 | } 129 | 130 | /** 131 | * Try Calling gateway method if user tries to access method 132 | * which is not available in the class GatewayManager. 133 | * 134 | * @param $method 135 | * @param $parameters 136 | * 137 | * @throws \BadMethodCallException 138 | * 139 | * @return mixed 140 | */ 141 | public function __call($method, $parameters) 142 | { 143 | if (method_exists($this->gateway(), $method)) { 144 | return call_user_func_array([$this->gateway(), $method], $parameters); 145 | } 146 | 147 | throw new \BadMethodCallException("Method [$method] is not supported by the gateway [$this->gateway]."); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/Cygnite/Services/Omnipay/Providers/OmnipayServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Services\Omnipay\Providers; 11 | 12 | use Cygnite\Container\Service\ServiceProvider; 13 | use Cygnite\Foundation\Application; 14 | use Cygnite\Helpers\Config; 15 | use Cygnite\Services\Omnipay\GatewayManager; 16 | use Omnipay\Common\GatewayFactory; 17 | 18 | /** 19 | * Class OmnipayServiceProvider. 20 | */ 21 | class OmnipayServiceProvider extends ServiceProvider 22 | { 23 | protected $app; 24 | 25 | private $config; 26 | 27 | public function register(Application $app) 28 | { 29 | $this->configureOmnipay(); 30 | $this->registerOmnipay(); 31 | } 32 | 33 | /** 34 | * Register the Stripe API class. 35 | * 36 | * @return void 37 | */ 38 | protected function registerOmnipay() 39 | { 40 | $this->app->singleton('omnipay', function ($c) { 41 | $omnipay = new GatewayManager($this->app, new GatewayFactory(), $this->config); 42 | $omnipay->gateway(); 43 | 44 | return $omnipay; 45 | }); 46 | } 47 | 48 | /** 49 | * Set Stripe Configuration. 50 | * 51 | * @return void 52 | */ 53 | protected function configureOmnipay() 54 | { 55 | $this->config = Config::get('global.config', 'omnipay.config'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Cygnite/Services/Omnipay/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cygnite/ominipay", 3 | "description": "Cygnite 2.0 integration for the Ominipay package.", 4 | "keywords": [ 5 | "php", 6 | "ominipay", 7 | "cygnite", 8 | "stripe" 9 | ], 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Sanjoy Dey", 14 | "email": "dey.sanjoy0@gmail.com", 15 | "homepage": "https://appsntech.com" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.4", 20 | "omnipay/omnipay": "~2.0", 21 | "cygnite/framework": "dev-master", 22 | }, 23 | "require-dev": { 24 | "phpunit/phpunit": "~4.0" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "Cygnite\\Services\\Ominipay\\Providers\\": "" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Cygnite/Services/SocialOAuth/Providers/SocialAuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Services\SocialOAuth\Providers; 11 | 12 | use Cygnite\Container\Service\ServiceProvider; 13 | use Cygnite\Foundation\Application; 14 | use Cygnite\Helpers\Config; 15 | use OAuth\Common\Consumer\Credentials; 16 | use OAuth\Common\Storage\Session; 17 | 18 | /** 19 | * Class SocialAuthServiceProvider. 20 | */ 21 | class SocialAuthServiceProvider extends ServiceProvider 22 | { 23 | protected $app; 24 | 25 | private $config; 26 | 27 | /** 28 | * @param Application $app 29 | */ 30 | public function register(Application $app) 31 | { 32 | if ($this->configureSocialAuth()) { 33 | $this->registerSocialAuth(); 34 | } 35 | } 36 | 37 | /** 38 | * Register the Social OAuth API class. 39 | * 40 | * @return void 41 | */ 42 | protected function registerSocialAuth() 43 | { 44 | // Session storage 45 | $storage = new Session(); 46 | $factory = new \OAuth\ServiceFactory(); 47 | 48 | foreach ($this->config['active'] as $key => $social) { 49 | $this->app->singleton($social, function ($c) use ($social, $factory, $storage) { 50 | // Setup the credentials for the requests 51 | $credentials = new Credentials( 52 | $this->config[$social]['key'], 53 | $this->config[$social]['secret'], 54 | $this->app->request->getFullUrl() 55 | ); 56 | 57 | return $factory->createService($social, $credentials, $storage, []); 58 | }); 59 | } 60 | } 61 | 62 | /** 63 | * Set Social OAuth Configuration. 64 | * 65 | * @return void 66 | */ 67 | protected function configureSocialAuth() 68 | { 69 | $this->config = Config::get('global.config', 'social.config'); 70 | 71 | if (isset($this->config['active']) && !empty($this->config['active'])) { 72 | return true; 73 | } 74 | 75 | return false; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Cygnite/Services/Stripe/Providers/StripeServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Services\Stripe\Providers; 11 | 12 | use Cartalyst\Stripe\Stripe; 13 | use Cygnite\Container\Service\ServiceProvider; 14 | use Cygnite\Foundation\Application; 15 | use Cygnite\Helpers\Config; 16 | 17 | /** 18 | * Class StripeServiceProvider. 19 | */ 20 | class StripeServiceProvider extends ServiceProvider 21 | { 22 | protected $app; 23 | 24 | private $config; 25 | 26 | public function register(Application $app) 27 | { 28 | $this->configureStripe(); 29 | $this->registerStripe(); 30 | } 31 | 32 | /** 33 | * Register the Stripe API class. 34 | * 35 | * @return void 36 | */ 37 | protected function registerStripe() 38 | { 39 | $this->app->singleton('stripe', function ($c) { 40 | return new Stripe($this->config['secret'], $this->config['version']); 41 | }); 42 | } 43 | 44 | /** 45 | * Set Stripe Configuration. 46 | * 47 | * @return void 48 | */ 49 | protected function configureStripe() 50 | { 51 | $this->config = Config::get('global.config', 'stripe.config'); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Cygnite/Services/Stripe/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cygnite/stripe", 3 | "description": "Cygnite 2.0 integration for the Cartalyst Stripe package.", 4 | "keywords": [ 5 | "php", 6 | "cartalyst", 7 | "cygnite", 8 | "stripe" 9 | ], 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Sanjoy Dey", 14 | "email": "dey.sanjoy0@gmail.com", 15 | "homepage": "https://appsntech.com" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.4", 20 | "cartalyst/stripe": "~1.0" 21 | }, 22 | "require-dev": { 23 | "phpunit/phpunit": "~4.0" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Cygnite\\Services\\Stripe\\": "" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Cygnite/Translation/TranslatorInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | namespace Cygnite\Validation; 11 | 12 | /** 13 | * trait ValidationTrait. 14 | */ 15 | trait ValidationTrait 16 | { 17 | public $errors = []; 18 | 19 | public $inputs = []; 20 | 21 | public $validation; 22 | 23 | /** 24 | * @return $this 25 | */ 26 | public function validator($inputs) 27 | { 28 | $this->inputs = $inputs; 29 | $this->validation = Validator::create($inputs); 30 | 31 | return $this; 32 | } 33 | 34 | /** 35 | * Get the validator instance. 36 | * 37 | * @return mixed 38 | */ 39 | public function getValidator() 40 | { 41 | return $this->validation; 42 | } 43 | 44 | /** 45 | * Add rules to validator. 46 | * 47 | * @return $this 48 | */ 49 | public function addRule() 50 | { 51 | foreach ($this->rules as $field => $rule) { 52 | $this->validation->addRule($field, $rule); 53 | } 54 | 55 | return $this; 56 | } 57 | 58 | /** 59 | * @return bool 60 | */ 61 | public function run() 62 | { 63 | return ($this->validation->run()) ? true : false; 64 | } 65 | 66 | /** 67 | * We will validate for and return boolean 68 | * value. 69 | * 70 | * @param $inputs 71 | * 72 | * @throws \RuntimeException 73 | * 74 | * @return bool 75 | */ 76 | public function validate($inputs) 77 | { 78 | if (empty($this->rules)) { 79 | throw new \RuntimeException('You must set rules for validator.'); 80 | return false; 81 | } 82 | 83 | if (empty($inputs)) { 84 | throw new \RuntimeException('Empty array passed to validate method'); 85 | } 86 | 87 | $this->validator($inputs)->addRule(); 88 | 89 | if (!$this->run()) { 90 | $this->setErrors($this->validation->getErrors()); 91 | 92 | return false; 93 | } 94 | 95 | return true; 96 | } 97 | 98 | /** 99 | * Set all validation errors into array. 100 | * 101 | * @param $errors 102 | */ 103 | private function setErrors($errors) 104 | { 105 | $this->errors = $errors; 106 | } 107 | 108 | /** 109 | * We will return validation errors if any. 110 | * 111 | * @return array 112 | */ 113 | public function validationErrors() 114 | { 115 | return $this->errors; 116 | } 117 | 118 | /** 119 | * @return bool 120 | */ 121 | public function hasErrors() 122 | { 123 | return !empty($this->errors); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/Cygnite/Validation/ValidatorInterface.php: -------------------------------------------------------------------------------- 1 |