PHP code example of reliv / pipe-rat-2

1. Go to this page and download the library: Download reliv/pipe-rat-2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reliv / pipe-rat-2 example snippets


'routes' => [
    /* Put your path here */
    'my.thing.find' => [
        /* Use standard route names for client simplicity */
        'name' => 'my.thing.find',
        
        /* Use standard route paths for client simplicity */
        'path' => 'my/thing',
        
        /* Wire each API independently */
        'middleware' => [
            RequestFormat::configKey()
            => RequestFormat::class,

            RequestAcl::configKey()
            => RequestAcl::class,

            RequestAttributes::configKey()
            => RequestAttributes::class,

            RequestAttributesValidate::configKey()
            => RequestAttributesValidate::class,

            /** <response-mutators> */
            ResponseHeaders::configKey()
            => ResponseHeaders::class,

            ResponseFormat::configKey()
            => ResponseFormat::class,

            ResponseDataExtractor::configKey()
            => ResponseDataExtractor::class,
            /** </response-mutators> */

            RepositoryFind::configKey()
            => RepositoryFind::class,
        ],
        
        /* Use route to find options at runtime */
        'options' => [
            RequestFormat::configKey() => [
                RequestFormat::OPTION_SERVICE_NAME
                => WithParsedBodyJson::class,

                RequestFormat::OPTION_SERVICE_OPTIONS => [],
            ],

            RequestAcl::configKey() => [
                RequestAcl::OPTION_SERVICE_NAME
                => IsAllowedNotConfigured::class,

                RequestAcl::OPTION_SERVICE_OPTIONS => [
                    IsAllowedNotConfigured::OPTION_MESSAGE
                    => IsAllowedNotConfigured::DEFAULT_MESSAGE
                        . ' for pipe-rat-2 resource: "{pipe-rat-2-config.resource-name}"'
                        . ' in file: "{pipe-rat-2-config.source-config-file}"',
                ],
            ],

            RequestAttributes::configKey() => [
                RequestAttributes::OPTION_SERVICE_NAMES => [
                    WithRequestAttributeFields::class
                    => WithRequestAttributeUrlEncodedFields::class,

                    WithRequestAttributeAllowedFieldConfig::class
                    => WithRequestAttributeAllowedFieldConfigFromOptions::class,

                    WithRequestAttributeExtractorFieldConfig::class
                    => WithRequestAttributeExtractorFieldConfigByRequestFields::class,

                    WithRequestAttributeWhere::class
                    => WithRequestAttributeUrlEncodedWhere::class,

                    WithRequestAttributeWhereMutator::class
                    => WithRequestAttributeWhereMutatorNoop::class,

                    WithRequestAttributeOrder::class
                    => WithRequestAttributeUrlEncodedOrder::class,

                    WithRequestAttributeSkip::class
                    => WithRequestAttributeUrlEncodedSkip::class,

                    WithRequestAttributeLimit::class
                    => WithRequestAttributeUrlEncodedLimit::class,
                ],

                RequestAttributes::OPTION_SERVICE_NAMES_OPTIONS => [
                    WithRequestAttributeAllowedFieldConfig::class => [
                        WithRequestAttributeAllowedFieldConfigFromOptions::OPTION_ALLOWED_FIELDS
                        /* @todo Over-ride with YOUR FieldsConfig */
                        => [
                            FieldConfig::KEY_TYPE => FieldConfig::COLLECTION,
                            FieldConfig::KEY_PROPERTIES => [],
                            FieldConfig::KEY_INCLUDE => true,
                        ],
                    ]
                ],
            ],
            
            RequestAttributesValidate::configKey() => [
                RequestAttributesValidate::OPTION_SERVICE_NAME
                => WithRequestValidAttributesAsserts::class,
            ],

            /** <response-mutators> */
            ResponseHeaders::configKey() => [
                ResponseHeaders::OPTION_SERVICE_NAME
                => WithResponseHeadersAdded::class,

                ResponseHeaders::OPTION_SERVICE_OPTIONS => [
                    WithResponseHeadersAdded::OPTION_HEADERS => []
                ],
            ],

            ResponseFormat::configKey() => [
                ResponseFormat::OPTION_SERVICE_NAME
                => WithFormattedResponseJson::class,

                ResponseFormat::OPTION_SERVICE_OPTIONS => [],
            ],

            ResponseDataExtractor::configKey() => [
                ResponseDataExtractor::OPTION_SERVICE_NAME => ExtractByType::class,
            ],
            /** </response-mutators> */

            RepositoryFind::configKey() => [
                RepositoryFind::OPTION_SERVICE_NAME
                => FindNotConfigured::class,

                RepositoryFind::OPTION_SERVICE_OPTIONS => [
                    FindNotConfigured::OPTION_MESSAGE
                    => FindNotConfigured::DEFAULT_MESSAGE
                        . ' for pipe-rat-2 resource: "{pipe-rat-2-config.resource-name}"'
                        . ' in file: "{pipe-rat-2-config.source-config-file}"',
                ],
            ],
        ],
        
        /* Use to define allowed methods */
        'allowed_methods' => ['GET'],
    ],
],