PHP code example of galactium / space

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

    

galactium / space example snippets


use Galactium\Space\Translation\Adapter\NestedArray;

$messages = [
    'title' => [
        'message' => 'Welcome'
    ],
];

$adapter = new NestedArray([
    'content' => $messages,
]);

json_encode($adapter->toArray());

use Galactium\Space\Translation\Adapter\NestedArray;

$messages = [
    'title' => [
        'message' => 'Welcome'
    ],
];

$adapter = new NestedArray([
    'content' => $messages,
]);

 echo $adapter->_('title.message'); // prints Welocme

use Galactium\Space\Translation\Loader\File;
use Galactium\Space\Translation\Manager;

$mainLanguage = 'en';
$fallbackLanguage = 'ru';

$translationManager = new Manager(new File('/path/to/messages/dir/'), $mainLanguage, $fallbackLanguage);

$mainLanguage = 'en';
$fallbackLanguage = 'ru';

$translationManager = new Manager(new File('/recourses/messages/'), $mainLanguage, $fallbackLanguage);

$translationManager->loadTranslation('Module::Common'); // to load only /recourses/messages/en/Module/Common.php

$translationManager->getLoadedTranslations() // return Galactium\Space\Translation\Adapter\NestedArray

use Galactium\Space\Mail\Manager;
use Phalcon\Config;

$transport = (new \Swift_SmtpTransport('smtp.service.com', 465, false))
    ->setUsername('user_name')
    ->setPassword('user_password');

$mailer = new \Swift_Mailer($transport);

$manager = new Manager($mailer, $transport, new Config([
    'views_dir' => '/path/to/views/dir/',
    'from' => [ // define a global 'from'
        'email' => '[email protected]',
        'name' => 'My Name'
    ]
]));

// create your first message: 
$mailManager->message()
            ->to('[email protected]')
            ->subject('Subject')
    	    ->body('Text')
    	    ->send();

// create using a volt template:
$mailManager->message()
            ->view('volt-template', [
                'user' => Users::findFIrst()
            ])
            ->to('[email protected]')
            ->subject('Subject')
    	    ->send();

// you can pass a callback to manipulate the view instance:
$mailManager->message()
            ->view('volt-template', [
                'user' => Users::findFIrst()
            ], function (ViewBaseInterface $view) {
			// code here ...
            })
            ->to('[email protected]')
            ->subject('Subject')
    	    ->send();


class Model implements IdentifiableInterface {
    public const MODULE_NAME = 'Module'
    public $id;
}

class Guids implements IntercatorInterface {
    public $guid;
}

$record = Model::findFirst(1);

$idetifier = (string) $record->identify(); // return 'module::namespace.model.id.1'

$guid = Guids::findFirst(1);

$interactedRecord = $guid->interacte() // same that Model::findFirst(1);

  use Galactium\Space\Seo\Manager;

  $seoManager = new Manager();

  $seoManager->breadcrumbs()->push('title','/link');

  $seoManager->get(); // returns Galactium\Space\Seo\Breadcrumbs\Breadcrumb[]
  

  use Galactium\Space\Seo\Manager;

  $seoManager = new Manager();

  $seoManager->metas()
              ->add(new Titile('Title'))
              ->add(new Description('Description'))
              ->add(new Keywords('Keywords'))
              ->add(new Canonical('/canonical'));

  foreach($seoManager->metas() as $meta){
      echo $meta->render();
  }
  

  use Galactium\Space\Seo\Manager;

  $seoManager = new Manager(); 

  $seoManager->openGraph()
             ->setType('opengrpah.type')
             ->setTitle('title')
             ->setDescription('description')
             ->if($item->hasImage(), function ($openGraph) use ($item) {
                 $openGraph->setImage($item->getImage()->getSrc());
             })
             ->setUrl('/href');

  

class Model {
    protected $append = [
        'full_name'
    ];
    public $id;
    public $first_name;
    public $last_name;
    
    public function getFullName()
    {
        return "{$this->first_name} {$this->last_name}"; 
    }
    
}
json_encode(Model::findFirst()); //returns all attrubutes and result of getFullName() method.

/resources
    /messages
        /en
            /Module
                Common.php
                Edit.php

/resources
    /messages
        /en
            /Module
                Module.php