在php中声明一个Abstract类

时间:2017-03-05 10:24:14

标签: php abstract

我有2个班级 - A和B. 两者都应该使用.ini或.php的配置文件。 并且都有方法调用帖来从不同的api获取smth 什么是最好的设计方法?

我是否需要在构造函数中使用abstact和config。 ? 我只需拨打$ this-> config?

即可获得配置

例如:

abstract class parent
{
  constructor()
   {
   $this->config = "get file";
}
}

class a extends parent {
   ...
   how to use $this->conifg ? 

}
很多

1 个答案:

答案 0 :(得分:2)

只需在父类中定义一个函数,它会返回你的配置:

 public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
           ConfigureAuth(app);
        }
    }


public void ConfigureAuth(IAppBuilder app)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = clientId,
                    Authority = Authority,
                    PostLogoutRedirectUri = postLogoutRedirectUri,

                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {
                        //If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
                        AuthorizationCodeReceived = (context) =>
                        {
                            var code = context.Code;
                            ClientCredential credential = new ClientCredential(clientId, appKey);
                            string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
                            AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));
                            AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
                            code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);

                            return Task.FromResult(0);
                        }
                    }
                });
        }
相关问题