アプリ関連ニュース

[Laravel] Passportを使用したBearer token認証[1]

PHPのLaravelフレームワークのPassportを使用したBearer token認証の方法について紹介いたします。今回はPassport実装テスト用のプロジェクトを準備するところまでを説明します。

続きを読む

iMovieを使ってみよう

Macに付属する動画編集アプリのiMovieを使って
簡単な動画編集をやってみます。

続きを読む

Singleton Design Pattern

Singleton is one of the creational design pattern that allows you to ensure that a class has only one instance, while providing a global access point to this instance.

Make the single instance object class responsible for creation, initialization, access, and execution. Declare the instance as a member of private static data. Provides a public static member function that encapsulates all initialization code and provides access to the instance.

The client calls the access function (using the class name and the scope resolution operator) whenever a reference to the single instance is required.

The singleton should be considered only if the following three criteria are met:

Single instance ownership cannot reasonably be assigned
Lazy initialization is desirable
Global access is not provided otherwise

Lets take a look at code samples

PHP code sample

<?php

/**
 * Singleton class
 */
class LogSingleton {
    /**
     * I kept this attribute and constructor as private so that other sub class can't instantiate
     * it can also be protected if you want to allow sub classes to be instantiated
     */
    private static $intance = null;

    private function __construct() {
    }

    /**
     * I will assign the singleton instance if $instance is null.
     * otherwise will return directly.
     */
    public static function log() {
      if (self::$intance == null) {
         self::$intance = new LogSingleton();
      }
      return self::$intance;
    }

    //can also declare other public functions below.
    public function debugLog()
    {
      return "debug log";
    }
  }

//client code
$client = LogSingleton::log(); // this is the singleton instance.
var_dump($client->debugLog());

C# sample code

using System;

namespace HelloWorld
{
    class LogSingleton
    {
        /**
         * I kept this attributes as private so that other sub class can't instantiate
         * it can also be protected if you want to allow sub classes to be instantiated
         */
        private static LogSingleton instance;

        /**
         * for the first use for this class, s_lock will have a object.
         * This will later use along with lock function to protect from multi thread base.
         */
        private static readonly object s_lock = new object();

        public static LogSingleton log()
        {
            if (instance == null)
            {
                /**
                 * The client who has s_lock will proceed this condition.
                 */
                lock (s_lock)
                {
                    /**
                     * I will assign the singleton instance if instance is null.
                     * otherwise will return directly.
                     */
                    if (instance == null)
                    {
                        instance = new LogSingleton();
                    }
                }
            }
            return instance;
        }

        //can also declare other public functions below.
        public string debugLog()
        {
            return "debug log";
        }

        //client code
        class Program
        {
            static void Main(string[] args)
            {
                var client = LogSingleton.log(); // this is the singleton instance.
                Console.WriteLine(client.debugLog());

            }
        }
    }

}

By Yuuma



[Laravel] sessionの共有について

過去記事「[Laravel] 設定ファイル「.env」の切り替えについて」にて、URLのパス指定により、複数の「.env」設定ファイルの切り替えをおこなう方法を紹介いたしました。
今回は上記過去記事の補足説明となります。

続きを読む

Windows 95発売から25年が経ちました

Microsoft がWindows 95発売から25周年を
記念した動画をYoutube上で公開していました。

続きを読む

アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム