├── .coveralls.yml ├── LICENSE.md ├── README.md ├── composer.json ├── docs └── logo.svg ├── resources └── views │ └── pagination │ ├── bootstrap-4.blade.php │ └── default.blade.php └── src ├── App.php ├── Concerns ├── SetupLaravel.php └── SetupTracy.php ├── Exceptions └── EntryNotFoundException.php ├── Laravel.php └── helpers.php /.coveralls.yml: -------------------------------------------------------------------------------- 1 | coverage_clover: build/logs/clover.xml 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 recca0120 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | Build Status 5 | Coverage Status 6 | Latest Stable Version 7 | Total Downloads 8 | Latest Unstable Version 9 | License 10 | Monthly Downloads 11 | Daily Downloads 12 |

13 | 14 | 15 | ## Installation 16 | 17 | Add Presenter to your composer.json file: 18 | 19 | ```json 20 | "require": { 21 | "recca0120/laravel-bridge": "^1.0.0" 22 | } 23 | ``` 24 | 25 | > Require `illuminate/translation` when using Pagination. 26 | 27 | Now, run a composer update on the command line from the root of your project: 28 | 29 | ``` 30 | composer update 31 | ``` 32 | 33 | > **NOTICE**: NOT support Laravel 5.4.* 34 | 35 | ## How to use 36 | 37 | setup 38 | 39 | ```php 40 | use Recca0120\LaravelBridge\Laravel; 41 | 42 | require __DIR__.'/vendor/autoload.php'; 43 | 44 | $connections = [ 45 | 'default' => [ 46 | 'driver' => 'mysql', 47 | 'host' => 'localhost', 48 | 'port' => 3306, 49 | 'database' => 'forge', 50 | 'username' => 'forge', 51 | 'password' => '', 52 | 'charset' => 'utf8', 53 | 'collation' => 'utf8_unicode_ci', 54 | 'prefix' => '', 55 | 'strict' => false, 56 | 'engine' => null, 57 | ], 58 | ]; 59 | 60 | Laravel::instance() 61 | ->setupView(__DIR__.'/views/', __DIR__.'/views/cache/compiled/') 62 | ->setupDatabase($connections) 63 | ->setupPagination() 64 | ->setupTracy([ 65 | 'showBar' => true 66 | ]); 67 | ``` 68 | 69 | eloquent 70 | 71 | ```php 72 | class User extends \Illuminate\Database\Eloquent\Model 73 | { 74 | protected $fillable = [ 75 | 'name', 76 | 'email', 77 | 'password', 78 | ]; 79 | } 80 | 81 | var_dump(User::all()); 82 | ``` 83 | 84 | view 85 | 86 | view.blade.php 87 | 88 | ```php 89 | @foreach ($rows as $row) 90 | {{ $row }}; 91 | @endforeach 92 | ``` 93 | 94 | view 95 | 96 | ```php 97 | echo View::make('view', ['rows' => [1, 2, 3]]); 98 | ``` 99 | 100 | ### Example 101 | 102 | [Laraigniter](https://github.com/recca0120/laraigniter) 103 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "recca0120/laravel-bridge", 3 | "description": "use laravel eloquent, view, pagination anywhere", 4 | "keywords": ["laravel", "artisan", "terminal", "console", "web", "web artisan"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "recca0120", 9 | "email": "recca0120@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.5.9", 14 | "illuminate/container": "^5.2", 15 | "illuminate/database": "^5.2", 16 | "illuminate/events": "^5.2", 17 | "illuminate/filesystem": "^5.2", 18 | "illuminate/http": "^5.2", 19 | "illuminate/pagination": "^5.2", 20 | "illuminate/support": "^5.2", 21 | "illuminate/view": "^5.2", 22 | "psr/container": "^1.0", 23 | "recca0120/laravel-tracy": "^1.5" 24 | }, 25 | "require-dev": { 26 | "illuminate/translation": "^5.2", 27 | "mockery/mockery": "~0.9.2", 28 | "nesbot/carbon": "~1.20", 29 | "php-coveralls/php-coveralls": "^2.1", 30 | "phpunit/phpunit": "^4 | ^5 | ^6", 31 | "psy/psysh": "^0.9.9", 32 | "squizlabs/php_codesniffer": "^3.4" 33 | }, 34 | "conflict": { 35 | "illuminate/contracts": "5.3.* | 5.4.*" 36 | }, 37 | "autoload": { 38 | "files": [ 39 | "src/helpers.php" 40 | ], 41 | "psr-4": { 42 | "Recca0120\\LaravelBridge\\": "src" 43 | } 44 | }, 45 | "autoload-dev": { 46 | "psr-4": { 47 | "Tests\\": "tests" 48 | } 49 | }, 50 | "config": { 51 | "preferred-install": "dist", 52 | "sort-packages": true, 53 | "optimize-autoloader": true 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /docs/logo.svg: -------------------------------------------------------------------------------- 1 | Laravel Bridge 2 | -------------------------------------------------------------------------------- /resources/views/pagination/bootstrap-4.blade.php: -------------------------------------------------------------------------------- 1 | @if ($paginator->hasPages()) 2 | 44 | @endif 45 | -------------------------------------------------------------------------------- /resources/views/pagination/default.blade.php: -------------------------------------------------------------------------------- 1 | @if ($paginator->hasPages()) 2 | 44 | @endif 45 | -------------------------------------------------------------------------------- /src/App.php: -------------------------------------------------------------------------------- 1 | register(); 43 | 44 | if (property_exists($provider, 'bindings')) { 45 | foreach ($provider->bindings as $key => $value) { 46 | $this->bind($key, $value); 47 | } 48 | } 49 | 50 | if (property_exists($provider, 'singletons')) { 51 | foreach ($provider->singletons as $key => $value) { 52 | $this->singleton($key, $value); 53 | } 54 | } 55 | 56 | $this->serviceProviders[$class] = $provider; 57 | 58 | return $provider; 59 | } 60 | 61 | public function boot() 62 | { 63 | array_walk($this->serviceProviders, function ($provider) { 64 | if (method_exists($provider, 'boot')) { 65 | $this->call([$provider, 'boot']); 66 | } 67 | }); 68 | } 69 | 70 | /** 71 | * @param string|mixed $provider 72 | * @return mixed 73 | */ 74 | public function getProvider($provider) 75 | { 76 | $name = is_string($provider) ? $provider : get_class($provider); 77 | 78 | $found = Arr::where($this->serviceProviders, function ($value) use ($name) { 79 | return $value instanceof $name; 80 | }); 81 | 82 | $values = array_values($found); 83 | 84 | return isset($values[0]) ? $values[0] : null; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Concerns/SetupLaravel.php: -------------------------------------------------------------------------------- 1 | filter(function ($provider) { 42 | return class_exists($provider); 43 | })->each(function ($provider) { 44 | $this->app->register($provider); 45 | }); 46 | } 47 | 48 | /** 49 | * setup user define provider. 50 | * 51 | * @param callable $callable The callable can return the instance of ServiceProvider 52 | * 53 | * @return static 54 | */ 55 | public function setupCallableProvider(callable $callable) 56 | { 57 | $serviceProvider = $callable($this->app); 58 | $serviceProvider->register(); 59 | 60 | if (method_exists($serviceProvider, 'boot') === true) { 61 | $this->call([$serviceProvider, 'boot']); 62 | } 63 | 64 | return $this; 65 | } 66 | 67 | /** 68 | * @param array $connections 69 | * @param string $default 70 | * @param int $fetch 71 | * 72 | * @return static 73 | */ 74 | public function setupDatabase(array $connections, $default = 'default', $fetch = PDO::FETCH_CLASS) 75 | { 76 | $this->app['config']['database.connections'] = $connections; 77 | $this->app['config']['database.default'] = $default; 78 | $this->app['config']['database.fetch'] = $fetch; 79 | 80 | return $this->bootProvider(DatabaseServiceProvider::class); 81 | } 82 | 83 | /** 84 | * @param string $locale 85 | * 86 | * @return static 87 | */ 88 | public function setupLocale($locale) 89 | { 90 | $this->app['config']['app.locale'] = $locale; 91 | 92 | return $this; 93 | } 94 | 95 | /** 96 | * @return static 97 | */ 98 | public function setupPagination() 99 | { 100 | if (! isset($this->app['path.lang'])) { 101 | // default pagination view without translation 102 | $this->app['view']->addNamespace('pagination', __DIR__.'/../../resources/views/pagination/'); 103 | } 104 | 105 | return $this->bootProvider(PaginationServiceProvider::class); 106 | } 107 | 108 | /** 109 | * @param string $langPath 110 | * 111 | * @return static 112 | */ 113 | public function setupTranslator($langPath) 114 | { 115 | $this->app->instance('path.lang', $langPath); 116 | 117 | return $this->bootProvider(TranslationServiceProvider::class); 118 | } 119 | 120 | /** 121 | * @param string|array $viewPath 122 | * @param string $compiledPath 123 | * 124 | * @return static 125 | */ 126 | public function setupView($viewPath, $compiledPath) 127 | { 128 | $this->app['config']['view.paths'] = is_array($viewPath) ? $viewPath : [$viewPath]; 129 | $this->app['config']['view.compiled'] = $compiledPath; 130 | 131 | return $this->bootProvider(ViewServiceProvider::class); 132 | } 133 | 134 | /** 135 | * @param string|mixed $provider 136 | * @return static 137 | */ 138 | public function bootProvider($provider) 139 | { 140 | $provider = $this->app->getProvider($provider); 141 | 142 | if (method_exists($provider, 'boot')) { 143 | $this->app->call([$provider, 'boot']); 144 | } 145 | 146 | return $this; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/Concerns/SetupTracy.php: -------------------------------------------------------------------------------- 1 | getPanel('database'); 19 | $this->getEvents()->listen(QueryExecuted::class, function ($event) use ($databasePanel) { 20 | $sql = $event->sql; 21 | $bindings = $event->bindings; 22 | $time = $event->time; 23 | $name = $event->connectionName; 24 | $pdo = $event->connection->getPdo(); 25 | 26 | $databasePanel->logQuery($sql, $bindings, $time, $name, $pdo); 27 | }); 28 | 29 | return $this; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Exceptions/EntryNotFoundException.php: -------------------------------------------------------------------------------- 1 | View::class, 37 | ]; 38 | 39 | /** 40 | * @var App 41 | */ 42 | private $app; 43 | 44 | /** 45 | * @var bool 46 | */ 47 | private $bootstrapped = false; 48 | 49 | public function __construct() 50 | { 51 | $this->app = new App(); 52 | } 53 | 54 | public function __call($method, $arguments) 55 | { 56 | if (method_exists($this->app, $method)) { 57 | return call_user_func_array([$this->app, $method], $arguments); 58 | } 59 | 60 | throw new BadMethodCallException("Undefined method '$method'"); 61 | } 62 | 63 | /** 64 | * @return static 65 | */ 66 | public function bootstrap() 67 | { 68 | if ($this->bootstrapped) { 69 | return $this; 70 | } 71 | 72 | $this->bootstrapped = true; 73 | 74 | $this->app->singleton('request', function () { 75 | return Request::capture(); 76 | }); 77 | 78 | $this->app->singleton('config', Fluent::class); 79 | $this->app->singleton('events', Dispatcher::class); 80 | $this->app->singleton('files', Filesystem::class); 81 | 82 | Facade::setFacadeApplication($this->app); 83 | 84 | $this->setupLaravelProviders(); 85 | 86 | foreach ($this->aliases as $alias => $class) { 87 | if (!class_exists($alias)) { 88 | class_alias($class, $alias); 89 | } 90 | } 91 | 92 | return $this; 93 | } 94 | 95 | /** 96 | * @return bool 97 | */ 98 | public function isBootstrapped() 99 | { 100 | return $this->bootstrapped; 101 | } 102 | 103 | /** 104 | * {@inheritDoc} 105 | */ 106 | public function has($id) 107 | { 108 | return $this->app->bound($id); 109 | } 110 | 111 | /** 112 | * {@inheritDoc} 113 | */ 114 | public function get($id) 115 | { 116 | try { 117 | return $this->app->make($id); 118 | } catch (Exception $e) { 119 | if ($this->has($id)) { 120 | throw $e; 121 | } 122 | 123 | throw new EntryNotFoundException("Entry '$id' is not found"); 124 | } 125 | } 126 | 127 | /** 128 | * getApp. 129 | * 130 | * @method getApp 131 | * 132 | * @return LaravelContainer 133 | */ 134 | public function getApp() 135 | { 136 | return $this->app; 137 | } 138 | 139 | /** 140 | * @return Request 141 | */ 142 | public function getRequest() 143 | { 144 | return $this->app->make('request'); 145 | } 146 | 147 | /** 148 | * @return Dispatcher 149 | */ 150 | public function getEvents() 151 | { 152 | return $this->app->make('events'); 153 | } 154 | 155 | /** 156 | * @return Fluent 157 | */ 158 | public function getConfig() 159 | { 160 | return $this->app->make('config'); 161 | } 162 | 163 | /** 164 | * @param bool $is 165 | * 166 | * @return static 167 | */ 168 | public function setupRunningInConsole($is = true) 169 | { 170 | $this->app['runningInConsole'] = $is; 171 | 172 | return $this; 173 | } 174 | 175 | /** 176 | * @return static 177 | * @deprecated use getInstance() 178 | */ 179 | public static function instance() 180 | { 181 | return static::getInstance(); 182 | } 183 | 184 | /** 185 | * @return static 186 | */ 187 | public static function getInstance() 188 | { 189 | if (null === static::$instance) { 190 | static::$instance = new static(); 191 | } 192 | 193 | if (!static::$instance->isBootstrapped()) { 194 | static::$instance->bootstrap(); 195 | } 196 | 197 | return static::$instance; 198 | } 199 | 200 | /** 201 | * Flash instance 202 | */ 203 | public static function flashInstance() 204 | { 205 | $instance = static::getInstance(); 206 | 207 | $instance->flush(); 208 | $instance->bootstrapped = false; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | make($abstract, $parameters); 20 | } 21 | } 22 | --------------------------------------------------------------------------------