<commit_before><?php

namespace DreamFactory\Core\Resources\System;

use DreamFactory\Core\Enums\ApiOptions;
use DreamFactory\Core\Exceptions\BadRequestException;
use DreamFactory\Core\Models\App as AppModel;
use DreamFactory\Core\Utility\Packager;

class App extends BaseSystemResource
{
    protected function handleGET()
    {
        if(!empty($this->resource)){
            if($this->request->getParameterAsBool('pkg')){
                $includeFiles = $this->request->getParameterAsBool('include_files');
                $includeServices = $this->request->getParameterAsBool('include_services');
                $includeSchema = $this->request->getParameterAsBool('include_schema');
                $includeData = $this->request->getParameterAsBool('include_data');
                $services = explode(',', $this->request->getParameter('services'));

                $package = new Packager($this->resource);

//                $services = [
//                    [
//                        'name' => 'mysql',
//                        'component' => 'Events,todo'
//                    ],
//                    [
//                        'name' => 'dfdev'
//                    ],
//                    [
//                        'name' => 'email'
//                    ],
//                    [
//                        'name' => 'system'
//                    ],
//                    [
//                        'name' => 's3'
//                    ]
//                ];

                $package->setExportItems($services);
                return $package->exportAppAsPackage($includeFiles, $includeServices, $includeSchema, $includeData);
            }
        }
        return parent::handleGET();
    }

    /**
     * Handles PATCH action
     *
     * @return \DreamFactory\Core\Utility\ServiceResponse
     * @throws BadRequestException
     * @throws \Exception
     */
    protected function handlePATCH()
    {
        if (!empty($this->resource)) {
            if ($this->request->getParameterAsBool(ApiOptions::REGENERATE)) {
                /** @var AppModel $appClass */
                $appClass = $this->model;
                $app = $appClass::find($this->resource)->first();
                $app->api_key = $appClass::generateApiKey($app->name);
                $app->save();
            }
        }<commit_msg>Package export to use POST with GET verb-tunneling<commit_after><?php

namespace DreamFactory\Core\Resources\System;

use DreamFactory\Core\Enums\ApiOptions;
use DreamFactory\Core\Exceptions\BadRequestException;
use DreamFactory\Core\Models\App as AppModel;
use DreamFactory\Core\Utility\Packager;

class App extends BaseSystemResource
{
    protected function handleGET()
    {
        if(!empty($this->resource)){
            if($this->request->getParameterAsBool('pkg')){
                $includeFiles = $this->request->getParameterAsBool('include_files');
                $includeServices = $this->request->getParameterAsBool('include_services');
                $includeSchema = $this->request->getParameterAsBool('include_schema');
                $includeData = $this->request->getParameterAsBool('include_data');
                $services = $this->getPayloadData('services');
                $package = new Packager($this->resource);
                $package->setExportItems($services);
                return $package->exportAppAsPackage($includeFiles, $includeServices, $includeSchema, $includeData);
            }
        }
        return parent::handleGET();
    }

    /**
     * Handles PATCH action
     *
     * @return \DreamFactory\Core\Utility\ServiceResponse
     * @throws BadRequestException
     * @throws \Exception
     */
    protected function handlePATCH()
    {
        if (!empty($this->resource)) {
            if ($this->request->getParameterAsBool(ApiOptions::REGENERATE)) {
                /** @var AppModel $appClass */
                $appClass = $this->model;
                $app = $appClass::find($this->resource)->first();
                $app->api_key = $appClass::generateApiKey($app->name);
                $app->save();
            }
        }
{'fraction_non_alphanumeric': 0.13843175217812198, 'fraction_numerical': 0.0002420135527589545, 'mean_word_length': 1.842503438789546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5368449', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1030, 'n_words': 159}