Giter Site home page Giter Site logo

bear.package's People

Contributors

apple-x-co avatar atakig avatar dependabot[bot] avatar fiahfy avatar hum2 avatar iteman avatar izayoi256 avatar jingu avatar kalibora avatar kawanamiyuu avatar kenchingh avatar kenjis avatar koriym avatar ktutumi avatar kumamidori avatar mackstar avatar madapaja avatar mugeso avatar naokitsuchiya avatar piotzkhider avatar remore avatar sasezaki avatar sosuke-ito avatar tanakahisateru avatar zukimochi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bear.package's Issues

[development] Instant edit enchancement

概要

開発画面でリソースに表示されるコード/テンプレートエディタを同じウインドウで表示する

2013-08-11 11 20 28

実装

  • iframe を追加?

検討

  • 固定サイズのエディタ画面にするか、リサイズハンドラ付でリソースと同じ大きさのエディタ画面にするか

Refactor API output

  • use REQUEST_URI method
  • use production application instance
  • use no exception handler for development
  • 400/404/503 simple text error
  • no asset access in cli-server

DI injection log

With this log, we can know

  • which dependency were exactly injected,
  • which setter injection method were called.
  • object scope (singleton) by object hash id

this log is also outputed by zf2-log.

 2013-02-26 22 25 17

Example of dependency modification.

SmartyProvider create Smarty instance.

class SmartyProvider implements Provide
{
    use TmpDirInject;
    use AppDirInject;

    /**
     * Return instance
     *
     * @return Smarty
     */
    public function get()
    {
        $smarty = new Smarty;
        $appPlugin = $this->appDir . '/vendor/libs/smarty/plugin/';
        $frameworkPlugin = __DIR__ . '/plugin';
        $smarty
            ->setCompileDir($this->tmpDir . '/smarty/template_c')
            ->setCacheDir($this->tmpDir . '/smarty/cache')
            ->setTemplateDir($this->appDir . '/Resource/View')
            ->setPluginsDir(array_merge($smarty->getPluginsDir(), [$appPlugin, $frameworkPlugin]) );

        return $smarty;
    }
}

SmartyConfigureProvider modify smarty object as we need..
This provider class can be changed by override binding.

class MySmartyConfigProvider implements ProviderInterface
{
    /**
     * @param Smarty $smarty
     *
     * @Inject
     */
    public function __construct(Smarty $smarty)
    {
        $this->smarty = $smarty;
    }

    /**
     * Return instance
     *
     * @return Smarty
     */
    public function get()
    {
        // config here

        return $this->smarty;
    }
}

SmartyModule connects all together.

class SmartyModule extends AbstractModule
{
    /**
     * Configure dependency binding
     *
     * @return void
     */
    protected function configure()
    {
        $this
            ->bind('BEAR\Sunday\Extension\TemplateEngine\TemplateEngineAdapterInterface')
            ->to(__NAMESPACE__ . '\SmartyAdapter')
            ->in(Scope::SINGLETON);
        $this
            ->bind('Smarty')
            ->annotatedWith('configured')
            ->toProvider(__NAMESPACE__ . '\SmartyConfigProvider');
        $this
            ->bind('Smarty')
            ->toProvider(__NAMESPACE__ . '\SmartyProvider')
            ->in(Scope::SINGLETON);
    }
}

SmartyAdapter needs @nAmed annotation to have "configured" dependency.

class SmartyAdapter implements TemplateEngineAdapterInterface
{
    ...

    /**
     * Constructor
     *
     * Smarty $smarty
     *
     * @Inject
     * @Named("configured")
     */
    public function __construct(Smarty $smarty)
    {
        $this->smarty = $smarty;
    }

素案でこういうのを考えてみました。
ping @tanakahisateru

Make public script global

Use global namespace to make reuse easier.
These are current public(htdoc) scripts.

  • public/web.php
  • public/api.php
  • public/index.php

Object serialize enabler

概要

オブジェクトがどんな値を保持してもシリアライズできる機能。プロパティにPDOオブジェクトやクロージャが含まれれば除去する。配列やオブジェクトは再帰で除去する。

(new Serailizer)->serialize($object);

プロパティにシリアライズ付加のものがあれば全て除去してシリアライズでエラーが出ないようにする。復元のためのシリアライズではなく、記録のためのシリアライズ。

用途

  • エラー/例外の時にアプリケーション状態を全て保存
  • develop時にアプリケーション状態を逐次保存してアプリケーション状態のスナップショットを保存する

検討事項

  • シリアライズできない変数を単に除去か、除去したオブジェクトの情報を含む除去ログオブジェクトに置換?

[performance] <head> contents output first

概要

HTMLの外部ファイルの読み込みを、PHPの実行完了前に開始する

2013-08-11 12 49 44

この図のように通常フレームワークの処理がすべて終わってから(ページレンダリングが完全に準備完了になってから)HTMLの出力が行われ、htmlの<head>の中で外部のスタティックなファイル(JS/CSS)を読み込み始める。

</head>タグまでが固定化されたものであるなら先にそれを出力すればレスポンス向上に貢献するのではないか。

実装

/**
 * @Pipleline(200)
 */

例)200のコードと</head>までの部分的な出力を依頼するアノテーション

検討事項

  • HTTPコードを先に決定しなければならない
  • PHPのフレームワークでBigPipeを実装しているものがあったとおもう
  • BEARはBigPipeの実装に向いているアーキテクチャ

Manual check / improvement

マニュアルの改善

  • マニュアルのサンプルが実際に問題なく行えるか
  • コメントが不適切でないか
  • 解説が必要な用語はないか

Keep same interface in aspect weaved object

概要

アスペクトを織り込んだオブジェクトのインターフェイスを変えない機能。現状はRay.Aopを使ってアスペクトを織り込むとWeaverクラス(アスペクトを織り込んだオブジェクトを委譲実行するクラス)にオブジェクトが変更されていしまう。

同じインターフェイスを保持するクラスを自動生成してアスペクトを含んでもインターフェイスが変わらないようにする。

利点

アスペクトを織り込んでもインターフェイスが変わらないので、インターフェイスに依存するインジェクトポイント(セッターやコンストラクター)でインジェクトが可能。

これまでもフレームワークのコンポーネントを入れ替える事が出来立たが、これが可能になれば全てのオブジェクトにアスペクトを織り込む事ができるようになる。

方法

例えば以下のクラスにアスペクトを織り込む事を考える。

interface doInterface
{
    public function doSomething($param1, $param2);
}

class Foo implements doInterface
{
    public function doSomething($param1, $param2)
    {
    }
}

以下のような「アスペクトを織り込んだオブジェクトを保持して、実行を委譲するクラス」を自動生成する。

class Foo_AspectWeaved extends Foo implements doInterface
{
    use AspectTrait;

    private $weaver;

    public function setWeaver($object, Weave $weaver)
    {
        $this->object = $object;
        $this->weaver = $weaver;
    }

    public function doSomething($param1, $param2)
    {
        return $this->weaver->doSomething($param1, $param2);
    }
}

自動生成はインターフェイスを保持したままメソッド実行をアスペクト織り込み済みのクラスに委譲する。プロパティアクセスはAspectTraitをuseする事でカバーする。

trait AspectTrait
{
    protected $object;

    /**
     * Return public property
     *
     * @param string $name
     *
     * @throws UndefinedProperty
     */
    public function __get($name)
    {
        if (isset($this->object->$name)) {
            return $this->object->$name;
        }
        throw new UndefinedProperty(__METHOD__ . ':' . get_class($this->object) . '::$' . $name);
    }

    /**
     * Set public property
     *
     * @param string $name
     * @param mixed  $value
     */
    public function __set($name, $value)
    {
        $this->object->$name = $value;
    }

    /**
     * Return string
     *
     * @return string
     */
    public function __toString()
    {
        return (string)$this->object;
    }

    /**
     * Return offsetExists
     *
     * @param mixed $offset
     *
     * @return bool
     * @throws \RuntimeException
     */
    public function offsetExists($offset)
    {
        if (!$this->object instanceof ArrayAccess) {
            throw new RuntimeException('ArrayAccess not allowed.');
        }

        return isset($this->object[$offset]);
    }

    /**
     * Return offset exists
     *
     * @param mixed $offset
     *
     * @return mixed
     * @throws \RuntimeException
     */
    public function offsetGet($offset)
    {
        if (!$this->object instanceof ArrayAccess) {
            throw new RuntimeException('ArrayAccess not allowed.');
        }

        return $this->object[$offset];
    }

    /**
     * Set
     *
     * @param string $offset key
     * @param mixed  $value
     *
     * @throws RuntimeException
     */
    public function offsetSet($offset, $value)
    {
        if (!$this->object instanceof ArrayAccess) {
            throw new RuntimeException('ArrayAccess not allowed.');
        }
        $this->object[$offset] = $value;
    }

    /**
     * Unset
     *
     * @param string $offset key
     */
    public function offsetUnset($offset)
    {
        unset($this->object[$offset]);
    }
}

実装

  • https://github.com/nikic/PHP-Parser を使いPHPをパース
  • パースしたPHPソースをこの形に組み直したクラスファイルを生成、何処かに保存してそれをrequireする
  • APC利用ならその自動生成ファイルはapc_compile_fileした後に消去可能

検討事項

  • こんな事できる?
  • Guiceも同じような方法?

Twig support

  • もう少しきちんとした実装を(パフォーマンス)
  • linkヘルパー

Skeleton project

Now we have a 3rd application - "Skeleton"

  • helloworld - minimum resource page example
  • sandbox - sandbox for testing, demo
  • skeleton - application skeleton

Developer starts project with this skeleton application.
Rename apps/Skeleton/* as well as composer.json for auto loading.

[development] Embedded REST client

概要

内蔵のRESTクライアント。

実装

2013-08-11 12 37 40

/dev/のリソースリストのオプションメソッドをクリックすると、そのメソッドに対応するフォームが現れてリソースリクエストをそのままwebで行う事ができる。

named arguments in method interceptor

target

    /**
     * @param string $title
     * @param string $body
     *
     * @Form
     */
    public function onPost($title, $body)
    {

before

     const TITLE = 0;
     const BODY = 1;

   public function invoke(MethodInvocation $invocation)
   {
        $args = $invocation->getArguments();
        if ($args[self::TITLE] === '') ...

we need to specify the the order of parameters.

after

   use NamedArgsInject;

   public function invoke(MethodInvocation $invocation)
   {
       $args = $this->namedArgs->get($invocation);
        if ($args['title'] === '') ...

with use NamedArgsInject, you can use "named parameter".

Composer\Downloader\TransportException in composer install

If you encounter the error as shown below,
もしインストールでこのようなエラーがでたら

[Composer\Downloader\TransportException]                                                                                   
  The "https://packages.zendframework.com/composer/Zend_Db-2.1.3.zip" file could not be downloaded (HTTP/1.1 404 Not Found)

try --prefer-source.
これで試してみて下さい。zipではなくgit cloneします。

$ curl -s https://getcomposer.org/installer | php
$ php composer.phar create-project --prefer-source --dev bear/package bear

Hope you will have no more problems with install.

Resource browser

for development and administrative purpose, developer can browse / add resource class file via web browser.

  • resource list
     2013-02-02 16 23 23
  • create new resource
     2013-02-02 16 30 42

bin/new_app.php

We can create 'MyApp' new application as follows.

bin/new_app.php MyApp

this "composer create-project" wrapping is not only to reduce the typing, but also the script can handle more complicated creation (choose component or compatibility control) later.

[development] phpdoc type checker

概要

コードとドキュメント品質向上のために、実行時にphpdocの型のチェックを行う。intやstringなど言語レベルでサポートされていない型のチェックも含める。

実装

  • アスペクトで
  • phpdocと実メソッドシグネチャーに相違がないか
  • 渡されたスカラー値とphpdocに違いがないかランタイムでチェックする
  • @params@returnの双方のチェック
  • 開発時のみ束縛する

検討事項

  • phpdocのパースのライブラリの選択
  • エラーの表現方法(例外?ログ?)
  • 修正の提案、あるいは自動修正?
  • phpdocのランタイム自動生成は?

[Performance] 304 Not Modified using Etag

概要

Etagを用いて無変更のコンテンツに対して304を返す。正しいHTTPレスポンスを返すとともにパフォーマンスアップを計る。

実装

  • RESTの特徴を持つBEARのリソースオブジェクトはリソースの変更をメソッドの外側から検知がしやすい。それを利用して、コンテンツの変更がないと確信できる仕組みをつくり適切に304を返す。
  • アスペクトとして実装。
class News extend AbstractObject
{
    /**
     * @NotModified
     */
    public function onGet()
    {

こういうニュースリソースがあったとして、リソースの状態変更は管理ツールで行うとする。変更したときにEtagを再生成するようにする。

failed to create new resource

php bin/new_res.php Sandbox page://self/one

New resource file path is wrong as  "apps/Sandbox/Resource/PageOne.php"

[development] `Halo` doesn't break screen layout

開発時にリソースの周囲に出る"ハロー"(リソース境界を示す線)とツールをリソースコンテンツの内側にだしてレイアウトが崩れないようにする

400 / 405

php web.php read /

should return 400 Bad Request

php web.php delete /

should return 405 Method Not Allowed

./{yourAppName} only accepts upper camel case at this moment?

While README.md tells like this,

$ php composer.phar create-project -s dev --dev bear/skeleton ./{yourAppName}

At /{yourAppName} parameter It seems "MyApp" works fine but "myApp" doesn't.

The error I've encountered today was:

[hoge@hostname public]# pwd
/tmp/bear/apps/myApp/public
[hoge@hostname public]# php api.php get /
500 Internal Server Error
x-exception-class: ["BEAR\\Package\\Provide\\Application\\Exception\\InvalidMode"]
x-exception-message: ["Invalid mode [Api], [MyApp\\Module\\ApiModule] class unavailable"]
x-exception-code-file-line: ["(0) \/tmp\/bear\/src\/BEAR\/Package\/Provide\/Application\/ApplicationFactory.php:51"]
x-exception-previous: ["-"]
x-exception-id: ["e500-7cfe3"]
x-exception-id-file: ["\/tmp\/bear\/scripts\/data\/log\/e500-7cfe3.log"]
cache-control: ["no-cache"]
date: ["Sun, 17 Feb 2013 16:24:34 GMT"]
[BODY]
Internal error occurred (e500-7cfe3)

Just my guess but it looks weird that x-exception-message uses upper camel case for application name.

Cache doesn't work

BEAR\Sunday\Module\Constant\NamedModule::__construct() must be of the type array, null given, called

This error triggered when cache is on and load two page.
It seems AppModul::configure() called without constructor method does not called.

Request in shutdown

概要

リソースリクエストを画面表示前ではなく、PHP終了時に行う。リソースのレイジーリクエスト。

例えばmixiの足跡機能を考えてみる。画面表示前にDB操作を行う必要はなく、画面を表示してから行えばレスポンスが向上する。

実装

例1)
shutdownQueに対してアタッチされたリクエストはPHP終了時に行われる

use ShtdownQueInject;

public function onGet()
{
    $this->shutdownQue->attach([
        $this->resource->post->uri('app://self/footprint')->request(),
        $this->resource->post->uri('app://self/admin/log')->request()
    ]);
}
  • ShtdownQueInjectに__destructメソッドを含ませそこでrequest処理を行うか、register_shutdown_function()で終了後のリクエストを登録する
  • あるいはjob queで

Resource browser

for development and administrative purpose, developer can browse / add resource class file via web browser.

  • resource list
     2013-02-02 16 23 23
  • create new resource
     2013-02-02 16 30 42

Graph visualizer

概要

依存グラフの描画。現在のprint_oのような(あるいは進化させた)もの。

grapher_screenshot

この図はGuiceのオブジェクトグラファーによるもの https://code.google.com/p/google-guice/wiki/Grapher

  • オブジェクトの依存、DIグラフ。
  • リソースの依存とリンクのリソースのリソースグラフ。

効果

  • アプリケーションがもつリソース情報の関連性の可視化
  • プログラミング実装の可視化

実装

検討

  • 要素をダブルクリックするとエディタが開くのはどうでしょうか

[Performance] Prepared statement cache

概要

リソースオブジェクトのメソッド全体をプリペアードステートメントと見なして扱うアスペクトを用意してクエリーキャッシュを使いパフォーマンスのアップを計る。

/**
 * @param null $id
 *
 * @Statement
 */
public function onGet($id = null)
{
    $sql = "SELECT id, title, body, created, modified FROM {$this->table} WHERE id = :id";
    $stmt = $this->db->prepare($sql);
    $stmt->bindValue('id', $id);
    $stmt->execute();
    $this->body = $stmt->fetch(PDO::FETCH_ASSOC);
}

例えば上記メソッドなら、最初のリクエストはprepareが必要だが次回のクエリーはそのprepareの結果を利用して'bindValue'と'execute'だけを行いbodyにセットする。

実装

@Statementがアノテートされているメソッドに適用するアスペクトとして実装。

効果

速度。特にn+1系、リソースリンクで繰り返し単純なSQLを発行するときに有効では?

検討事項

  • ステートメントの取得は最後のpreparedクエリー、あるいは結果としてのどちらが可能か?
  • 引き数でIDをつくり、メソッドの複数のクエリーに対応する

method "HEAD"

exception 'BEAR\Resource\Exception\MethodNotAllowed' with message 'MyApp\Resource\Page\Index::onHead()

in Sakura VPS, but not in OSX local apache environment.
Router should not accept HEAD. (or onHead method check ?)

Reduce minimum requirement

Remove requirement ini setting

  • apc.enable_cli
  • xhprof.output_dir

apc.enable_cli - provide mock function script
xhprof.output_di - use sys_get_temp_dir

Automated test code creation

概要

テスト・スクリプトの自動生成

実装

  • リソースリクエストログからリソースリクエストDSLコードを生成
  • Web test
    • 選択したDOMのパスを生成し、ターゲットのDOMクエリーを自動生成
    • webでの連続したアクションをリソースログとして記録、再生できる機能
  • eagerのリソースリクエストをlazyにして、リクエストの結果ではなく意図をテストできるようにする機能

検討

  • UIは?フルスクラッチ?AnguluarJS ?

'Dev' mode reload error.

If you start with 'Dev' mode the Web server,
public/web.php

$mode = 'Dev';
% php -S localhost:8088 web.php

The first request succeeds, but the second fail.

Probably 'src/Bear/Resource/Devinvoker.php' is related to this error.
It works when using the "Invoker" instead of "Devinvoker".

src/BEAR/Package/Module/Resource/DevResourceModule.php

protected function configure()
    {
        // DBAL debug
        $this->bind('Doctrine\DBAL\Logging\SQLLogger')->to('Doctrine\DBAL\Logging\DebugStack')->in(Scope::SINGLETON);
        // Common debug
        //$this->bind('BEAR\Resource\InvokerInterface')->to('BEAR\Resource\DevInvoker')->in(Scope::SINGLETON);
        $this->bind('BEAR\Resource\InvokerInterface')->to('BEAR\Resource\Invoker')->in(Scope::SINGLETON);
        $this->install(new ProvideModule\ResourceView\DevRendererModule($this));
        $this->installDevLogger();
    }

英語自信ないので日本語で補足します。
'Dev'モードの時、どのページでもいいので一旦表示させたあとにリロードするとwebサーバーがsegmentation faultで落ちてしまいます。
Invorkerを使うようにすると普通に動くので、DevInvokerが関係していそう、というところまでは調べたのですがその先が追えていません。

Stub module

@koriym $mode = 'Stub';が小文字、config/stubパスがデフォルトのSandboxスケルトンとマニュアルでずれているような気がします。

— kuma_nana (@kuma_nana) July 18, 2013
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

BEAR.Sundayのブログチュートリアルが古いみたいで指示通りにやってもスタブ使えない…ディレクトリ構成も随分変わってるみたいだしつらい…

— halt (@Halt) August 13, 2013
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

@halt あぁぁ…. ディレクトリ構成は確かに古いものと今とでは変わってますね….

— NEKOGET (@NEKOGET) August 13, 2013
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

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.