server 3 年 前
コミット
6116b67e09
共有12 個のファイルを変更した351 個の追加0 個の削除を含む
  1. 5 0
      .htaccess
  2. 20 0
      .htrouter.php
  3. 30 0
      app/config/config.php
  4. 13 0
      app/config/loader.php
  5. 36 0
      app/config/router.php
  6. 122 0
      app/config/services.php
  7. 9 0
      app/controllers/ControllerBase.php
  8. 33 0
      app/controllers/IndexController.php
  9. 21 0
      app/views/index.phtml
  10. 7 0
      app/views/index/index.phtml
  11. 8 0
      public/.htaccess
  12. 47 0
      public/index.php

+ 5 - 0
.htaccess

@@ -0,0 +1,5 @@
1
+<IfModule mod_rewrite.c>
2
+	RewriteEngine on
3
+	RewriteRule  ^$ public/    [L]
4
+	RewriteRule  (.*) public/$1 [L]
5
+</IfModule>

+ 20 - 0
.htrouter.php

@@ -0,0 +1,20 @@
1
+<?php
2
+
3
+/**
4
+ * This file is part of the Phalcon Developer Tools.
5
+ *
6
+ * (c) Phalcon Team <team@phalcon.io>
7
+ *
8
+ * For the full copyright and license information, please view
9
+ * the LICENSE file that was distributed with this source code.
10
+ */
11
+
12
+$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
13
+
14
+if ($uri !== '/' && file_exists(__DIR__ . '/public' . $uri)) {
15
+    return false;
16
+}
17
+
18
+$_GET['_url'] = $_SERVER['REQUEST_URI'];
19
+
20
+require_once __DIR__ . '/public/index.php';

+ 30 - 0
app/config/config.php

@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+/*
4
+ * Modified: prepend directory path of current file, because of this file own different ENV under between Apache and command line.
5
+ * NOTE: please remove this comment.
6
+ */
7
+defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
8
+defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');
9
+
10
+return new \Phalcon\Config([
11
+    'database' => [
12
+        'adapter'     => 'Mysql',
13
+        'host'        => 'localhost',
14
+        'username'    => 'root',
15
+        'password'    => '',
16
+        'dbname'      => 'test',
17
+        'charset'     => 'utf8',
18
+    ],
19
+    'application' => [
20
+        'appDir'         => APP_PATH . '/',
21
+        'controllersDir' => APP_PATH . '/controllers/',
22
+        'modelsDir'      => APP_PATH . '/models/',
23
+        'migrationsDir'  => APP_PATH . '/migrations/',
24
+        'viewsDir'       => APP_PATH . '/views/',
25
+        'pluginsDir'     => APP_PATH . '/plugins/',
26
+        'libraryDir'     => APP_PATH . '/library/',
27
+        'cacheDir'       => BASE_PATH . '/cache/',
28
+        'baseUri'        => '/',
29
+    ]
30
+]);

+ 13 - 0
app/config/loader.php

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+$loader = new \Phalcon\Loader();
4
+
5
+/**
6
+ * We're a registering a set of directories taken from the configuration file
7
+ */
8
+$loader->registerDirs(
9
+    [
10
+        $config->application->controllersDir,
11
+        $config->application->modelsDir
12
+    ]
13
+)->register();

+ 36 - 0
app/config/router.php

@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+$router = $di->getRouter();
4
+
5
+// Define your routes here
6
+
7
+$router->handle($_SERVER['REQUEST_URI']);
8
+
9
+
10
+$router->add('/',[
11
+    'controller' => 'index',
12
+    'action' => 'index',
13
+]);
14
+
15
+$router->add('/:controller/:action/:params',[
16
+    'controller' => 1,
17
+    'action' => 2,
18
+    'params' => 3
19
+]);
20
+
21
+$router->add('/:controller',[
22
+    'controller' => 1,
23
+    'action' => 'index'
24
+]);
25
+
26
+$router->add('/gogs/:params',[
27
+    'controller'=>'gogs',
28
+    'action'=>'index',
29
+    'params'=>1
30
+]);
31
+
32
+$router->notFound([
33
+    'controller' => 'index',
34
+    'action' => 'show404',
35
+]);
36
+

+ 122 - 0
app/config/services.php

@@ -0,0 +1,122 @@
1
+<?php
2
+declare(strict_types=1);
3
+
4
+use Phalcon\Escaper;
5
+use Phalcon\Flash\Direct as Flash;
6
+use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
7
+use Phalcon\Mvc\View;
8
+use Phalcon\Mvc\View\Engine\Php as PhpEngine;
9
+use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
10
+use Phalcon\Session\Adapter\Stream as SessionAdapter;
11
+use Phalcon\Session\Manager as SessionManager;
12
+use Phalcon\Url as UrlResolver;
13
+
14
+/**
15
+ * Shared configuration service
16
+ */
17
+$di->setShared('config', function () {
18
+    return include APP_PATH . "/config/config.php";
19
+});
20
+
21
+/**
22
+ * The URL component is used to generate all kind of urls in the application
23
+ */
24
+$di->setShared('url', function () {
25
+    $config = $this->getConfig();
26
+
27
+    $url = new UrlResolver();
28
+    $url->setBaseUri($config->application->baseUri);
29
+
30
+    return $url;
31
+});
32
+
33
+/**
34
+ * Setting up the view component
35
+ */
36
+$di->setShared('view', function () {
37
+    $config = $this->getConfig();
38
+
39
+    $view = new View();
40
+    $view->setDI($this);
41
+    $view->setViewsDir($config->application->viewsDir);
42
+
43
+    $view->registerEngines([
44
+        '.volt' => function ($view) {
45
+            $config = $this->getConfig();
46
+
47
+            $volt = new VoltEngine($view, $this);
48
+
49
+            $volt->setOptions([
50
+                'path' => $config->application->cacheDir,
51
+                'separator' => '_'
52
+            ]);
53
+
54
+            return $volt;
55
+        },
56
+        '.phtml' => PhpEngine::class
57
+
58
+    ]);
59
+
60
+    return $view;
61
+});
62
+
63
+/**
64
+ * Database connection is created based in the parameters defined in the configuration file
65
+ */
66
+$di->setShared('db', function () {
67
+    $config = $this->getConfig();
68
+
69
+    $class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
70
+    $params = [
71
+        'host'     => $config->database->host,
72
+        'username' => $config->database->username,
73
+        'password' => $config->database->password,
74
+        'dbname'   => $config->database->dbname,
75
+        'charset'  => $config->database->charset
76
+    ];
77
+
78
+    if ($config->database->adapter == 'Postgresql') {
79
+        unset($params['charset']);
80
+    }
81
+
82
+    return new $class($params);
83
+});
84
+
85
+
86
+/**
87
+ * If the configuration specify the use of metadata adapter use it or use memory otherwise
88
+ */
89
+$di->setShared('modelsMetadata', function () {
90
+    return new MetaDataAdapter();
91
+});
92
+
93
+/**
94
+ * Register the session flash service with the Twitter Bootstrap classes
95
+ */
96
+$di->set('flash', function () {
97
+    $escaper = new Escaper();
98
+    $flash = new Flash($escaper);
99
+    $flash->setImplicitFlush(false);
100
+    $flash->setCssClasses([
101
+        'error'   => 'alert alert-danger',
102
+        'success' => 'alert alert-success',
103
+        'notice'  => 'alert alert-info',
104
+        'warning' => 'alert alert-warning'
105
+    ]);
106
+
107
+    return $flash;
108
+});
109
+
110
+/**
111
+ * Start the session the first time some component request the session service
112
+ */
113
+$di->setShared('session', function () {
114
+    $session = new SessionManager();
115
+    $files = new SessionAdapter([
116
+        'savePath' => sys_get_temp_dir(),
117
+    ]);
118
+    $session->setAdapter($files);
119
+    $session->start();
120
+
121
+    return $session;
122
+});

+ 9 - 0
app/controllers/ControllerBase.php

@@ -0,0 +1,9 @@
1
+<?php
2
+declare(strict_types=1);
3
+
4
+use Phalcon\Mvc\Controller;
5
+
6
+class ControllerBase extends Controller
7
+{
8
+    // Implement common logic
9
+}

+ 33 - 0
app/controllers/IndexController.php

@@ -0,0 +1,33 @@
1
+<?php
2
+declare(strict_types=1);
3
+
4
+class IndexController extends ControllerBase
5
+{
6
+
7
+    public function indexAction()
8
+    {
9
+
10
+	if(!$this->request->isPost()) exit();
11
+
12
+        if(isset($_POST['payload']) && $_POST['payload']){
13
+          $payload = json_decode($_POST['payload'],true);
14
+          $name = $payload['repository']['name'];
15
+
16
+          if(is_dir('/home/www/'.$name)){
17
+              system('cd /home/www/'.$name.';git pull',$return);
18
+            }else{
19
+              $repo = $payload['repository']['ssh_url'];
20
+              system('cd /home/www;git clone '.$repo.';git pull',$return);
21
+            }
22
+
23
+            return '请求成功';
24
+        }
25
+        return '请求错误';
26
+    }
27
+
28
+    public function show404Action(){
29
+        return 'UNKNOWN REQUEST';
30
+    }
31
+
32
+}
33
+

+ 21 - 0
app/views/index.phtml

@@ -0,0 +1,21 @@
1
+<!DOCTYPE html>
2
+<html>
3
+    <head>
4
+        <meta charset="utf-8">
5
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+        <meta name="viewport" content="width=device-width, initial-scale=1">
7
+        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
8
+        <title>Phalcon PHP Framework</title>
9
+        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
10
+        <link rel="shortcut icon" type="image/x-icon" href="<?php echo $this->url->get('img/favicon.ico')?>"/>
11
+    </head>
12
+    <body>
13
+        <div class="container">
14
+            <?php echo $this->getContent(); ?>
15
+        </div>
16
+        <!-- jQuery first, then Popper.js, and then Bootstrap's JavaScript -->
17
+        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
18
+        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
19
+        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
20
+    </body>
21
+</html>

+ 7 - 0
app/views/index/index.phtml

@@ -0,0 +1,7 @@
1
+<div class="page-header">
2
+    <h1>Congratulations!</h1>
3
+</div>
4
+
5
+<p>You're now flying with Phalcon. Great things are about to happen!</p>
6
+
7
+<p>This page is located at <code>views/index/index.phtml</code></p>

+ 8 - 0
public/.htaccess

@@ -0,0 +1,8 @@
1
+AddDefaultCharset UTF-8
2
+
3
+<IfModule mod_rewrite.c>
4
+    RewriteEngine On
5
+    RewriteCond %{REQUEST_FILENAME} !-d
6
+    RewriteCond %{REQUEST_FILENAME} !-f
7
+    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
8
+</IfModule>

+ 47 - 0
public/index.php

@@ -0,0 +1,47 @@
1
+<?php
2
+declare(strict_types=1);
3
+
4
+use Phalcon\Di\FactoryDefault;
5
+
6
+error_reporting(E_ALL);
7
+
8
+define('BASE_PATH', dirname(__DIR__));
9
+define('APP_PATH', BASE_PATH . '/app');
10
+
11
+try {
12
+    /**
13
+     * The FactoryDefault Dependency Injector automatically registers
14
+     * the services that provide a full stack framework.
15
+     */
16
+    $di = new FactoryDefault();
17
+
18
+    /**
19
+     * Read services
20
+     */
21
+    include APP_PATH . '/config/services.php';
22
+
23
+    /**
24
+     * Handle routes
25
+     */
26
+    include APP_PATH . '/config/router.php';
27
+    /**
28
+     * Get config service for use in inline setup below
29
+     */
30
+    $config = $di->getConfig();
31
+
32
+    /**
33
+     * Include Autoloader
34
+     */
35
+    include APP_PATH . '/config/loader.php';
36
+
37
+    /**
38
+     * Handle the request
39
+     */
40
+    $application = new \Phalcon\Mvc\Application($di);
41
+    //$request = new \Phalcon\Http\Request();
42
+    //$application->handle($request->getURI())->send();
43
+    $application->handle($_SERVER['REQUEST_URI'])->send();
44
+} catch (\Exception $e) {
45
+    echo $e->getMessage() . '<br>';
46
+    echo '<pre>' . $e->getTraceAsString() . '</pre>';
47
+}