Giter Site home page Giter Site logo

lowebf's People

Contributors

dependabot[bot] avatar lausek avatar

Watchers

 avatar  avatar  avatar

lowebf's Issues

New module for accessing predefined constants

Idea: Provide functionality for reading and converting superglobal values.

// version 1
$pageId = $env->variables()->get()->getAsInteger("pageId")->unwrapOr(1);

// version 2
$pageId = $env->variables()->get()->asInteger("pageId")->unwrapOr(1);

// version 3
$pageId = $env->variables()->get("pageId")->mapToInteger()->unwrapOr(1);

Alternative Names

  • superglobals
  • predefined
  • globals

Mockup

class VariableModule extends Module {
    // $_GET variable
    public function get() -> Array;
    // $_POST variable
    public function post() -> Array;
    // $_SERVER variable
    public function server() -> Array;
}
class Array {
    public static function from(array &$data) : Array;
    public function getAsInteger(string $name) : Result<int>;
    public function getAsFloat(string $name) : Result<float>;
    // ...
}

Add Result Type for handling Exceptions

Idea: Introduce a new class for wrapping up operation results or errors like a sum type.

Old code:

$env = lowebf\Environment::getInstance();
// will throw an exception
$posts = $env->posts()->loadPage(null);
// ...

New code:

$env = lowebf\Environment::getInstance();
// throws an exception like previous example
$posts = $env->posts()->loadPage(null)->unwrap();
// returns the result if found or exits script if not
$posts = $env->posts()->loadPage(null)->unwrapOrExit($env);
// ...

$env->listDirectory(null)
        ->mapOk(function ($folders) {
            // ... do something with folders ...
            return $folders;
        });

Mockup

class Result {
    const OK_STATE = 1;
    const ERROR_STATE = 2;

    /** @var int */
    private $state;
    private $argument;

    private function __construct(int $state, $argument);

    public static function ok($value) : Result;

    public static function error(Exception $e) : Result;

    public function isOk() : bool;

    public function isError() : bool;

    // try to return operations result.
    // throws exception if result is not successful.
    public function unwrap();

    // unwrap the result or use default
    public function unwrapOr($default);

    // clear output buffer and set status code
    public function unwrapOrExit(Environment $env, $statusCode = null);
   
    // if the result is ok -> pass it to $mapper and wrap it in a new result.
    // returns itself otherwise.
    public function mapOk(callable $mapper) : Result;
}

Make attribute access from configuration easier

Add new method to ConfigModule for reading nested attributes.

Example

Expected output:

  • $env->config()->getNested("site.db") should return ["host": "localhost"].
  • $env->config()->getNested("site.db.host") should return localhost.
site:
    db:
        host: "localhost"

Gallery-Feature

Requirements:

  • Save images as a group at a deterministic location
  • Support fixed creation date (do not rely on filemtime)
  • List available galleries by date (descending)
  • Associate Posts with Galleries.

Concept:

  • Save galleries at /data/galleries/<year>-<month>-<day>-<title>/...
  • New GalleryModule
    • load, loadOrCreate, loadGalleries
  • New data class Gallery
    • $date
    • $title
    • $items (image or video)
    • save
    • FUTURE: add, remove
  • Post now has an attribute gallery that stores the associated gallery id.
    • getGallery() : ?Gallery

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.