Commit 2e5caa15 by hcy001

1

parent 17d4adeb
Showing with 2870 additions and 3 deletions
...@@ -25,6 +25,12 @@ class HdController extends Controller ...@@ -25,6 +25,12 @@ class HdController extends Controller
//添加参数 //添加参数
private function cf(){ private function cf(){
$mongo = \DB::connection("mongodbs")
->collection("spu")
// ->where("****","***")
->first();
print_r($mongo);
die();
$param = [ $param = [
["spu_name"=>"RCP0603W110RGS3","brand_name"=>"vishay"] ["spu_name"=>"RCP0603W110RGS3","brand_name"=>"vishay"]
]; ];
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
"vladimir-yuldashev/laravel-queue-rabbitmq": "5.2", "vladimir-yuldashev/laravel-queue-rabbitmq": "5.2",
"artisaninweb/laravel-soap": "0.2.*", "artisaninweb/laravel-soap": "0.2.*",
"hprose/hprose": "^2.0", "hprose/hprose": "^2.0",
"barryvdh/laravel-dompdf": "^0.8.2" "barryvdh/laravel-dompdf": "^0.8.2",
"jenssegers/mongodb": "2.3"
}, },
"require-dev": { "require-dev": {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "758b5dc4d97e06149cb8a2a50dcf0487", "content-hash": "98f95b32ed02c6f50300f4c0347aff51",
"packages": [ "packages": [
{ {
"name": "artisaninweb/laravel-soap", "name": "artisaninweb/laravel-soap",
...@@ -672,6 +672,64 @@ ...@@ -672,6 +672,64 @@
"time": "2015-04-20T18:58:01+00:00" "time": "2015-04-20T18:58:01+00:00"
}, },
{ {
"name": "jenssegers/mongodb",
"version": "v2.3.0",
"source": {
"type": "git",
"url": "https://github.com/jenssegers/laravel-mongodb.git",
"reference": "22063084ea4370c3865b2364f56d0508f09ec4e8"
},
"dist": {
"type": "zip",
"url": "https://repo.huaweicloud.com/repository/php/dist/jenssegers/mongodb/jenssegers-mongodb-v2.3.0-22063084.zip",
"reference": "22063084ea4370c3865b2364f56d0508f09ec4e8",
"shasum": "2d4d44926acd4fe21db31e529f64b537c59242c7"
},
"require": {
"illuminate/container": "^5.1",
"illuminate/database": "^5.1",
"illuminate/events": "^5.1",
"illuminate/support": "^5.1"
},
"require-dev": {
"mockery/mockery": "^0.9",
"orchestra/testbench": "^3.1",
"phpunit/phpunit": "^4.0|^5.0",
"satooshi/php-coveralls": "^0.6"
},
"suggest": {
"jenssegers/mongodb-sentry": "Add Sentry support to Laravel-MongoDB",
"jenssegers/mongodb-session": "Add MongoDB session support to Laravel-MongoDB"
},
"type": "library",
"autoload": {
"psr-0": {
"Jenssegers\\Mongodb": "src/",
"Jenssegers\\Eloquent": "src/"
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Jens Segers",
"homepage": "https://jenssegers.com"
}
],
"description": "A MongoDB based Eloquent model and Query builder for Laravel 4",
"homepage": "https://github.com/jenssegers/laravel-mongodb",
"keywords": [
"database",
"eloquent",
"laravel",
"model",
"mongo",
"mongodb"
],
"time": "2016-02-03T23:25:16+00:00"
},
{
"name": "jeremeamia/SuperClosure", "name": "jeremeamia/SuperClosure",
"version": "2.4.0", "version": "2.4.0",
"source": { "source": {
...@@ -2876,6 +2934,7 @@ ...@@ -2876,6 +2934,7 @@
"faker", "faker",
"fixtures" "fixtures"
], ],
"abandoned": true,
"time": "2017-08-15T16:48:10+00:00" "time": "2017-08-15T16:48:10+00:00"
}, },
{ {
......
...@@ -162,6 +162,7 @@ return [ ...@@ -162,6 +162,7 @@ return [
Artisaninweb\SoapWrapper\ServiceProvider::class, Artisaninweb\SoapWrapper\ServiceProvider::class,
Barryvdh\DomPDF\ServiceProvider::class, Barryvdh\DomPDF\ServiceProvider::class,
Jenssegers\Mongodb\MongodbServiceProvider::class,
], ],
...@@ -211,6 +212,7 @@ return [ ...@@ -211,6 +212,7 @@ return [
'Excel' => Maatwebsite\Excel\Facades\Excel::class, 'Excel' => Maatwebsite\Excel\Facades\Excel::class,
'SoapWrapper' => Artisaninweb\SoapWrapper\Facades\SoapWrapper::class, 'SoapWrapper' => Artisaninweb\SoapWrapper\Facades\SoapWrapper::class,
'PDF' => Barryvdh\DomPDF\Facade::class 'PDF' => Barryvdh\DomPDF\Facade::class
], ],
]; ];
...@@ -122,6 +122,17 @@ return [ ...@@ -122,6 +122,17 @@ return [
'password' => env('RABBITMQ_PASSWORD', 'guest'), 'password' => env('RABBITMQ_PASSWORD', 'guest'),
'queue' => env('RABBITMQ_QUEUE'), // name of the default queue, 'queue' => env('RABBITMQ_QUEUE'), // name of the default queue,
], ],
'mongodbs' => [
'driver' => 'mongodb',
'host' => env('DB_MONGO_HOST', ''),
'database' => env('DB_MONGO_DATABASE', ''),
'username' => env('DB_MONGO_USERNAME', ''),
'password' => env('DB_MONGO_PASSWORD', ''),
'port' => env('DB_MONGO_PORT', 27017),
// 'options' => [
// 'database' => 'ichunt' // sets the authentication database required by mongo 3
// ]
],
], ],
/* /*
......
<?php <?php
ini_set('mongo.long_as_object', 1);
/** /**
* Laravel - A PHP Framework For Web Artisans * Laravel - A PHP Framework For Web Artisans
* *
......
...@@ -23,18 +23,23 @@ return array( ...@@ -23,18 +23,23 @@ return array(
'App\\Http\\Controllers\\WebController' => $baseDir . '/app/Http/Controllers/WebController.php', 'App\\Http\\Controllers\\WebController' => $baseDir . '/app/Http/Controllers/WebController.php',
'App\\Http\\Kernel' => $baseDir . '/app/Http/Kernel.php', 'App\\Http\\Kernel' => $baseDir . '/app/Http/Kernel.php',
'App\\Http\\Middleware\\CheckLogin' => $baseDir . '/app/Http/Middleware/CheckLogin.php', 'App\\Http\\Middleware\\CheckLogin' => $baseDir . '/app/Http/Middleware/CheckLogin.php',
'App\\Http\\Middleware\\EnableCrossRequestMiddleware' => $baseDir . '/app/Http/Middleware/EnableCrossRequestMiddleware.php',
'App\\Http\\Middleware\\JsonpCallback' => $baseDir . '/app/Http/Middleware/JsonpCallback.php', 'App\\Http\\Middleware\\JsonpCallback' => $baseDir . '/app/Http/Middleware/JsonpCallback.php',
'App\\Http\\Middleware\\WmsVerification' => $baseDir . '/app/Http/Middleware/WmsVerification.php', 'App\\Http\\Middleware\\WmsVerification' => $baseDir . '/app/Http/Middleware/WmsVerification.php',
'App\\Http\\Requests\\Request' => $baseDir . '/app/Http/Requests/Request.php', 'App\\Http\\Requests\\Request' => $baseDir . '/app/Http/Requests/Request.php',
'App\\Jobs\\Job' => $baseDir . '/app/Jobs/Job.php', 'App\\Jobs\\Job' => $baseDir . '/app/Jobs/Job.php',
'App\\Model\\CmsModel' => $baseDir . '/app/Model/CmsModel.php',
'App\\Model\\CommonModel' => $baseDir . '/app/Model/CommonModel.php', 'App\\Model\\CommonModel' => $baseDir . '/app/Model/CommonModel.php',
'App\\Model\\InquiryItemsAssignModel' => $baseDir . '/app/Model/InquiryItemsAssignModel.php', 'App\\Model\\InquiryItemsAssignModel' => $baseDir . '/app/Model/InquiryItemsAssignModel.php',
'App\\Model\\InquiryItemsModel' => $baseDir . '/app/Model/InquiryItemsModel.php', 'App\\Model\\InquiryItemsModel' => $baseDir . '/app/Model/InquiryItemsModel.php',
'App\\Model\\InquiryItemsReportModel' => $baseDir . '/app/Model/InquiryItemsReportModel.php', 'App\\Model\\InquiryItemsReportModel' => $baseDir . '/app/Model/InquiryItemsReportModel.php',
'App\\Model\\InquiryItemsUrgeModel' => $baseDir . '/app/Model/InquiryItemsUrgeModel.php', 'App\\Model\\InquiryItemsUrgeModel' => $baseDir . '/app/Model/InquiryItemsUrgeModel.php',
'App\\Model\\InquiryModel' => $baseDir . '/app/Model/InquiryModel.php', 'App\\Model\\InquiryModel' => $baseDir . '/app/Model/InquiryModel.php',
'App\\Model\\InquiryUsersModel' => $baseDir . '/app/Model/InquiryUsersModel.php',
'App\\Model\\LoginModel' => $baseDir . '/app/Model/LoginModel.php',
'App\\Model\\OpLogModel' => $baseDir . '/app/Model/OpLogModel.php', 'App\\Model\\OpLogModel' => $baseDir . '/app/Model/OpLogModel.php',
'App\\Model\\QuoteModel' => $baseDir . '/app/Model/QuoteModel.php', 'App\\Model\\QuoteModel' => $baseDir . '/app/Model/QuoteModel.php',
'App\\Model\\SearchModel' => $baseDir . '/app/Model/SearchModel.php',
'App\\Model\\Server\\ExportModel' => $baseDir . '/app/Model/ExportModel.php', 'App\\Model\\Server\\ExportModel' => $baseDir . '/app/Model/ExportModel.php',
'App\\Model\\Server\\GoModel' => $baseDir . '/app/Model/GoModel.php', 'App\\Model\\Server\\GoModel' => $baseDir . '/app/Model/GoModel.php',
'App\\Model\\SupplierChannelComModel' => $baseDir . '/app/Model/SupplierChannelComModel.php', 'App\\Model\\SupplierChannelComModel' => $baseDir . '/app/Model/SupplierChannelComModel.php',
...@@ -1387,6 +1392,29 @@ return array( ...@@ -1387,6 +1392,29 @@ return array(
'JakubOnderka\\PhpConsoleColor\\ConsoleColor' => $vendorDir . '/jakub-onderka/php-console-color/src/JakubOnderka/PhpConsoleColor/ConsoleColor.php', 'JakubOnderka\\PhpConsoleColor\\ConsoleColor' => $vendorDir . '/jakub-onderka/php-console-color/src/JakubOnderka/PhpConsoleColor/ConsoleColor.php',
'JakubOnderka\\PhpConsoleColor\\InvalidStyleException' => $vendorDir . '/jakub-onderka/php-console-color/src/JakubOnderka/PhpConsoleColor/InvalidStyleException.php', 'JakubOnderka\\PhpConsoleColor\\InvalidStyleException' => $vendorDir . '/jakub-onderka/php-console-color/src/JakubOnderka/PhpConsoleColor/InvalidStyleException.php',
'JakubOnderka\\PhpConsoleHighlighter\\Highlighter' => $vendorDir . '/jakub-onderka/php-console-highlighter/src/JakubOnderka/PhpConsoleHighlighter/Highlighter.php', 'JakubOnderka\\PhpConsoleHighlighter\\Highlighter' => $vendorDir . '/jakub-onderka/php-console-highlighter/src/JakubOnderka/PhpConsoleHighlighter/Highlighter.php',
'Jenssegers\\Eloquent\\Model' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Eloquent/Model.php',
'Jenssegers\\Mongodb\\Auth\\DatabaseTokenRepository' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php',
'Jenssegers\\Mongodb\\Auth\\PasswordResetServiceProvider' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php',
'Jenssegers\\Mongodb\\Collection' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Collection.php',
'Jenssegers\\Mongodb\\Connection' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Connection.php',
'Jenssegers\\Mongodb\\Eloquent\\Builder' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Eloquent/Builder.php',
'Jenssegers\\Mongodb\\Eloquent\\HybridRelations' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Eloquent/HybridRelations.php',
'Jenssegers\\Mongodb\\Eloquent\\SoftDeletes' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Eloquent/SoftDeletes.php',
'Jenssegers\\Mongodb\\Model' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Model.php',
'Jenssegers\\Mongodb\\MongodbServiceProvider' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/MongodbServiceProvider.php',
'Jenssegers\\Mongodb\\Query\\Builder' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Builder.php',
'Jenssegers\\Mongodb\\Query\\Grammar' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Grammar.php',
'Jenssegers\\Mongodb\\Query\\Processor' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Processor.php',
'Jenssegers\\Mongodb\\Relations\\BelongsTo' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/BelongsTo.php',
'Jenssegers\\Mongodb\\Relations\\BelongsToMany' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/BelongsToMany.php',
'Jenssegers\\Mongodb\\Relations\\EmbedsMany' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/EmbedsMany.php',
'Jenssegers\\Mongodb\\Relations\\EmbedsOne' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/EmbedsOne.php',
'Jenssegers\\Mongodb\\Relations\\EmbedsOneOrMany' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php',
'Jenssegers\\Mongodb\\Relations\\HasMany' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/HasMany.php',
'Jenssegers\\Mongodb\\Relations\\HasOne' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/HasOne.php',
'Jenssegers\\Mongodb\\Relations\\MorphTo' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/MorphTo.php',
'Jenssegers\\Mongodb\\Schema\\Blueprint' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Blueprint.php',
'Jenssegers\\Mongodb\\Schema\\Builder' => $vendorDir . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Builder.php',
'JsonSerializable' => $vendorDir . '/nesbot/carbon/src/JsonSerializable.php', 'JsonSerializable' => $vendorDir . '/nesbot/carbon/src/JsonSerializable.php',
'League\\Flysystem\\AdapterInterface' => $vendorDir . '/league/flysystem/src/AdapterInterface.php', 'League\\Flysystem\\AdapterInterface' => $vendorDir . '/league/flysystem/src/AdapterInterface.php',
'League\\Flysystem\\Adapter\\AbstractAdapter' => $vendorDir . '/league/flysystem/src/Adapter/AbstractAdapter.php', 'League\\Flysystem\\Adapter\\AbstractAdapter' => $vendorDir . '/league/flysystem/src/Adapter/AbstractAdapter.php',
......
...@@ -12,6 +12,8 @@ return array( ...@@ -12,6 +12,8 @@ return array(
'PHPExcel' => array($vendorDir . '/phpoffice/phpexcel/Classes'), 'PHPExcel' => array($vendorDir . '/phpoffice/phpexcel/Classes'),
'Mockery' => array($vendorDir . '/mockery/mockery/library'), 'Mockery' => array($vendorDir . '/mockery/mockery/library'),
'Maatwebsite\\Excel\\' => array($vendorDir . '/maatwebsite/excel/src'), 'Maatwebsite\\Excel\\' => array($vendorDir . '/maatwebsite/excel/src'),
'Jenssegers\\Mongodb' => array($vendorDir . '/jenssegers/mongodb/src'),
'Jenssegers\\Eloquent' => array($vendorDir . '/jenssegers/mongodb/src'),
'JakubOnderka\\PhpConsoleHighlighter' => array($vendorDir . '/jakub-onderka/php-console-highlighter/src'), 'JakubOnderka\\PhpConsoleHighlighter' => array($vendorDir . '/jakub-onderka/php-console-highlighter/src'),
'JakubOnderka\\PhpConsoleColor' => array($vendorDir . '/jakub-onderka/php-console-color/src'), 'JakubOnderka\\PhpConsoleColor' => array($vendorDir . '/jakub-onderka/php-console-color/src'),
'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'), 'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'),
......
...@@ -341,6 +341,14 @@ class ComposerStaticInitfbba5c913d657e1c2bf0c2ab261712a7 ...@@ -341,6 +341,14 @@ class ComposerStaticInitfbba5c913d657e1c2bf0c2ab261712a7
), ),
'J' => 'J' =>
array ( array (
'Jenssegers\\Mongodb' =>
array (
0 => __DIR__ . '/..' . '/jenssegers/mongodb/src',
),
'Jenssegers\\Eloquent' =>
array (
0 => __DIR__ . '/..' . '/jenssegers/mongodb/src',
),
'JakubOnderka\\PhpConsoleHighlighter' => 'JakubOnderka\\PhpConsoleHighlighter' =>
array ( array (
0 => __DIR__ . '/..' . '/jakub-onderka/php-console-highlighter/src', 0 => __DIR__ . '/..' . '/jakub-onderka/php-console-highlighter/src',
...@@ -384,18 +392,23 @@ class ComposerStaticInitfbba5c913d657e1c2bf0c2ab261712a7 ...@@ -384,18 +392,23 @@ class ComposerStaticInitfbba5c913d657e1c2bf0c2ab261712a7
'App\\Http\\Controllers\\WebController' => __DIR__ . '/../..' . '/app/Http/Controllers/WebController.php', 'App\\Http\\Controllers\\WebController' => __DIR__ . '/../..' . '/app/Http/Controllers/WebController.php',
'App\\Http\\Kernel' => __DIR__ . '/../..' . '/app/Http/Kernel.php', 'App\\Http\\Kernel' => __DIR__ . '/../..' . '/app/Http/Kernel.php',
'App\\Http\\Middleware\\CheckLogin' => __DIR__ . '/../..' . '/app/Http/Middleware/CheckLogin.php', 'App\\Http\\Middleware\\CheckLogin' => __DIR__ . '/../..' . '/app/Http/Middleware/CheckLogin.php',
'App\\Http\\Middleware\\EnableCrossRequestMiddleware' => __DIR__ . '/../..' . '/app/Http/Middleware/EnableCrossRequestMiddleware.php',
'App\\Http\\Middleware\\JsonpCallback' => __DIR__ . '/../..' . '/app/Http/Middleware/JsonpCallback.php', 'App\\Http\\Middleware\\JsonpCallback' => __DIR__ . '/../..' . '/app/Http/Middleware/JsonpCallback.php',
'App\\Http\\Middleware\\WmsVerification' => __DIR__ . '/../..' . '/app/Http/Middleware/WmsVerification.php', 'App\\Http\\Middleware\\WmsVerification' => __DIR__ . '/../..' . '/app/Http/Middleware/WmsVerification.php',
'App\\Http\\Requests\\Request' => __DIR__ . '/../..' . '/app/Http/Requests/Request.php', 'App\\Http\\Requests\\Request' => __DIR__ . '/../..' . '/app/Http/Requests/Request.php',
'App\\Jobs\\Job' => __DIR__ . '/../..' . '/app/Jobs/Job.php', 'App\\Jobs\\Job' => __DIR__ . '/../..' . '/app/Jobs/Job.php',
'App\\Model\\CmsModel' => __DIR__ . '/../..' . '/app/Model/CmsModel.php',
'App\\Model\\CommonModel' => __DIR__ . '/../..' . '/app/Model/CommonModel.php', 'App\\Model\\CommonModel' => __DIR__ . '/../..' . '/app/Model/CommonModel.php',
'App\\Model\\InquiryItemsAssignModel' => __DIR__ . '/../..' . '/app/Model/InquiryItemsAssignModel.php', 'App\\Model\\InquiryItemsAssignModel' => __DIR__ . '/../..' . '/app/Model/InquiryItemsAssignModel.php',
'App\\Model\\InquiryItemsModel' => __DIR__ . '/../..' . '/app/Model/InquiryItemsModel.php', 'App\\Model\\InquiryItemsModel' => __DIR__ . '/../..' . '/app/Model/InquiryItemsModel.php',
'App\\Model\\InquiryItemsReportModel' => __DIR__ . '/../..' . '/app/Model/InquiryItemsReportModel.php', 'App\\Model\\InquiryItemsReportModel' => __DIR__ . '/../..' . '/app/Model/InquiryItemsReportModel.php',
'App\\Model\\InquiryItemsUrgeModel' => __DIR__ . '/../..' . '/app/Model/InquiryItemsUrgeModel.php', 'App\\Model\\InquiryItemsUrgeModel' => __DIR__ . '/../..' . '/app/Model/InquiryItemsUrgeModel.php',
'App\\Model\\InquiryModel' => __DIR__ . '/../..' . '/app/Model/InquiryModel.php', 'App\\Model\\InquiryModel' => __DIR__ . '/../..' . '/app/Model/InquiryModel.php',
'App\\Model\\InquiryUsersModel' => __DIR__ . '/../..' . '/app/Model/InquiryUsersModel.php',
'App\\Model\\LoginModel' => __DIR__ . '/../..' . '/app/Model/LoginModel.php',
'App\\Model\\OpLogModel' => __DIR__ . '/../..' . '/app/Model/OpLogModel.php', 'App\\Model\\OpLogModel' => __DIR__ . '/../..' . '/app/Model/OpLogModel.php',
'App\\Model\\QuoteModel' => __DIR__ . '/../..' . '/app/Model/QuoteModel.php', 'App\\Model\\QuoteModel' => __DIR__ . '/../..' . '/app/Model/QuoteModel.php',
'App\\Model\\SearchModel' => __DIR__ . '/../..' . '/app/Model/SearchModel.php',
'App\\Model\\Server\\ExportModel' => __DIR__ . '/../..' . '/app/Model/ExportModel.php', 'App\\Model\\Server\\ExportModel' => __DIR__ . '/../..' . '/app/Model/ExportModel.php',
'App\\Model\\Server\\GoModel' => __DIR__ . '/../..' . '/app/Model/GoModel.php', 'App\\Model\\Server\\GoModel' => __DIR__ . '/../..' . '/app/Model/GoModel.php',
'App\\Model\\SupplierChannelComModel' => __DIR__ . '/../..' . '/app/Model/SupplierChannelComModel.php', 'App\\Model\\SupplierChannelComModel' => __DIR__ . '/../..' . '/app/Model/SupplierChannelComModel.php',
...@@ -1748,6 +1761,29 @@ class ComposerStaticInitfbba5c913d657e1c2bf0c2ab261712a7 ...@@ -1748,6 +1761,29 @@ class ComposerStaticInitfbba5c913d657e1c2bf0c2ab261712a7
'JakubOnderka\\PhpConsoleColor\\ConsoleColor' => __DIR__ . '/..' . '/jakub-onderka/php-console-color/src/JakubOnderka/PhpConsoleColor/ConsoleColor.php', 'JakubOnderka\\PhpConsoleColor\\ConsoleColor' => __DIR__ . '/..' . '/jakub-onderka/php-console-color/src/JakubOnderka/PhpConsoleColor/ConsoleColor.php',
'JakubOnderka\\PhpConsoleColor\\InvalidStyleException' => __DIR__ . '/..' . '/jakub-onderka/php-console-color/src/JakubOnderka/PhpConsoleColor/InvalidStyleException.php', 'JakubOnderka\\PhpConsoleColor\\InvalidStyleException' => __DIR__ . '/..' . '/jakub-onderka/php-console-color/src/JakubOnderka/PhpConsoleColor/InvalidStyleException.php',
'JakubOnderka\\PhpConsoleHighlighter\\Highlighter' => __DIR__ . '/..' . '/jakub-onderka/php-console-highlighter/src/JakubOnderka/PhpConsoleHighlighter/Highlighter.php', 'JakubOnderka\\PhpConsoleHighlighter\\Highlighter' => __DIR__ . '/..' . '/jakub-onderka/php-console-highlighter/src/JakubOnderka/PhpConsoleHighlighter/Highlighter.php',
'Jenssegers\\Eloquent\\Model' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Eloquent/Model.php',
'Jenssegers\\Mongodb\\Auth\\DatabaseTokenRepository' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php',
'Jenssegers\\Mongodb\\Auth\\PasswordResetServiceProvider' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php',
'Jenssegers\\Mongodb\\Collection' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Collection.php',
'Jenssegers\\Mongodb\\Connection' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Connection.php',
'Jenssegers\\Mongodb\\Eloquent\\Builder' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Eloquent/Builder.php',
'Jenssegers\\Mongodb\\Eloquent\\HybridRelations' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Eloquent/HybridRelations.php',
'Jenssegers\\Mongodb\\Eloquent\\SoftDeletes' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Eloquent/SoftDeletes.php',
'Jenssegers\\Mongodb\\Model' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Model.php',
'Jenssegers\\Mongodb\\MongodbServiceProvider' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/MongodbServiceProvider.php',
'Jenssegers\\Mongodb\\Query\\Builder' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Builder.php',
'Jenssegers\\Mongodb\\Query\\Grammar' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Grammar.php',
'Jenssegers\\Mongodb\\Query\\Processor' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Processor.php',
'Jenssegers\\Mongodb\\Relations\\BelongsTo' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/BelongsTo.php',
'Jenssegers\\Mongodb\\Relations\\BelongsToMany' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/BelongsToMany.php',
'Jenssegers\\Mongodb\\Relations\\EmbedsMany' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/EmbedsMany.php',
'Jenssegers\\Mongodb\\Relations\\EmbedsOne' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/EmbedsOne.php',
'Jenssegers\\Mongodb\\Relations\\EmbedsOneOrMany' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php',
'Jenssegers\\Mongodb\\Relations\\HasMany' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/HasMany.php',
'Jenssegers\\Mongodb\\Relations\\HasOne' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/HasOne.php',
'Jenssegers\\Mongodb\\Relations\\MorphTo' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/MorphTo.php',
'Jenssegers\\Mongodb\\Schema\\Blueprint' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Blueprint.php',
'Jenssegers\\Mongodb\\Schema\\Builder' => __DIR__ . '/..' . '/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Builder.php',
'JsonSerializable' => __DIR__ . '/..' . '/nesbot/carbon/src/JsonSerializable.php', 'JsonSerializable' => __DIR__ . '/..' . '/nesbot/carbon/src/JsonSerializable.php',
'League\\Flysystem\\AdapterInterface' => __DIR__ . '/..' . '/league/flysystem/src/AdapterInterface.php', 'League\\Flysystem\\AdapterInterface' => __DIR__ . '/..' . '/league/flysystem/src/AdapterInterface.php',
'League\\Flysystem\\Adapter\\AbstractAdapter' => __DIR__ . '/..' . '/league/flysystem/src/Adapter/AbstractAdapter.php', 'League\\Flysystem\\Adapter\\AbstractAdapter' => __DIR__ . '/..' . '/league/flysystem/src/Adapter/AbstractAdapter.php',
......
...@@ -845,6 +845,66 @@ ...@@ -845,6 +845,66 @@
"abandoned": "php-parallel-lint/php-console-highlighter" "abandoned": "php-parallel-lint/php-console-highlighter"
}, },
{ {
"name": "jenssegers/mongodb",
"version": "v2.3.0",
"version_normalized": "2.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/jenssegers/laravel-mongodb.git",
"reference": "22063084ea4370c3865b2364f56d0508f09ec4e8"
},
"dist": {
"type": "zip",
"url": "https://repo.huaweicloud.com/repository/php/dist/jenssegers/mongodb/jenssegers-mongodb-v2.3.0-22063084.zip",
"reference": "22063084ea4370c3865b2364f56d0508f09ec4e8",
"shasum": "2d4d44926acd4fe21db31e529f64b537c59242c7"
},
"require": {
"illuminate/container": "^5.1",
"illuminate/database": "^5.1",
"illuminate/events": "^5.1",
"illuminate/support": "^5.1"
},
"require-dev": {
"mockery/mockery": "^0.9",
"orchestra/testbench": "^3.1",
"phpunit/phpunit": "^4.0|^5.0",
"satooshi/php-coveralls": "^0.6"
},
"suggest": {
"jenssegers/mongodb-sentry": "Add Sentry support to Laravel-MongoDB",
"jenssegers/mongodb-session": "Add MongoDB session support to Laravel-MongoDB"
},
"time": "2016-02-03T23:25:16+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Jenssegers\\Mongodb": "src/",
"Jenssegers\\Eloquent": "src/"
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Jens Segers",
"homepage": "https://jenssegers.com"
}
],
"description": "A MongoDB based Eloquent model and Query builder for Laravel 4",
"homepage": "https://github.com/jenssegers/laravel-mongodb",
"keywords": [
"database",
"eloquent",
"laravel",
"model",
"mongo",
"mongodb"
]
},
{
"name": "jeremeamia/SuperClosure", "name": "jeremeamia/SuperClosure",
"version": "2.4.0", "version": "2.4.0",
"version_normalized": "2.4.0.0", "version_normalized": "2.4.0.0",
......
{
"name": "jenssegers/mongodb",
"description": "A MongoDB based Eloquent model and Query builder for Laravel 4",
"keywords": ["laravel","eloquent","mongodb","mongo","database","model"],
"homepage": "https://github.com/jenssegers/laravel-mongodb",
"authors": [
{
"name": "Jens Segers",
"homepage": "https://jenssegers.com"
}
],
"license" : "MIT",
"require": {
"illuminate/support": "^5.1",
"illuminate/container": "^5.1",
"illuminate/database": "^5.1",
"illuminate/events": "^5.1"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0",
"orchestra/testbench": "^3.1",
"mockery/mockery": "^0.9",
"satooshi/php-coveralls": "^0.6"
},
"autoload": {
"psr-0": {
"Jenssegers\\Mongodb": "src/",
"Jenssegers\\Eloquent": "src/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php",
"tests/models",
"tests/seeds"
]
},
"suggest": {
"jenssegers/mongodb-session": "Add MongoDB session support to Laravel-MongoDB",
"jenssegers/mongodb-sentry": "Add Sentry support to Laravel-MongoDB"
}
}
<?php namespace Jenssegers\Eloquent;
use Jenssegers\Mongodb\Eloquent\HybridRelations;
abstract class Model extends \Illuminate\Database\Eloquent\Model
{
use HybridRelations;
}
<?php namespace Jenssegers\Mongodb\Auth;
use DateTime;
use MongoDate;
class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository
{
/**
* Build the record payload for the table.
*
* @param string $email
* @param string $token
* @return array
*/
protected function getPayload($email, $token)
{
return ['email' => $email, 'token' => $token, 'created_at' => new MongoDate];
}
/**
* Determine if the token has expired.
*
* @param array $token
* @return bool
*/
protected function tokenExpired($token)
{
// Convert MongoDate to a date string.
if ($token['created_at'] instanceof MongoDate) {
$date = new DateTime;
$date->setTimestamp($token['created_at']->sec);
$token['created_at'] = $date->format('Y-m-d H:i:s');
} elseif (is_array($token['created_at']) and isset($token['created_at']['date'])) {
$token['created_at'] = $token['created_at']['date'];
}
return parent::tokenExpired($token);
}
}
<?php namespace Jenssegers\Mongodb\Auth;
use Jenssegers\Mongodb\Auth\DatabaseTokenRepository as DbRepository;
class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider
{
/**
* Register the token repository implementation.
*
* @return void
*/
protected function registerTokenRepository()
{
$this->app->singleton('auth.password.tokens', function ($app) {
$connection = $app['db']->connection();
// The database token repository is an implementation of the token repository
// interface, and is responsible for the actual storing of auth tokens and
// their e-mail addresses. We will inject this table and hash key to it.
$table = $app['config']['auth.password.table'];
$key = $app['config']['app.key'];
$expire = $app['config']->get('auth.password.expire', 60);
return new DbRepository($connection, $table, $key, $expire);
});
}
}
<?php namespace Jenssegers\Mongodb;
use Exception;
use MongoCollection;
class Collection
{
/**
* The connection instance.
*
* @var Connection
*/
protected $connection;
/**
* The MongoCollection instance..
*
* @var MongoCollection
*/
protected $collection;
/**
* Constructor.
*/
public function __construct(Connection $connection, MongoCollection $collection)
{
$this->connection = $connection;
$this->collection = $collection;
}
/**
* Handle dynamic method calls.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
$start = microtime(true);
$result = call_user_func_array([$this->collection, $method], $parameters);
if ($this->connection->logging()) {
// Once we have run the query we will calculate the time that it took to run and
// then log the query, bindings, and execution time so we will report them on
// the event that the developer needs them. We'll log time in milliseconds.
$time = $this->connection->getElapsedTime($start);
$query = [];
// Convert the query paramters to a json string.
foreach ($parameters as $parameter) {
try {
$query[] = json_encode($parameter);
} catch (Exception $e) {
$query[] = '{...}';
}
}
$queryString = $this->collection->getName() . '.' . $method . '(' . implode(',', $query) . ')';
$this->connection->logQuery($queryString, [], $time);
}
return $result;
}
}
<?php namespace Jenssegers\Mongodb;
use MongoClient;
class Connection extends \Illuminate\Database\Connection
{
/**
* The MongoDB database handler.
*
* @var MongoDB
*/
protected $db;
/**
* The MongoClient connection handler.
*
* @var MongoClient
*/
protected $connection;
/**
* Create a new database connection instance.
*
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
// Build the connection string
$dsn = $this->getDsn($config);
// You can pass options directly to the MongoClient constructor
$options = array_get($config, 'options', []);
// Create the connection
$this->connection = $this->createConnection($dsn, $config, $options);
// Select database
$this->db = $this->connection->{$config['database']};
$this->useDefaultPostProcessor();
}
/**
* Get the default post processor instance.
*
* @return Query\Processor
*/
protected function getDefaultPostProcessor()
{
return new Query\Processor;
}
/**
* Begin a fluent query against a database collection.
*
* @param string $collection
* @return QueryBuilder
*/
public function collection($collection)
{
$processor = $this->getPostProcessor();
$query = new Query\Builder($this, $processor);
return $query->from($collection);
}
/**
* Begin a fluent query against a database collection.
*
* @param string $table
* @return QueryBuilder
*/
public function table($table)
{
return $this->collection($table);
}
/**
* Get a MongoDB collection.
*
* @param string $name
* @return MongoDB
*/
public function getCollection($name)
{
return new Collection($this, $this->db->selectCollection($name));
}
/**
* Get a schema builder instance for the connection.
*
* @return Schema\Builder
*/
public function getSchemaBuilder()
{
return new Schema\Builder($this);
}
/**
* Get the MongoDB database object.
*
* @return MongoDB
*/
public function getMongoDB()
{
return $this->db;
}
/**
* return MongoClient object.
*
* @return MongoClient
*/
public function getMongoClient()
{
return $this->connection;
}
/**
* Create a new MongoClient connection.
*
* @param string $dsn
* @param array $config
* @param array $options
* @return MongoClient
*/
protected function createConnection($dsn, array $config, array $options)
{
// Add credentials as options, this makes sure the connection will not fail if
// the username or password contains strange characters.
if (! empty($config['username'])) {
$options['username'] = $config['username'];
}
if (! empty($config['password'])) {
$options['password'] = $config['password'];
}
// By default driver options is an empty array.
$driverOptions = [];
if (isset($config['driver_options']) && is_array($config['driver_options'])) {
$driverOptions = $config['driver_options'];
}
return new MongoClient($dsn, $options, $driverOptions);
}
/**
* Disconnect from the underlying MongoClient connection.
*/
public function disconnect()
{
$this->connection->close();
}
/**
* Create a DSN string from a configuration.
*
* @param array $config
* @return string
*/
protected function getDsn(array $config)
{
// First we will create the basic DSN setup as well as the port if it is in
// in the configuration options. This will give us the basic DSN we will
// need to establish the MongoClient and return them back for use.
extract($config);
// Check if the user passed a complete dsn to the configuration.
if (! empty($dsn)) {
return $dsn;
}
// Treat host option as array of hosts
$hosts = is_array($host) ? $host : [$host];
foreach ($hosts as &$host) {
// Check if we need to add a port to the host
if (strpos($host, ':') === false and isset($port)) {
$host = "{$host}:{$port}";
}
}
// The database name needs to be in the connection string, otherwise it will
// authenticate to the admin database, which may result in permission errors.
return "mongodb://" . implode(',', $hosts) . "/{$database}";
}
/**
* Get the elapsed time since a given starting point.
*
* @param int $start
* @return float
*/
public function getElapsedTime($start)
{
return parent::getElapsedTime($start);
}
/**
* Get the PDO driver name.
*
* @return string
*/
public function getDriverName()
{
return 'mongodb';
}
/**
* Dynamically pass methods to the connection.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return call_user_func_array([$this->db, $method], $parameters);
}
}
<?php namespace Jenssegers\Mongodb\Eloquent;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\Relation;
use MongoCursor;
class Builder extends EloquentBuilder
{
/**
* The methods that should be returned from query builder.
*
* @var array
*/
protected $passthru = [
'toSql', 'lists', 'insert', 'insertGetId', 'pluck',
'count', 'min', 'max', 'avg', 'sum', 'exists', 'push', 'pull',
];
/**
* Update a record in the database.
*
* @param array $values
* @return int
*/
public function update(array $values)
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation()) {
$relation->performUpdate($this->model, $values);
return 1;
}
return parent::update($values);
}
/**
* Insert a new record into the database.
*
* @param array $values
* @return bool
*/
public function insert(array $values)
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation()) {
$relation->performInsert($this->model, $values);
return true;
}
return parent::insert($values);
}
/**
* Insert a new record and get the value of the primary key.
*
* @param array $values
* @param string $sequence
* @return int
*/
public function insertGetId(array $values, $sequence = null)
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation()) {
$relation->performInsert($this->model, $values);
return $this->model->getKey();
}
return parent::insertGetId($values, $sequence);
}
/**
* Delete a record from the database.
*
* @return mixed
*/
public function delete()
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation()) {
$relation->performDelete($this->model);
return $this->model->getKey();
}
return parent::delete();
}
/**
* Increment a column's value by a given amount.
*
* @param string $column
* @param int $amount
* @param array $extra
* @return int
*/
public function increment($column, $amount = 1, array $extra = [])
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation()) {
$value = $this->model->{$column};
// When doing increment and decrements, Eloquent will automatically
// sync the original attributes. We need to change the attribute
// temporary in order to trigger an update query.
$this->model->{$column} = null;
$this->model->syncOriginalAttribute($column);
$result = $this->model->update([$column => $value]);
return $result;
}
return parent::increment($column, $amount, $extra);
}
/**
* Decrement a column's value by a given amount.
*
* @param string $column
* @param int $amount
* @param array $extra
* @return int
*/
public function decrement($column, $amount = 1, array $extra = [])
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation()) {
$value = $this->model->{$column};
// When doing increment and decrements, Eloquent will automatically
// sync the original attributes. We need to change the attribute
// temporary in order to trigger an update query.
$this->model->{$column} = null;
$this->model->syncOriginalAttribute($column);
return $this->model->update([$column => $value]);
}
return parent::decrement($column, $amount, $extra);
}
/**
* Add the "has" condition where clause to the query.
*
* @param \Illuminate\Database\Eloquent\Builder $hasQuery
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
* @param string $operator
* @param int $count
* @param string $boolean
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $operator, $count, $boolean)
{
$query = $hasQuery->getQuery();
// Get the number of related objects for each possible parent.
$relationCount = array_count_values($query->lists($relation->getHasCompareKey()));
// Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) {
// If we are comparing to 0, we always need all results.
if ($count == 0) {
return true;
}
switch ($operator) {
case '>=':
case '<':
return $counted >= $count;
case '>':
case '<=':
return $counted > $count;
case '=':
case '!=':
return $counted == $count;
}
});
// If the operator is <, <= or !=, we will use whereNotIn.
$not = in_array($operator, ['<', '<=', '!=']);
// If we are comparing to 0, we need an additional $not flip.
if ($count == 0) {
$not = !$not;
}
// All related ids.
$relatedIds = array_keys($relationCount);
// Add whereIn to the query.
return $this->whereIn($this->model->getKeyName(), $relatedIds, $boolean, $not);
}
/**
* Create a raw database expression.
*
* @param closure $expression
* @return mixed
*/
public function raw($expression = null)
{
// Get raw results from the query builder.
$results = $this->query->raw($expression);
// Convert MongoCursor results to a collection of models.
if ($results instanceof MongoCursor) {
$results = iterator_to_array($results, false);
return $this->model->hydrate($results);
}
// The result is a single object.
elseif (is_array($results) and array_key_exists('_id', $results)) {
$model = $this->model->newFromBuilder($results);
$model->setConnection($this->model->getConnection());
return $model;
}
return $results;
}
}
<?php namespace Jenssegers\Mongodb\Eloquent;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str;
use Jenssegers\Mongodb\Model;
use Jenssegers\Mongodb\Relations\BelongsTo;
use Jenssegers\Mongodb\Relations\BelongsToMany;
use Jenssegers\Mongodb\Relations\HasMany;
use Jenssegers\Mongodb\Relations\HasOne;
use Jenssegers\Mongodb\Relations\MorphTo;
trait HybridRelations
{
/**
* Define a one-to-one relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function hasOne($related, $foreignKey = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Model')) {
return parent::hasOne($related, $foreignKey, $localKey);
}
$foreignKey = $foreignKey ?: $this->getForeignKey();
$instance = new $related;
$localKey = $localKey ?: $this->getKeyName();
return new HasOne($instance->newQuery(), $this, $foreignKey, $localKey);
}
/**
* Define a polymorphic one-to-one relationship.
*
* @param string $related
* @param string $name
* @param string $type
* @param string $id
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphOne
*/
public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Model')) {
return parent::morphOne($related, $name, $type, $id, $localKey);
}
$instance = new $related;
list($type, $id) = $this->getMorphs($name, $type, $id);
$table = $instance->getTable();
$localKey = $localKey ?: $this->getKeyName();
return new MorphOne($instance->newQuery(), $this, $type, $id, $localKey);
}
/**
* Define a one-to-many relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function hasMany($related, $foreignKey = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Model')) {
return parent::hasMany($related, $foreignKey, $localKey);
}
$foreignKey = $foreignKey ?: $this->getForeignKey();
$instance = new $related;
$localKey = $localKey ?: $this->getKeyName();
return new HasMany($instance->newQuery(), $this, $foreignKey, $localKey);
}
/**
* Define a polymorphic one-to-many relationship.
*
* @param string $related
* @param string $name
* @param string $type
* @param string $id
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Model')) {
return parent::morphMany($related, $name, $type, $id, $localKey);
}
$instance = new $related;
// Here we will gather up the morph type and ID for the relationship so that we
// can properly query the intermediate table of a relation. Finally, we will
// get the table and create the relationship instances for the developers.
list($type, $id) = $this->getMorphs($name, $type, $id);
$table = $instance->getTable();
$localKey = $localKey ?: $this->getKeyName();
return new MorphMany($instance->newQuery(), $this, $type, $id, $localKey);
}
/**
* Define an inverse one-to-one or many relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $otherKey
* @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if (is_null($relation)) {
list($current, $caller) = debug_backtrace(false, 2);
$relation = $caller['function'];
}
// Check if it is a relation with an original model.
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Model')) {
return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
}
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
if (is_null($foreignKey)) {
$foreignKey = Str::snake($relation) . '_id';
}
$instance = new $related;
// Once we have the foreign key names, we'll just create a new Eloquent query
// for the related models and returns the relationship instance which will
// actually be responsible for retrieving and hydrating every relations.
$query = $instance->newQuery();
$otherKey = $otherKey ?: $instance->getKeyName();
return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation);
}
/**
* Define a polymorphic, inverse one-to-one or many relationship.
*
* @param string $name
* @param string $type
* @param string $id
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function morphTo($name = null, $type = null, $id = null)
{
// If no name is provided, we will use the backtrace to get the function name
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
if (is_null($name)) {
list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$name = Str::snake($caller['function']);
}
list($type, $id) = $this->getMorphs($name, $type, $id);
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
if (is_null($class = $this->$type)) {
return new MorphTo(
$this->newQuery(), $this, $id, null, $type, $name
);
}
// If we are not eager loading the relationship we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
else {
$class = $this->getActualClassNameForMorph($class);
$instance = new $class;
return new MorphTo(
$instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name
);
}
}
/**
* Define a many-to-many relationship.
*
* @param string $related
* @param string $collection
* @param string $foreignKey
* @param string $otherKey
* @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null)
{
// If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply.
if (is_null($relation)) {
$relation = $this->getBelongsToManyCaller();
}
// Check if it is a relation with an original model.
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Model')) {
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation);
}
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
$foreignKey = $foreignKey ?: $this->getForeignKey() . 's';
$instance = new $related;
$otherKey = $otherKey ?: $instance->getForeignKey() . 's';
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
if (is_null($collection)) {
$collection = $instance->getTable();
}
// Now we're ready to create a new query builder for the related model and
// the relationship instances for the relation. The relations will set
// appropriate query constraint and entirely manages the hydrations.
$query = $instance->newQuery();
return new BelongsToMany($query, $this, $collection, $foreignKey, $otherKey, $relation);
}
}
<?php namespace Jenssegers\Mongodb\Eloquent;
trait SoftDeletes
{
use \Illuminate\Database\Eloquent\SoftDeletes;
/**
* Get the fully qualified "deleted at" column.
*
* @return string
*/
public function getQualifiedDeletedAtColumn()
{
return $this->getDeletedAtColumn();
}
}
<?php namespace Jenssegers\Mongodb;
use Illuminate\Support\ServiceProvider;
class MongodbServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*/
public function boot()
{
Model::setConnectionResolver($this->app['db']);
Model::setEventDispatcher($this->app['events']);
}
/**
* Register the service provider.
*/
public function register()
{
$this->app->resolving('db', function ($db) {
$db->extend('mongodb', function ($config) {
return new Connection($config);
});
});
}
}
<?php namespace Jenssegers\Mongodb\Query;
use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar;
class Grammar extends BaseGrammar
{
}
<?php namespace Jenssegers\Mongodb\Query;
use Illuminate\Database\Query\Processors\Processor as BaseProcessor;
class Processor extends BaseProcessor
{
}
<?php namespace Jenssegers\Mongodb\Relations;
class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
{
/**
* Set the base constraints on the relation query.
*/
public function addConstraints()
{
if (static::$constraints) {
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
$this->query->where($this->otherKey, '=', $this->parent->{$this->foreignKey});
}
}
/**
* Set the constraints for an eager load of the relation.
*
* @param array $models
*/
public function addEagerConstraints(array $models)
{
// We'll grab the primary key name of the related models since it could be set to
// a non-standard name and not "id". We will then construct the constraint for
// our eagerly loading query so it returns the proper models from execution.
$key = $this->otherKey;
$this->query->whereIn($key, $this->getEagerModelKeys($models));
}
}
<?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
class BelongsToMany extends EloquentBelongsToMany
{
/**
* Hydrate the pivot table relationship on the models.
*
* @param array $models
*/
protected function hydratePivotRelation(array $models)
{
// Do nothing.
}
/**
* Set the select clause for the relation query.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
protected function getSelectColumns(array $columns = ['*'])
{
return $columns;
}
/**
* Set the base constraints on the relation query.
*/
public function addConstraints()
{
if (static::$constraints) {
$this->setWhere();
}
}
/**
* Set the where clause for the relation query.
*
* @return $this
*/
protected function setWhere()
{
$foreign = $this->getForeignKey();
$this->query->where($foreign, '=', $this->parent->getKey());
return $this;
}
/**
* Save a new model and attach it to the parent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param array $joining
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
*/
public function save(Model $model, array $joining = [], $touch = true)
{
$model->save(['touch' => false]);
$this->attach($model, $joining, $touch);
return $model;
}
/**
* Create a new instance of the related model.
*
* @param array $attributes
* @param array $joining
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
*/
public function create(array $attributes, array $joining = [], $touch = true)
{
$instance = $this->related->newInstance($attributes);
// Once we save the related model, we need to attach it to the base model via
// through intermediate table so we'll use the existing "attach" method to
// accomplish this which will insert the record and any more attributes.
$instance->save(['touch' => false]);
$this->attach($instance, $joining, $touch);
return $instance;
}
/**
* Sync the intermediate tables with a list of IDs or collection of models.
*
* @param array $ids
* @param bool $detaching
* @return array
*/
public function sync($ids, $detaching = true)
{
$changes = [
'attached' => [], 'detached' => [], 'updated' => [],
];
if ($ids instanceof Collection) {
$ids = $ids->modelKeys();
}
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
// if they exist in the array of current ones, and if not we will insert.
$current = $this->parent->{$this->otherKey} ?: [];
// See issue #256.
if ($current instanceof Collection) {
$current = $ids->modelKeys();
}
$records = $this->formatSyncList($ids);
$detach = array_diff($current, array_keys($records));
// We need to make sure we pass a clean array, so that it is not interpreted
// as an associative array.
$detach = array_values($detach);
// Next, we will take the differences of the currents and given IDs and detach
// all of the entities that exist in the "current" array but are not in the
// the array of the IDs given to the method which will complete the sync.
if ($detaching and count($detach) > 0) {
$this->detach($detach);
$changes['detached'] = (array) array_map(function ($v) {
return is_numeric($v) ? (int) $v : (string) $v;
}, $detach);
}
// Now we are finally ready to attach the new records. Note that we'll disable
// touching until after the entire operation is complete so we don't fire a
// ton of touch operations until we are totally done syncing the records.
$changes = array_merge(
$changes, $this->attachNew($records, $current, false)
);
if (count($changes['attached']) || count($changes['updated'])) {
$this->touchIfTouching();
}
return $changes;
}
/**
* Update an existing pivot record on the table.
*
* @param mixed $id
* @param array $attributes
* @param bool $touch
*/
public function updateExistingPivot($id, array $attributes, $touch = true)
{
// Do nothing, we have no pivot table.
}
/**
* Attach a model to the parent.
*
* @param mixed $id
* @param array $attributes
* @param bool $touch
*/
public function attach($id, array $attributes = [], $touch = true)
{
if ($id instanceof Model) {
$model = $id;
$id = $model->getKey();
// Attach the new parent id to the related model.
$model->push($this->foreignKey, $this->parent->getKey(), true);
} else {
$query = $this->newRelatedQuery();
$query->whereIn($this->related->getKeyName(), (array) $id);
// Attach the new parent id to the related model.
$query->push($this->foreignKey, $this->parent->getKey(), true);
}
// Attach the new ids to the parent model.
$this->parent->push($this->otherKey, (array) $id, true);
if ($touch) {
$this->touchIfTouching();
}
}
/**
* Detach models from the relationship.
*
* @param int|array $ids
* @param bool $touch
* @return int
*/
public function detach($ids = [], $touch = true)
{
if ($ids instanceof Model) {
$ids = (array) $ids->getKey();
}
$query = $this->newRelatedQuery();
// If associated IDs were passed to the method we will only delete those
// associations, otherwise all of the association ties will be broken.
// We'll return the numbers of affected rows when we do the deletes.
$ids = (array) $ids;
// Detach all ids from the parent model.
$this->parent->pull($this->otherKey, $ids);
// Prepare the query to select all related objects.
if (count($ids) > 0) {
$query->whereIn($this->related->getKeyName(), $ids);
}
// Remove the relation to the parent.
$query->pull($this->foreignKey, $this->parent->getKey());
if ($touch) {
$this->touchIfTouching();
}
return count($ids);
}
/**
* Build model dictionary keyed by the relation's foreign key.
*
* @param \Illuminate\Database\Eloquent\Collection $results
* @return array
*/
protected function buildDictionary(Collection $results)
{
$foreign = $this->foreignKey;
// First we will build a dictionary of child models keyed by the foreign key
// of the relation so that we will easily and quickly match them to their
// parents without having a possibly slow inner loops for every models.
$dictionary = [];
foreach ($results as $result) {
foreach ($result->$foreign as $item) {
$dictionary[$item][] = $result;
}
}
return $dictionary;
}
/**
* Create a new query builder for the related model.
*
* @return \Illuminate\Database\Query\Builder
*/
protected function newPivotQuery()
{
return $this->newRelatedQuery();
}
/**
* Create a new query builder for the related model.
*
* @return \Illuminate\Database\Query\Builder
*/
public function newRelatedQuery()
{
return $this->related->newQuery();
}
/**
* Get the fully qualified foreign key for the relation.
*
* @return string
*/
public function getForeignKey()
{
return $this->foreignKey;
}
}
<?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use MongoId;
class EmbedsMany extends EmbedsOneOrMany
{
/**
* Get the results of the relationship.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getResults()
{
return $this->toCollection($this->getEmbedded());
}
/**
* Save a new model and attach it to the parent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model
*/
public function performInsert(Model $model)
{
// Generate a new key if needed.
if ($model->getKeyName() == '_id' and ! $model->getKey()) {
$model->setAttribute('_id', new MongoId);
}
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested()) {
$this->associate($model);
return $this->parent->save();
}
// Push the new model to the database.
$result = $this->getBaseQuery()->push($this->localKey, $model->getAttributes(), true);
// Attach the model to its parent.
if ($result) {
$this->associate($model);
}
return $result ? $model : false;
}
/**
* Save an existing model and attach it to the parent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return Model|bool
*/
public function performUpdate(Model $model)
{
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested()) {
$this->associate($model);
return $this->parent->save();
}
// Get the correct foreign key value.
$foreignKey = $this->getForeignKeyValue($model);
// Use array dot notation for better update behavior.
$values = array_dot($model->getDirty(), $this->localKey . '.$.');
// Update document in database.
$result = $this->getBaseQuery()->where($this->localKey . '.' . $model->getKeyName(), $foreignKey)
->update($values);
// Attach the model to its parent.
if ($result) {
$this->associate($model);
}
return $result ? $model : false;
}
/**
* Delete an existing model and detach it from the parent model.
*
* @param Model $model
* @return int
*/
public function performDelete(Model $model)
{
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested()) {
$this->dissociate($model);
return $this->parent->save();
}
// Get the correct foreign key value.
$foreignKey = $this->getForeignKeyValue($model);
$result = $this->getBaseQuery()->pull($this->localKey, [$model->getKeyName() => $foreignKey]);
if ($result) {
$this->dissociate($model);
}
return $result;
}
/**
* Associate the model instance to the given parent, without saving it to the database.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model
*/
public function associate(Model $model)
{
if (! $this->contains($model)) {
return $this->associateNew($model);
} else {
return $this->associateExisting($model);
}
}
/**
* Dissociate the model instance from the given parent, without saving it to the database.
*
* @param mixed $ids
* @return int
*/
public function dissociate($ids = [])
{
$ids = $this->getIdsArrayFrom($ids);
$records = $this->getEmbedded();
$primaryKey = $this->related->getKeyName();
// Remove the document from the parent model.
foreach ($records as $i => $record) {
if (in_array($record[$primaryKey], $ids)) {
unset($records[$i]);
}
}
$this->setEmbedded($records);
// We return the total number of deletes for the operation. The developers
// can then check this number as a boolean type value or get this total count
// of records deleted for logging, etc.
return count($ids);
}
/**
* Destroy the embedded models for the given IDs.
*
* @param mixed $ids
* @return int
*/
public function destroy($ids = [])
{
$count = 0;
$ids = $this->getIdsArrayFrom($ids);
// Get all models matching the given ids.
$models = $this->getResults()->only($ids);
// Pull the documents from the database.
foreach ($models as $model) {
if ($model->delete()) {
$count++;
}
}
return $count;
}
/**
* Delete all embedded models.
*
* @return int
*/
public function delete()
{
// Overwrite the local key with an empty array.
$result = $this->query->update([$this->localKey => []]);
if ($result) {
$this->setEmbedded([]);
}
return $result;
}
/**
* Destroy alias.
*
* @param mixed $ids
* @return int
*/
public function detach($ids = [])
{
return $this->destroy($ids);
}
/**
* Save alias.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model
*/
public function attach(Model $model)
{
return $this->save($model);
}
/**
* Associate a new model instance to the given parent, without saving it to the database.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model
*/
protected function associateNew($model)
{
// Create a new key if needed.
if (! $model->getAttribute('_id')) {
$model->setAttribute('_id', new MongoId);
}
$records = $this->getEmbedded();
// Add the new model to the embedded documents.
$records[] = $model->getAttributes();
return $this->setEmbedded($records);
}
/**
* Associate an existing model instance to the given parent, without saving it to the database.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model
*/
protected function associateExisting($model)
{
// Get existing embedded documents.
$records = $this->getEmbedded();
$primaryKey = $this->related->getKeyName();
$key = $model->getKey();
// Replace the document in the parent model.
foreach ($records as &$record) {
if ($record[$primaryKey] == $key) {
$record = $model->getAttributes();
break;
}
}
return $this->setEmbedded($records);
}
/**
* Get a paginator for the "select" statement.
*
* @param int $perPage
* @return \Illuminate\Pagination\Paginator
*/
public function paginate($perPage = null)
{
$page = Paginator::resolveCurrentPage();
$perPage = $perPage ?: $this->related->getPerPage();
$results = $this->getEmbedded();
$total = count($results);
$start = ($page - 1) * $perPage;
$sliced = array_slice($results, $start, $perPage);
return new LengthAwarePaginator($sliced, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
]);
}
/**
* Get the embedded records array.
*
* @return array
*/
protected function getEmbedded()
{
return parent::getEmbedded() ?: [];
}
/**
* Set the embedded records array.
*
* @param array $models
*/
protected function setEmbedded($models)
{
if (! is_array($models)) {
$models = [$models];
}
return parent::setEmbedded(array_values($models));
}
/**
* Handle dynamic method calls to the relationship.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
// Collection methods
if (method_exists('Illuminate\Database\Eloquent\Collection', $method)) {
return call_user_func_array([$this->getResults(), $method], $parameters);
}
return parent::__call($method, $parameters);
}
}
<?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Model;
use MongoId;
class EmbedsOne extends EmbedsOneOrMany
{
/**
* Get the results of the relationship.
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function getResults()
{
return $this->toModel($this->getEmbedded());
}
/**
* Save a new model and attach it to the parent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model
*/
public function performInsert(Model $model)
{
// Generate a new key if needed.
if ($model->getKeyName() == '_id' and ! $model->getKey()) {
$model->setAttribute('_id', new MongoId);
}
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested()) {
$this->associate($model);
return $this->parent->save();
}
$result = $this->getBaseQuery()->update([$this->localKey => $model->getAttributes()]);
// Attach the model to its parent.
if ($result) {
$this->associate($model);
}
return $result ? $model : false;
}
/**
* Save an existing model and attach it to the parent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model|bool
*/
public function performUpdate(Model $model)
{
if ($this->isNested()) {
$this->associate($model);
return $this->parent->save();
}
// Use array dot notation for better update behavior.
$values = array_dot($model->getDirty(), $this->localKey . '.');
$result = $this->getBaseQuery()->update($values);
// Attach the model to its parent.
if ($result) {
$this->associate($model);
}
return $result ? $model : false;
}
/**
* Delete an existing model and detach it from the parent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return int
*/
public function performDelete(Model $model)
{
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested()) {
$this->dissociate($model);
return $this->parent->save();
}
// Overwrite the local key with an empty array.
$result = $this->getBaseQuery()->update([$this->localKey => null]);
// Detach the model from its parent.
if ($result) {
$this->dissociate();
}
return $result;
}
/**
* Attach the model to its parent.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model
*/
public function associate(Model $model)
{
return $this->setEmbedded($model->getAttributes());
}
/**
* Detach the model from its parent.
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function dissociate()
{
return $this->setEmbedded(null);
}
/**
* Delete all embedded models.
*
* @return int
*/
public function delete()
{
$model = $this->getResults();
return $this->performDelete($model);
}
}
<?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany;
class HasMany extends EloquentHasMany
{
/**
* Add the constraints for a relationship query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @param array|mixed $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{
$query->select($columns);
$key = $this->wrap($this->getQualifiedParentKeyName());
return $query->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Add the constraints for a relationship count query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationCountQuery(Builder $query, Builder $parent)
{
$foreignKey = $this->getHasCompareKey();
return $query->select($this->getHasCompareKey())->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Get the plain foreign key.
*
* @return string
*/
public function getPlainForeignKey()
{
return $this->getForeignKey();
}
}
<?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne;
class HasOne extends EloquentHasOne
{
/**
* Add the constraints for a relationship query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @param array|mixed $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{
$query->select($columns);
$key = $this->wrap($this->getQualifiedParentKeyName());
return $query->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Add the constraints for a relationship count query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationCountQuery(Builder $query, Builder $parent)
{
$foreignKey = $this->getHasCompareKey();
return $query->select($this->getHasCompareKey())->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Get the plain foreign key.
*
* @return string
*/
public function getPlainForeignKey()
{
return $this->getForeignKey();
}
}
<?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo;
class MorphTo extends EloquentMorphTo
{
/**
* Set the base constraints on the relation query.
*/
public function addConstraints()
{
if (static::$constraints) {
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
$this->query->where($this->otherKey, '=', $this->parent->{$this->foreignKey});
}
}
/**
* Get all of the relation results for a type.
*
* @param string $type
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function getResultsByType($type)
{
$instance = $this->createModelByType($type);
$key = $instance->getKeyName();
$query = $instance->newQuery();
$query = $this->useWithTrashed($query);
return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get();
}
}
<?php namespace Jenssegers\Mongodb\Schema;
use Closure;
use Illuminate\Database\Connection;
class Blueprint extends \Illuminate\Database\Schema\Blueprint
{
/**
* The MongoConnection object for this blueprint.
*
* @var MongoConnection
*/
protected $connection;
/**
* The MongoCollection object for this blueprint.
*
* @var MongoCollection
*/
protected $collection;
/**
* Fluent columns.
*
* @var array
*/
protected $columns = [];
/**
* Create a new schema blueprint.
*
* @param string $table
* @param Closure $callback
*/
public function __construct(Connection $connection, $collection)
{
$this->connection = $connection;
$this->collection = $connection->getCollection($collection);
}
/**
* Specify an index for the collection.
*
* @param string|array $columns
* @param array $options
* @return Blueprint
*/
public function index($columns = null, $options = [])
{
$columns = $this->fluent($columns);
// Columns are passed as a default array.
if (is_array($columns) && is_int(key($columns))) {
// Transform the columns to the required array format.
$transform = [];
foreach ($columns as $column) {
$transform[$column] = 1;
}
$columns = $transform;
}
$this->collection->ensureIndex($columns, $options);
return $this;
}
/**
* Specify the primary key(s) for the table.
*
* @param string|array $columns
* @param array $options
* @return \Illuminate\Support\Fluent
*/
public function primary($columns = null, $options = [])
{
return $this->unique($columns, $options);
}
/**
* Indicate that the given index should be dropped.
*
* @param string|array $columns
* @return Blueprint
*/
public function dropIndex($columns = null)
{
$columns = $this->fluent($columns);
// Columns are passed as a default array.
if (is_array($columns) && is_int(key($columns))) {
// Transform the columns to the required array format.
$transform = [];
foreach ($columns as $column) {
$transform[$column] = 1;
}
$columns = $transform;
}
$this->collection->deleteIndex($columns);
return $this;
}
/**
* Specify a unique index for the collection.
*
* @param string|array $columns
* @param array $options
* @return Blueprint
*/
public function unique($columns = null, $options = [])
{
$columns = $this->fluent($columns);
$options['unique'] = true;
$this->index($columns, $options);
return $this;
}
/**
* Specify a non blocking index for the collection.
*
* @param string|array $columns
* @return Blueprint
*/
public function background($columns = null)
{
$columns = $this->fluent($columns);
$this->index($columns, ['background' => true]);
return $this;
}
/**
* Specify a sparse index for the collection.
*
* @param string|array $columns
* @param array $options
* @return Blueprint
*/
public function sparse($columns = null, $options = [])
{
$columns = $this->fluent($columns);
$options['sparse'] = true;
$this->index($columns, $options);
return $this;
}
/**
* Specify the number of seconds after wich a document should be considered expired based,
* on the given single-field index containing a date.
*
* @param string|array $columns
* @param int $seconds
* @return Blueprint
*/
public function expire($columns, $seconds)
{
$columns = $this->fluent($columns);
$this->index($columns, ['expireAfterSeconds' => $seconds]);
return $this;
}
/**
* Indicate that the table needs to be created.
*
* @return bool
*/
public function create()
{
$collection = $this->collection->getName();
$db = $this->connection->getMongoDB();
// Ensure the collection is created.
$db->createCollection($collection);
}
/**
* Indicate that the collection should be dropped.
*
* @return bool
*/
public function drop()
{
$this->collection->drop();
}
/**
* Add a new column to the blueprint.
*
* @param string $type
* @param string $name
* @param array $parameters
* @return Blueprint
*/
protected function addColumn($type, $name, array $parameters = [])
{
$this->fluent($name);
return $this;
}
/**
* Allow fluent columns.
*
* @param string|array $columns
* @return string|array
*/
protected function fluent($columns = null)
{
if (is_null($columns)) {
return $this->columns;
} elseif (is_string($columns)) {
return $this->columns = [$columns];
} else {
return $this->columns = $columns;
}
}
/**
* Allows the use of unsupported schema methods.
*
* @return Blueprint
*/
public function __call($method, $args)
{
// Dummy.
return $this;
}
}
<?php namespace Jenssegers\Mongodb\Schema;
use Closure;
use Jenssegers\Mongodb\Connection;
class Builder extends \Illuminate\Database\Schema\Builder
{
/**
* Create a new database Schema manager.
*
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
/**
* Determine if the given table has a given column.
*
* @param string $table
* @param string $column
* @return bool
*/
public function hasColumn($table, $column)
{
return true;
}
/**
* Determine if the given table has given columns.
*
* @param string $table
* @param array $columns
* @return bool
*/
public function hasColumns($table, array $columns)
{
return true;
}
/**
* Determine if the given collection exists.
*
* @param string $collection
* @return bool
*/
public function hasCollection($collection)
{
$db = $this->connection->getMongoDB();
return in_array($collection, $db->getCollectionNames());
}
/**
* Determine if the given collection exists.
*
* @param string $collection
* @return bool
*/
public function hasTable($collection)
{
return $this->hasCollection($collection);
}
/**
* Modify a collection on the schema.
*
* @param string $collection
* @param Closure $callback
* @return bool
*/
public function collection($collection, Closure $callback)
{
$blueprint = $this->createBlueprint($collection);
if ($callback) {
$callback($blueprint);
}
}
/**
* Modify a collection on the schema.
*
* @param string $collection
* @param Closure $callback
* @return bool
*/
public function table($collection, Closure $callback)
{
return $this->collection($collection, $callback);
}
/**
* Create a new collection on the schema.
*
* @param string $collection
* @param Closure $callback
* @return bool
*/
public function create($collection, Closure $callback = null)
{
$blueprint = $this->createBlueprint($collection);
$blueprint->create();
if ($callback) {
$callback($blueprint);
}
}
/**
* Drop a collection from the schema.
*
* @param string $collection
* @return bool
*/
public function drop($collection)
{
$blueprint = $this->createBlueprint($collection);
return $blueprint->drop();
}
/**
* Create a new Blueprint.
*
* @param string $collection
* @return Schema\Blueprint
*/
protected function createBlueprint($collection, Closure $callback = null)
{
return new Blueprint($this->connection, $collection);
}
}
<?php require 'vendor/autoload.php';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment