コード例 #1
0
 /**
  * @param Slim $app
  * @param Resolver $resolver
  */
 public function register(Slim $app, Resolver $resolver)
 {
     $app->get('/', function () use($app) {
         $app->redirectTo('transfer_form');
     });
     $app->get('/transfer-form', $resolver->resolve($app, 'ewallet.transfer_form_controller:showForm', function () {
         return [Identifier::fromString('ABC')];
     }))->name('transfer_form');
     $app->post('/transfer-funds', $resolver->resolve($app, 'ewallet.transfer_funds_controller:transfer', function () use($app) {
         /** @var \EwalletModule\Bridges\Zf2\InputFilter\TransferFundsInputFilterRequest $request */
         $request = $app->container->get('ewallet.transfer_filter_request');
         $request->populate($app->request->post());
         return [$request];
     }))->name('transfer_funds');
 }
コード例 #2
0
 /**
  * @param string $routeName
  * @param string $tableName
  * @param callable $customCRUDFunction
  * @param string $displayName
  */
 public function add($routeName, $customCRUDFunction = null, $tableName = null, $displayName = null)
 {
     if ($tableName == null) {
         $tableName = $routeName;
     }
     $this->tableList[$routeName] = $tableName;
     $this->tableDisplayName[$routeName] = $displayName;
     $this->routeNameList[] = $routeName;
     /*
      * Page Group (ListView, CreateView, EditView)
      */
     $this->slim->group("/" . $this->groupName . "/" . $routeName, function () use($routeName, $customCRUDFunction, $tableName) {
         $this->slim->get("/", function () use($routeName) {
             $this->slim->redirectTo("_louisCRUD_" . $routeName);
         });
         /*
          * ListView
          */
         $this->slim->get("/list(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->listviewFunction != null) {
                 $listviewFunction = $this->listviewFunction;
                 $result = $listviewFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->isEnabledListView()) {
                 $this->renderListView();
             }
         })->name("_louisCRUD_" . $routeName);
         /*
          * Create
          */
         $this->slim->get("/create(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->createFunction != null) {
                 $createFunction = $this->createFunction;
                 $result = $createFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // Force Hide ID field
             $this->field("id")->hide();
             if ($this->isEnabledCreate()) {
                 $this->renderCreateView();
             }
         });
         /*
          * Edit
          */
         $this->slim->get("/edit/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             // Load Bean first
             $this->loadBean($id);
             // ID must be hidden
             $this->field("id")->hide();
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->editFunction != null) {
                 $editFunction = $this->editFunction;
                 $result = $editFunction($id, $p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // If user show the ID field, force set it to readonly
             $this->field("id")->setReadOnly(true);
             if ($this->isEnabledEdit()) {
                 $this->renderEditView();
             }
         });
         /*
          * Export Excel
          */
         $this->slim->map("/export(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->listviewFunction != null) {
                 $listviewFunction = $this->listviewFunction;
                 $result = $listviewFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->exportFunction != null) {
                 $exportFunction = $this->exportFunction;
                 $result = $exportFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // TODO: isEnabledExport();
             $this->renderExcel();
         })->via('GET', 'POST');
     });
     /*
      * API Group, RESTful style.
      */
     $this->slim->group("/" . $this->apiGroupName . "/" . $routeName, function () use($routeName, $customCRUDFunction, $tableName) {
         /*
          * JSON for Listview
          */
         $this->slim->map("/list(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             $this->enableJSONResponse();
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->listviewFunction != null) {
                 $listviewFunction = $this->listviewFunction;
                 $result = $listviewFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->isEnabledListView()) {
                 $this->getJSONList();
             }
             return;
         })->via('GET', 'POST');
         /*
          * For Datatables
          */
         $this->slim->map("/datatables(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             $this->enableJSONResponse();
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->listviewFunction != null) {
                 $listviewFunction = $this->listviewFunction;
                 $result = $listviewFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->isEnabledListView()) {
                 $this->getListViewJSONString();
             }
             return;
         })->via('GET', 'POST');
         /*
          * View a bean
          * PUT /api/{tableName}/{id}
          */
         $this->slim->get("/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             // Load Bean
             $this->loadBean($id);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             // Custom Global Function
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // Custom Edit Function
             if ($this->editFunction != null) {
                 $editFunction = $this->editFunction;
                 $result = $editFunction($id, $p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // Force hide ID
             $this->field("id")->hide();
             // Insert into database
             if ($this->isEnabledEdit()) {
                 $json = $this->getJSON(false);
                 $this->enableJSONResponse();
                 echo $json;
             }
         });
         /*
          * Insert a bean
          * POST /api/{tableName}
          */
         $this->slim->post("(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // Custom Global Function
             $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
             if ($result === false) {
                 return;
             }
             // Custom Create Function
             if ($this->createFunction != null) {
                 $createFunction = $this->createFunction;
                 $result = $createFunction($p1, $p2, $p3, $p4, $p5);
             }
             if ($result === false) {
                 return;
             }
             // Force hide ID
             $this->field("id")->hide();
             // Insert into database
             if ($this->isEnabledCreate()) {
                 $jsonObject = $this->insertBean($_POST);
                 $this->enableJSONResponse();
                 echo json_encode($jsonObject);
             } else {
                 // TODO: Should be json object
                 echo "No permission";
             }
         });
         /*
          * Update a bean
          * PUT /crud/{tableName}/{id}
          */
         $this->slim->put("/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             // Load Bean
             $this->loadBean($id);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             // Custom Global Function
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // Custom Create Function
             if ($this->editFunction != null) {
                 $editFunction = $this->editFunction;
                 $result = $editFunction($id, $p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // Force hide ID
             $this->field("id")->hide();
             // Insert into database
             if ($this->isEnabledEdit()) {
                 $jsonObject = $this->updateBean($this->slim->request()->params());
                 $this->enableJSONResponse();
                 echo json_encode($jsonObject);
             }
         });
         /*
          * Delete a bean
          * DELETE /crud/{tableName}/{id}
          */
         $this->slim->delete("/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
             // MUST INIT FIRST
             $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
             $this->enableJSONResponse();
             $this->loadBean($id);
             if ($this->configFunction != null) {
                 $function = $this->configFunction;
                 $result = $function();
                 if ($result === false) {
                     return;
                 }
             }
             // Custom Global Function
             if ($customCRUDFunction != null) {
                 $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             // Custom Delete Function
             if ($this->deleteFunction != null) {
                 $deleteFunction = $this->deleteFunction;
                 $result = $deleteFunction($id, $p1, $p2, $p3, $p4, $p5);
                 if ($result === false) {
                     return;
                 }
             }
             if ($this->isEnabledDelete()) {
                 $this->deleteBean();
                 $result = new \stdClass();
                 $result->status = "succ";
                 echo json_encode($result);
             }
         });
     });
 }