Laravel 에서 xdebug 를 통해 디버깅하는 과정을 알아본다.


0. PHP 설치

brew install php71

1. Xdebug 설치 


brew install homebrew/php/<php-version>-xdebug 에서 <php-versino>을 자기에 맞는 php 버전으로 치환 아래는 예제

brew install homebrew/php/php71-xdebug


2. Xdebug 설정 변경하기


맥에서의 위치: /usr/local/etc/php/7.1/conf.d


[xdebug]
zend_extension="/usr/local/opt/php71-xdebug/xdebug.so"
xdebug.remote_autostart=1
xdebug.default_enable=1
xdebug.remote_port=9001
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM


3. phpstorm run configuraiton 추가


- run configuration 에 들어간후 아래와 같이 PhpWeb Application 을 추가한다



- severs 옆버튼인 ...을 클릭해서 서버를 추가해준다


- + 버튼을 클릭하여 서버를 추가해주고

Host부분을 디버깅하고자 하는 주소를 입력한다

* 주의사항

Use path mappings 를 체크해제한다



Ok를 눌러 돌아온다


4. Phpstorm 의 설정부분에서 Php항목의 Debug 항목을 선택 DBGp Proxy 부분을 아래 스크린샷과 같이 변경. 

IDE key와 Port는 위 Xdebug설정에 맞춰서 입력해주면 된다. 자기 입맛에 맞게 커스터마이즈 하면된다


5. 실제 디버깅하고 싶은 곳에 브레이크 포인트를 설정하고 Debug 버튼을 클릭하면 아래 화면과 같이 해당하는 곳에서 디버거가 멈춰져 있는 것을 확인 가능하다. 



참조: 

1. https://laravel-news.com/xdebug-phpstorm-valet

'PHP > Laravel' 카테고리의 다른 글

Laravel 구동을 위한 Vagrant 설치 및 설정  (0) 2016.09.13

PHP 프로젝트를 이용할떄 Composr 를 이용해서 본인이 사용한 작성한 클래스를 불러와 사용하는 방법에 대해 서술한다. 


절차:


0. composer 설치및 composer init

1. PSR-4 표준에 맞는 폴더구조로 클래스파일과 함께 생성 (이때 네임스페이스에 주의한다)  

2. composer.json 에 폴더 연결 

"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php",
"tests/PassportTestCase.php"
],
"psr-4": {
"Tests\\": "tests/"
}
},

3. composer auto-dumpload 를 하면 클래스 위치들을 맵핑해주는 파일이 자동 생성된다.

4. 클래스를 사용하고자 하는 파일에서 autoload.php 파일 로드


** 주의점:

1. 클래스명과 파일명이 일치

2.한파일에는 클래스 하나만 존재


예제 파일구조를 본다

src

autoload.php

index.php

Users

User.php

UserDetail.php



index.php 에서 사용하자하면

require("./autoload.php")


- User.php 

<?php namespace Users;


class User { }


- UserDetail.php 

<?php namespace Users;


class UserDetail { }


- index.php


<?php

use Users\User;

$user = new User();








'PHP > PHP 문법' 카테고리의 다른 글

설치된 PHP가 threadsafe 혹은 nonthreadsafe 인지 알아내는법  (0) 2016.07.23
DB접속 (MySQL 기준)  (0) 2016.04.21

ES5.1

var myobj = (function () {

    // private members

    var name = "my, oh my";

    // implement the public part

    return {

        getName: function () {

            return name;

        }

    };

}());

myobj.getName(); // "my, oh my"



메모리 아끼는법 

function Gadget() {

    // private member

    var name = 'iPod';

    // public function

    this.getName = function () {

        return name;

    };

}

Gadget.prototype = (function () {

    // private member

    var browser = "Mobile Webkit";

    // public prototype members

    return {

        getBrowser: function () {

            return browser;

        }

    };

}());

 

 

ES6 

class Gadget {

var name = 'iPod'

getName() {

return name; 

}



static getBrowser() {

  var browser = "Mobile Webkit";

  return browser;

  }

}

 

 

ES2021+

class Gadget {

  #name = 'iPod'

  getName() {

  return name; 

  }
}

 

참조: 

http://www.2ality.com/2016/01/private-data-classes.html

3.x 버전대가 2016년 12월을 기준으로 종료된다기에 기존 3.2.9 버전의 스프링에서 4.x 버전대로 마이그레이션을 시도하였다.


다행히도 기존 진행하는 프로젝트에서 3.x 


Pom.xml 에서 주의해서 

<properties> <java-version>1.8</java-version> <org.springframework-version>4.3.5.RELEASE</org.springframework-version> <org.springframework-security-version>4.2.0.RELEASE</org.springframework-security-version> </properties> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- MappingJacksonJsonView --> <!-- <dependency> --> <!-- <groupId>org.codehaus.jackson</groupId> --> <!-- <artifactId>jackson-mapper-asl</artifactId> --> <!-- <version>1.9.13</version> --> <!-- </dependency> --> <!-- <dependency> --> <!-- <groupId>org.codehaus.jackson</groupId> --> <!-- <artifactId>jackson-core-asl</artifactId> --> <!-- <version>1.9.13</version> --> <!-- </dependency> -->


다른 Configuration  파일들도 schemaLocation 부분에 수정을 해주었다. xxx-3.0.xsd 로 로된부분을

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    					http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
        
</beans>


자동으로 인식하도록 숫자부분을 아래와 같이 변경했다.

http://www.springframework.org/schema/context/spring-context.xsd



resources 부분도 아래와 같이 변경했다.

<mvc:resources location="/public/" mapping="public/**"/>
<mvc:resources location="/css/" mapping="css/**"/>
<mvc:resources location="/images/" mapping="images/**"/>
<mvc:resources location="/js/" mapping="js/**"/>


JacksonJsonView를 사용하지 않기때문에 주석처리하였다 사용하기 위해서는 2버전을 사용해야한다.

<!-- <bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> -->


이렇게 하여 마이그레이션이 완료되었다.

마이그레이션은 프로젝트 마다 케이스바이 케이스기 떄문에 스프링버전에 의존하는 라이브러리가 없나 살펴보아야한다.

더 자세한 마이그레이션 관련은 아래에 링크된 스프링 공식홈페이지의 깃허브를 참조한다. 


참조:

1. https://github.com/spring-projects/spring-framework/wiki/Migrating-from-earlier-versions-of-the-spring-framework

'Java > Spring Framework' 카테고리의 다른 글

Spring 한글설정  (0) 2015.03.19
Spring AOP  (0) 2015.01.19
스프링 스터디 - 의존성 주입 대상  (0) 2015.01.14
스프링 학습 개발 도구 설치  (0) 2015.01.13
프레임 워크 배우기 좋은 웹사이트  (0) 2014.11.04

파이썬 디버깅시 유용하게 사용하는 Ipdb로 디버깅하는 도중 루프안에 같혀 강제 종료해야할 경우 

아래 혹은

import sys
sys.exit()

아래의 방법으로 시도한다 (2.7과 3.5 버전의 경우 현재 확인결과 아래 방법으로 작동되었다)

import os
os._exit(0)


본래 서버 개발자이지만 이번에 양기종 앱을 개발할일이 생겨 하이브리드 어플리케이션을 개발하였는데 앱스토어 관련 삽질을 많이 하게되었다.


최초 앱을 업로드하고 앱스토에 업데이트 버전을 올릴때 주의할점을 이야기해본다. 


처음 업데이트된 Binary 버전을 업데이트하고 앱스토어에서 추가로 업데이트된 버전에 대해 설정을 해주어야했다

기존 안드로이드 구글 플레이스토어처럼 업로드만 하면 자동으로 될거란 생각에 기다리가다가 업데이트가 되지 않길래 

확인해보았더니 아래 화면의 빨간영역의 버튼과 같이 버전추가를 Xcode에서 바이너리 코드 업로드후수동으로 해주어야했다. 


저와같이 처음 앱을 개발하는 분들은 이런삽질을 안하길 바라며 블로깅한다.


Ajax mobile 에서는 아래와 같은 형태로 loader 가 존재하는데 문제는 기본스타일이 구식이므로 커스텀이 필요한 경우가 많다. 


.ui-loader .ui-icon-loading {
  background-color: #000; 
  display: block;
  margin: 0;
  width: 2.75em;
  height: 2.75em;
  padding: .0625em;
  -webkit-border-radius: 2.25em;
  border-radius: 2.25em;
}

.ui-icon-loading {
  background: url(images/ajax-loader.gif);
  background-size: 2.875em 2.875em;
 }


위의 항목들중에 일부를 변경하여 쉽게 변경한다. 

보통 이미지를 바꾸고 싶어하므로 .ui-icon-loading 의 url 항목을 아래와 같이 변경한다 .


1. 

.ui-loader .ui-icon-loading { background-color: transparent; }


.ui-icon-loading { background: url("더_url.gif"); }



2. JQuery 모바일에서 이미 HTML으로 커스텀하에 지정하는 기능이 있는데 위의 경우보단 약간 까다롭다


자세한건 아래 링크를 참조해보자. 예제 소스를 보면 쉽게 따라 할수 있다.

http://demos.jquerymobile.com/1.4.5/loader/#CustomHTML



참조:

1. http://stackoverflow.com/questions/23849604/how-to-change-the-default-jquery-mobile-loading-icon

화면 영역에서 클릭한 영역마다 HTML 엘리멘트가 겹칠경우 겹치 영역에 따라 다른 이벤트를 처리하기 위해서는 이벤트 구분이 필요하다.


픽셀단위로 영역을 짜르는 경우는 해상도가 디바이스마다 다른 요즘환경에서는 사용하기 어려운 방법이기 때문에 

다른방법으로 영역을 잡는 방법이 있지 않을까 해서 자바스크립트 레퍼런스를 뒤지던중 아래와 같은 방법으로 처리하게되었다.


$("selector").click(function(evt) { var target = evt.originalEvent.target; if (target.nodeName == "CANVAS") { // 클릭한 영역이 캔버스일 경우 처리 } else if (target.nodeName == "DIV") { // 클릭한 영역이 DIV일 경우 처리 } });


기존 클릭 영역을 동적으로 계산하는 방식은 정확도가 매우 부정확했지만 이와 같은 방법으로 

다른 구준자를 넣어 동일한 엘리먼트들에 대해서도 다른 방식으로 처리하는 방식으로 응용할수 있지 않을까 생가한다 .

스프링 프로파일을 사용해서 환경별로 다른 설정이 가능하다 .

* Maven 프로파일 설정과는 별개이므로 주의 Maven 프로파일 설정은 (https://www.lesstif.com/pages/viewpage.action?pageId=14090588) 참조

 

 

먼저 properties 파일들을 development 와 

spring 환경을 설정하는 방법은 2가지 방법이 있다.

 

 

1. 빌드시 전달하는 JVM property 

 

e.g)

java -jar -Dspring.profiles.active=dev

 

 

2. web.xml에서 active-profile 설정

<context-param> 	<param-name>spring.profiles.active</param-name> 	<param-value>production</param-value> </context-param>

3. catalina.sh 에 직접 설정 

JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=local"

 

4. catalina.properties 에 추가 (D를 빼는 것 주의)

spring.profiles.active=dev

 

 

** 중복된 설정 우선순위

현재 삽질하며 확인한 결과 web.xml 을 최우선시하고 tomcat 환경설정에 직접 넣은 값은 값이 있을 경우 무시한다

 

이제 spring.profiles.active 에 따라 다른 properties 파일을 읽는 설정을 해주어야한다. 

아래코드를 응요해서 자신에게 맞는 방법을 선택하자 

필자는 development.properties 와 production.properties 를 classpath 아래 두었다.

 

<bean id="config" 	class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 	<property name="locations"> 		<list>				 			<value>classpath:/#{systemProperties['spring.profiles.active']}.properties 			</value> 		</list> 	</property> </bean>

 

* 추가팁 로벌 spring 환경 설정 톰캣에서 사용할 경우 설정 방법 

1. 이클립스 환경 톰캣에서 지정

 

 

 

참고

 

1. http://stackoverflow.com/questions/15814497/setting-spring-profile-variable

2. http://jdm.kr/blog/81

 

스프링을 사용하다보면 webapps 폴더안에 파일들에 대해 접근해야할 필요가 있다. 

Servletcontext 를 이용한 접근 방법이 있으나 이방법은 Servletcontext 에 의존적이라는 단점이 있다. 

특정 동작만을 위한 모듈을 덧붙일 경우 다른 방법이 필요한데 스프링에서는 이방법 또한 제공한다. 바로 코드로 보자 


import java.io.IOException;
import java.io.InputStream;

import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

public class ArbitraryResourceLoader implements ResourceLoaderAware {
    private ResourceLoader resourceLoader;

    public void test() throws IOException {
        Resource resource = resourceLoader.getResource("file:webapps/config.txt");
    	InputStream is = resource.getInputStream();
    	try{
    		int i=0;
            while((i=is.read())!=-1)
            {
               char c=(char)i;
               System.out.print(c);
            }
        }catch(IOException e){
        	 e.printStackTrace();
         }finally{
            
           if(is!=null)
            is.close();
         }
    }

	@Override
	public void setResourceLoader( ResourceLoader resourceLoader) {
		this.resourceLoader = resourceLoader;		
	}

}


그리고 빈설정 파일에 아래와 같이 설정해준다 class 경로 같은 경우는 자기자신의 프로젝트에 따라 바뀔것이다

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-4.0.xsd">
 
	 <bean id="arbitraryResourceLoader" class="org.test.sample.ArbitraryResourceLoader"/>

</beans>


JavaConfig로도 쉽게 응용할수 있으리라 생각한다. 

+ Recent posts