PHP code example of php-enspired / peekaboo

1. Go to this page and download the library: Download php-enspired/peekaboo 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/ */

    

php-enspired / peekaboo example snippets


use at\peekaboo\ {
  HasMessages,
  MessageMapper
};

class Foo implements HasMessages {
  use MessageMapper;
}

$formatted = new Foo()->makeMessage("foo.welcome", ["place" => "jungle"]);
// Welcome to the jungle, we've got fun and games


use at\peekaboo\MessageRegistry;

MessageRegistry::register($yourDefaultResourceBundle);
MessageRegistry::register($yourUserResourceBundle, "user");

$formatted = MessageRegistry::message("users.namebadge", ["name" => "Adrian"], "ja_JP", "user");


use function at\peekaboo\_;

$formatted = _("users.namebadge", ["name" => "Adrian"], "ja_JP", "user");



$formatted = MessageRegistry::messageFrom($yourUserResourceBundle, "users.namebadge", ["name" => "Adrian"], "ja_JP");


use at\peekaboo\MessageBundle;

$myBundle = new MessageBundle(["welcome-user" => "Welcome to the {place}, {name}!"]);
echo MessageRegistry::messageFrom($myBundle, "welcome-user", ["name" => "Adrian", "place" => "jungle"]);
// Welcome to the jungle, Adrian!



class Foo implements HasMessages {
  use MessageMapper;

  public const array MESSAGES = [
    "foo" => [
      "welcome" => "Welcome to the {place}, we've got fun and games"
    ]
  ];
}

new Foo()->makeMessage("foo.welcome", ["place" => "jungle"]);
// Welcome to the jungle, we've got fun and games



use at\peekaboo\MessageEnum;

enum Woo : string implements EnumeratesMessages {
  use MessageEnum;

  case Welcome = "Welcome to the {place}, we've got fun and games";
}

Woo::Welcome->message(["place" => "jungle"]);
// Welcome to the jungle, we've got fun and games