galactium/space
Composer 安装命令:
composer require galactium/space
包简介
Galactium Space
关键字:
README 文档
README
Galactium Space is a light library to provide extended functionality for Galactium projects.
Requirements
- PHP 7.1 or above
- Phalcon 3.3
Installation
composer require galactium/space
Components
Translation
New Translation Adapter: NestedArray:
- implements \JsonSerializable interface:
use Galactium\Space\Translation\Adapter\NestedArray; $messages = [ 'title' => [ 'message' => 'Welcome' ], ]; $adapter = new NestedArray([ 'content' => $messages, ]); json_encode($adapter->toArray());
- supports "dot"-navigation:
use Galactium\Space\Translation\Adapter\NestedArray; $messages = [ 'title' => [ 'message' => 'Welcome' ], ]; $adapter = new NestedArray([ 'content' => $messages, ]); echo $adapter->_('title.message'); // prints Welocme
Translation Manager
- Supports fallback language;
- Supports Loader to load translations
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);
- Supports hierarchically messages directories:
/resources
/messages
/en
/Module
Common.php
Edit.php
$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
If you don't need multiple language files in Module directory, you can put to them translation file with the
same name:
/resources
/messages
/en
/Module
Module.php
- All lodaded translations are returned in single NestedArray adapter:
$translationManager->getLoadedTranslations() // return Galactium\Space\Translation\Adapter\NestedArray
Please note: Translation Manager works only with NestedArray Adapter.
Mailer wrapper of swiftmailer/swiftmailer.
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' => 'example@test.com', 'name' => 'My Name' ] ]));
// create your first message: $mailManager->message() ->to('test@test.com') ->subject('Subject') ->body('Text') ->send();
// create using a volt template: $mailManager->message() ->view('volt-template', [ 'user' => Users::findFIrst() ]) ->to('test@test.com') ->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('test@test.com') ->subject('Subject') ->send();
You can use {{ _message }} to get access to Message instance in your template. For example, it can be used to insert an image as embed content:
<img src="{{ _message.embed('/path/to/image.png') }}" alt="my image">
Identifier
The identifier has been developed to easily convert a model's key params (like module, namespace, table name, identity field, and it's value) to string.
Identifier Manager can generate GUID (Galactium Unique Identifer) in format: module::namespace.class.dotted.params
for a model which implements Galactium\Space\Identifier\IdentifiableInterface interface.
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);
By default Identifer supports only Galactium's class structure.
Errors Manager
Errors Manager provide a simple error handling for an app. It is used to catch all exceptions generated by an app and converting them to beautiful response.
Seo
Seo Component includes:
-
Breadcrumbs
use Galactium\Space\Seo\Manager; $seoManager = new Manager(); $seoManager->breadcrumbs()->push('title','/link'); $seoManager->get(); // returns Galactium\Space\Seo\Breadcrumbs\Breadcrumb[]
-
Meta information
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(); }
-
OpenGraph
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');
-
SchemaOrg (Factory for Spatie\SchemaOrg)
You can get access to all components listed above using Galactium\Space\Seo\Manager.
Other improvements
\Galactium\Space\Mvc\Modelhas a special field$appendYou can easily overwrite or add any attribute to json.
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.
Please note: For some reasons
$appenddoesn't work in some cases.
License
This library is licensed under the Apache 2.0 License - see the LICENSE.md file for details.
galactium/space 适用场景与选型建议
galactium/space 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 90 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「phalcon」 「space」 「galactium」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 galactium/space 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 galactium/space 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 galactium/space 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Public Space Plugin for CakePHP
Replaces regular space with a non-breaking space in places where line break should not occur as per Czech language spec
Package for manipulating colors in multiple color spaces.
Space invoices PHP sdk
Simple package to read system information
Inbox pattern process implementation for your Laravel Applications
统计信息
- 总下载量: 90
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2018-09-25