Skip to content

Commit b6a561f

Browse files
committed
first commit
0 parents  commit b6a561f

File tree

90 files changed

+3755
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3755
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Formbuilder for Laravel5.4
2+
3+
Step 1 : php artisan make:auth
4+
Step 2 : composer require MspPack/DDSGenerate
5+
Step 3 : Add service provider in config/app.php
6+
MspPack\DDSGenerate\DDSGenerateServiceProvider::class,
7+
Step 4 : php artisan migrate
8+
9+
Once you installed please visit : http://<DOMAIN>/admin/generate

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "msppack/DDSGenerate",
3+
"keywords": ["laravel5.4","DDSGenerate","social","facebook","google"],
4+
"description": "Package for create easly form with single sintex",
5+
"authors": [
6+
{
7+
"name": "Manoj Sonagra",
8+
"email": "manoj30808@gmail.com"
9+
}
10+
],
11+
"require": {
12+
"php": ">=5.5.9",
13+
"laravelcollective/html": "^5.4",
14+
"laracasts/generators": "dev-master as 1.1.4",
15+
"doctrine/dbal": "^2.5"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"MspPack\\DDSGenerate\\": "src"
20+
}
21+
},
22+
"scripts": {
23+
"post-create-project-cmd": [
24+
"php artisan migrate",
25+
"php artisan vendor:publish"
26+
],
27+
"post-install-cmd": [
28+
"Illuminate\\Foundation\\ComposerScripts::postInstall",
29+
"php artisan optimize"
30+
],
31+
"post-update-cmd": [
32+
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
33+
"php artisan optimize"
34+
]
35+
}
36+
}

src/DDSGenerateServiceProvider.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php namespace MspPack\DDSGenerate;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
5+
class DDSGenerateServiceProvider extends ServiceProvider {
6+
7+
8+
//protected $defer = false;
9+
10+
/**
11+
* Register the application services.
12+
*
13+
* @return void
14+
*/
15+
public function boot()
16+
{
17+
$this->loadRoutesFrom(__DIR__.'/routes.php');
18+
$this->publishes([
19+
__DIR__.'/resources' => resource_path('views'),
20+
]);
21+
$this->publishes([
22+
__DIR__.'/public' => public_path(),
23+
]);
24+
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
25+
/*
26+
$settings = \DB::table('settings')->get()->first();
27+
if (!empty($settings)) {
28+
\Config::set(['services.twitter.client_id'=>$settings->twitter_client_id]);
29+
\Config::set(['services.twitter.client_secret'=>$settings->twitter_client_secret]);
30+
31+
\Config::set(['services.google.client_id'=>$settings->google_client_id]);
32+
\Config::set(['services.google.client_secret'=>$settings->google_client_secret]);
33+
34+
\Config::set(['services.facebook.client_id'=>$settings->facebook_client_id]);
35+
\Config::set(['services.facebook.client_secret'=>$settings->facebook_client_secret]);
36+
37+
\Config::set(['services.pinterest.client_id'=>$settings->pinterest_client_id]);
38+
\Config::set(['services.pinterest.client_secret'=>$settings->pinterest_client_secret]);
39+
40+
\Config::set(['services.linkedin.client_id'=>$settings->linkedin_client_id]);
41+
\Config::set(['services.linkedin.client_secret'=>$settings->linkedin_client_secret]);
42+
43+
\Config::set(['mail.driver'=>$settings->mail_driver]);
44+
\Config::set(['mail.host'=>$settings->mail_host]);
45+
\Config::set(['mail.port'=>$settings->mail_port]);
46+
\Config::set(['mail.username'=>$settings->mail_username]);
47+
\Config::set(['mail.password'=>$settings->mail_password]);
48+
\Config::set(['mail.encryption'=>$settings->mail_encryption]);
49+
}
50+
\Config::set(['auth.providers.users.model'=>\MspPack\DDSGenerate\User::class]);
51+
\Config::set(['cache.default' => 'array' ]);
52+
\Config::set(['entrust.role' => 'MspPack\DDSGenerate\Role' ]);
53+
\Config::set(['entrust.permission' => 'MspPack\DDSGenerate\Permission' ]);
54+
55+
56+
\Validator::extend('alpha_space', function ($attribute, $value) {
57+
return preg_match('/^[\pL\s]+$/u', $value);
58+
});
59+
\Schema::defaultStringLength(191);*/
60+
}
61+
public function register()
62+
{
63+
$this->app->register('Collective\Html\HtmlServiceProvider');
64+
$this->app->register('Laracasts\Generators\GeneratorsServiceProvider');
65+
66+
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
67+
$loader->alias('Form', 'Collective\Html\FormFacade');
68+
$loader->alias('Html', 'Collective\Html\HtmlFacade');
69+
}
70+
}
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?php
2+
3+
namespace MspPack\DDSGenerate\DatabaseUpdate;
4+
5+
use Doctrine\DBAL\Schema\Column;
6+
use Doctrine\DBAL\Schema\SchemaException;
7+
use Doctrine\DBAL\Schema\TableDiff;
8+
use MspPack\DDSGenerate\DatabaseUpdate\Schema\SchemaManager;
9+
use MspPack\DDSGenerate\DatabaseUpdate\Schema\Table;
10+
use MspPack\DDSGenerate\DatabaseUpdate\Types\Type;
11+
12+
class DatabaseUpdater
13+
{
14+
protected $tableArr;
15+
protected $table;
16+
protected $originalTable;
17+
18+
public function __construct(array $tableArr)
19+
{
20+
Type::registerCustomPlatformTypes();
21+
22+
$this->table = Table::make($tableArr);
23+
$this->tableArr = $tableArr;
24+
$this->originalTable = SchemaManager::listTableDetails($tableArr['oldName']);
25+
}
26+
27+
/**
28+
* Update the table.
29+
*
30+
* @return void
31+
*/
32+
public static function update($table)
33+
{
34+
if (!is_array($table)) {
35+
$table = json_decode($table, true);
36+
}
37+
38+
if (!SchemaManager::tableExists($table['oldName'])) {
39+
throw SchemaException::tableDoesNotExist($table['oldName']);
40+
}
41+
42+
$updater = new self($table);
43+
44+
$updater->updateTable();
45+
}
46+
47+
/**
48+
* Updates the table.
49+
*
50+
* @return void
51+
*/
52+
public function updateTable()
53+
{
54+
// Get table new name
55+
if (($newName = $this->table->getName()) != $this->originalTable->getName()) {
56+
// Make sure the new name doesn't already exist
57+
if (SchemaManager::tableExists($newName)) {
58+
throw SchemaException::tableAlreadyExists($newName);
59+
}
60+
} else {
61+
$newName = false;
62+
}
63+
64+
// Rename columns
65+
if ($renamedColumnsDiff = $this->getRenamedColumnsDiff()) {
66+
SchemaManager::alterTable($renamedColumnsDiff);
67+
68+
// Refresh original table after renaming the columns
69+
$this->originalTable = SchemaManager::listTableDetails($this->tableArr['oldName']);
70+
}
71+
72+
$tableDiff = $this->originalTable->diff($this->table);
73+
74+
// Add new table name to tableDiff
75+
if ($newName) {
76+
if (!$tableDiff) {
77+
$tableDiff = new TableDiff($this->tableArr['oldName']);
78+
$tableDiff->fromTable = $this->originalTable;
79+
}
80+
81+
$tableDiff->newName = $newName;
82+
}
83+
84+
// Update the table
85+
if ($tableDiff) {
86+
SchemaManager::alterTable($tableDiff);
87+
}
88+
}
89+
90+
/**
91+
* Get the table diff to rename columns.
92+
*
93+
* @return \Doctrine\DBAL\Schema\TableDiff
94+
*/
95+
protected function getRenamedColumnsDiff()
96+
{
97+
$renamedColumns = $this->getRenamedColumns();
98+
99+
if (empty($renamedColumns)) {
100+
return false;
101+
}
102+
103+
$renamedColumnsDiff = new TableDiff($this->tableArr['oldName']);
104+
$renamedColumnsDiff->fromTable = $this->originalTable;
105+
106+
foreach ($renamedColumns as $oldName => $newName) {
107+
$renamedColumnsDiff->renamedColumns[$oldName] = $this->table->getColumn($newName);
108+
}
109+
110+
return $renamedColumnsDiff;
111+
}
112+
113+
/**
114+
* Get the table diff to rename columns and indexes.
115+
*
116+
* @return \Doctrine\DBAL\Schema\TableDiff
117+
*/
118+
protected function getRenamedDiff()
119+
{
120+
$renamedColumns = $this->getRenamedColumns();
121+
$renamedIndexes = $this->getRenamedIndexes();
122+
123+
if (empty($renamedColumns) && empty($renamedIndexes)) {
124+
return false;
125+
}
126+
127+
$renamedDiff = new TableDiff($this->tableArr['oldName']);
128+
$renamedDiff->fromTable = $this->originalTable;
129+
130+
foreach ($renamedColumns as $oldName => $newName) {
131+
$renamedDiff->renamedColumns[$oldName] = $this->table->getColumn($newName);
132+
}
133+
134+
foreach ($renamedIndexes as $oldName => $newName) {
135+
$renamedDiff->renamedIndexes[$oldName] = $this->table->getIndex($newName);
136+
}
137+
138+
return $renamedDiff;
139+
}
140+
141+
/**
142+
* Get columns that were renamed.
143+
*
144+
* @return array
145+
*/
146+
protected function getRenamedColumns()
147+
{
148+
$renamedColumns = [];
149+
150+
foreach ($this->tableArr['columns'] as $column) {
151+
$oldName = $column['oldName'];
152+
153+
// make sure this is an existing column and not a new one
154+
if ($this->originalTable->hasColumn($oldName)) {
155+
$name = $column['name'];
156+
157+
if ($name != $oldName) {
158+
$renamedColumns[$oldName] = $name;
159+
}
160+
}
161+
}
162+
163+
return $renamedColumns;
164+
}
165+
166+
/**
167+
* Get indexes that were renamed.
168+
*
169+
* @return array
170+
*/
171+
protected function getRenamedIndexes()
172+
{
173+
$renamedIndexes = [];
174+
175+
foreach ($this->tableArr['indexes'] as $index) {
176+
$oldName = $index['oldName'];
177+
178+
// make sure this is an existing index and not a new one
179+
if ($this->originalTable->hasIndex($oldName)) {
180+
$name = $index['name'];
181+
182+
if ($name != $oldName) {
183+
$renamedIndexes[$oldName] = $name;
184+
}
185+
}
186+
}
187+
188+
return $renamedIndexes;
189+
}
190+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace MspPack\DDSGenerate\DatabaseUpdate\Platforms;
4+
5+
use Illuminate\Support\Collection;
6+
use MspPack\DDSGenerate\DatabaseUpdate\Types\Type;
7+
8+
abstract class Mysql extends Platform
9+
{
10+
public static function getTypes(Collection $typeMapping)
11+
{
12+
$typeMapping->forget([
13+
'real', // same as double
14+
'int', // same as integer
15+
'string', // same as varchar
16+
'numeric', // same as decimal
17+
]);
18+
19+
return $typeMapping;
20+
}
21+
22+
public static function registerCustomTypeOptions()
23+
{
24+
// Not supported
25+
Type::registerCustomOption(Type::NOT_SUPPORTED, true, [
26+
'enum',
27+
'set',
28+
]);
29+
30+
// Not support index
31+
Type::registerCustomOption(Type::NOT_SUPPORT_INDEX, true, '*text');
32+
Type::registerCustomOption(Type::NOT_SUPPORT_INDEX, true, '*blob');
33+
34+
// Disable Default for unsupported types
35+
Type::registerCustomOption('default', [
36+
'disabled' => true,
37+
], '*text');
38+
Type::registerCustomOption('default', [
39+
'disabled' => true,
40+
], '*blob');
41+
Type::registerCustomOption('default', [
42+
'disabled' => true,
43+
], 'json');
44+
}
45+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace MspPack\DDSGenerate\DatabaseUpdate\Platforms;
4+
5+
use Illuminate\Support\Collection;
6+
7+
abstract class Platform
8+
{
9+
// abstract public static function getTypes(Collection $typeMapping);
10+
11+
// abstract public static function registerCustomTypeOptions();
12+
13+
public static function getPlatform($platformName)
14+
{
15+
$platform = __NAMESPACE__.'\\'.ucfirst($platformName);
16+
17+
if (!class_exists($platform)) {
18+
throw new \Exception("Platform {$platformName} doesn't exist");
19+
}
20+
21+
return $platform;
22+
}
23+
24+
public static function getPlatformTypes($platformName, Collection $typeMapping)
25+
{
26+
$platform = static::getPlatform($platformName);
27+
28+
return $platform::getTypes($typeMapping);
29+
}
30+
31+
public static function registerPlatformCustomTypeOptions($platformName)
32+
{
33+
$platform = static::getPlatform($platformName);
34+
35+
return $platform::registerCustomTypeOptions();
36+
}
37+
}

0 commit comments

Comments
 (0)